FFMPEG:segment fromat add timestamp into filename option

原本只能輸出成 %4d.mp4 ==> 0000.mp4, 0001.mp4
要改成可以像行車紀錄器般的檔案格式 201405020248.mp4

增加 %t 的參數
ffmpeg -i input -f segment -segment_time 60 -reset_timestamps 1 %t.mp4

這邊將 %t.mp4 定義成 Webcam年日月/E年日月時分秒.mp4
strftime(buf1, sizeof(buf1), “WebCam%Y%m%d/E%Y%m%d%H%M%S”, localtime(&tv.tv_sec));

修改方式如下:

修改 ffmpeg source / libavformat / utils.c 檔案
增加引用 #include <sys/time.h>

尋找 av_get_frame_filename function
替換成下面這一個

int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
{
    const char *p;
    char *q, buf1[50], c;
    int nd, len, percentd_found, percentt_found;
    struct timeval tv;

    q = buf;
    p = path;
    percentd_found = 0;
    percentt_found = 0;
    for (;;) {
        c = *p++;
        if (c == '')
            break;
        if (c == '%') {
            do {
                nd = 0;
                while (av_isdigit(*p))
                    nd = nd * 10 + *p++ - '0';
                c = *p++;
            } while (av_isdigit(c));

            switch (c) {
            case '%':
                goto addchar;
            case 'd':
                if (percentd_found)
                    goto fail;
                percentd_found = 1;
                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
                len = strlen(buf1);
                if ((q - buf + len) > buf_size - 1)
                    goto fail;
                memcpy(q, buf1, len);
                q += len;
                break;
            case 't':
                if (percentt_found)
                    goto fail;
                percentt_found = 1;

                gettimeofday(&tv, NULL);
                //strftime(buf1, sizeof(buf1), "%Y-%m-%d_%H-%M-%S", localtime(&tv.tv_sec));
                //
                strftime(buf1, sizeof(buf1), "WebCam%Y%m%d/E%Y%m%d%H%M%S", localtime(&tv.tv_sec));
                len = strlen(buf1);
                if ((q - buf + len) > buf_size - 1)
                    goto fail;
                memcpy(q, buf1, len);
                q += len;
                break;
            default:
                goto fail;
            }
        } else {
        addchar:
            if ((q - buf) < buf_size - 1)
                *q++ = c;
        }
    }
    if (!percentd_found && !percentt_found)
        goto fail;
    *q = '';
    return 0;
fail:
    *q = '';
    return -1;
}
Posted in FFMpeg | Leave a comment

FFmpeg:Install in the Ubuntu 12.04

#!/bin/sh
#
# Name: ffmpeg git
# Version: 0.01a
# Description: ffmpeg git compilation with libvorbis, x264, mp3 lame support
# Script_URI: http://www.techno-blog.net
#
# Author: Nikos


###########################
##### Run some checks #####
###########################

# Check if user is root
if [ $(id -u) != "0" ]; then
        echo "Erreur : Vous devez être root pour utiliser ce script, use sudo sh $0"
        exit 1
fi

#############################################
##### Set some variables and functions ######
#############################################

# Directory where this script is located
BASEDIR="$(dirname $0)"

error_out() {
        echo "Could not ${1}, aborting"
        exit 1
}

wrap() {
        local ErrorMsg="$1"
        shift
        local cmd="$1"
        shift
        $cmd "$@" || error_out "$ErrorMsg"
}

# Install aptitude
apt-get install aptitude

# Function to install packages
install_pkgs() {
        aptitude -yq=3 install "$@"
}

# Function to remove packages
remove_pkgs() {
        aptitude -yq=3 remove "$@"
}


#################################
##### The magic starts here #####
#################################

# Uninstall Packages
wrap "remove libmp3lame-dev ffmpeg yasm" remove_pkgs libmp3lame-dev ffmpeg yasm

# Install packages
wrap "install some dependancies" install_pkgs quilt libsdl1.2-dev libogg-dev libvorbis-dev liba52-dev libdts-dev libimlib2-dev texi2html libraw1394-dev libdc1394-22-dev libtheora-dev libgsm1-dev libxvidcore-dev libfaac-dev libfaad-dev build-essential git-core checkinstall texi2html libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libx11-dev libxfixes-dev zlib1g-dev nasm

# Retrieving x264, libvorbis, mp3lame
mkdir ffmpeg_source
cd ffmpeg_source

wrap "diwnload yasm-1.2.0" wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
wrap "set up yasm" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
wrap "compilation" make
wrap "build DEB package" make install
make distclean
export "PATH=$PATH:$HOME/bin"

cd ..
wrap "retrieving x264 from git sources" git clone git://git.videolan.org/x264
cd x264
wrap "set up x264 config" ./configure --enable-static --disable-opencl
wrap "compilation with 3 cores" make -j3
wrap "build install-lib-dev" make install-lib-dev
wrap "build DEB package" checkinstall --pkgname=x264 --default --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes

cd ..
mkdir -p /usr/local/share/doc/lame
wrap "download lamemp3 source" wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
tar xzvf lame-3.98.4.tar.gz
cd lame-3.98.4
wrap "set up lamemp3" ./configure --enable-nasm --disable-shared
wrap "compilation" make
wrap "build DEB package" checkinstall --pkgname=lame-ffmpeg --pkgversion="3.98.4" --backup=no --default --deldoc=yes

cd ..
wrap "retrieving libvpx from git sources" git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
wrap "set up libvpx config" ./configure
wrap "compilation with 3 cores" make -j3
wrap "build DEB package" checkinstall --pkgname=libvpx --pkgversion="$(date +%Y%m%d%H%M)-git" --backup=no --default --deldoc=yes

cd ..
wrap "retrieving ffmpeg from git sources" git clone git://git.videolan.org/ffmpeg
cd ffmpeg
wrap "set up ffmpeg config" ./configure --enable-gpl --enable-postproc --enable-swscale --enable-pthreads --enable-x11grab --enable-libdc1394 --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-avfilter
wrap "compilation with 3 cores" make -j3
wrap "build DEB package" checkinstall --pkgname=ffmpeg --pkgversion="0.6.3-git" --backup=no --deldoc=yes --default
hash x264 ffmpeg ffplay ffprobe

echo "#############################"
echo "##### Mission complete! #####"
echo "#############################"
Posted in FFMpeg, Ubuntu | Leave a comment

Install Vim Plugin: YouCompleteMe in CentOS #1

前一篇文章安裝一直失敗,所以重裝了vim後再來試試看!
基本上準備動作跟前一篇失敗的安裝記錄一樣 Continue reading

Posted in Linux | Leave a comment

Upgrade Vim version to 7.4 (tar install)

前一篇文章將vim更新至7.4後不僅plugin安裝失敗,連syntax顏色都不見了
所以就來試試看另外用tar安裝的方式
(但應該只是BundleInstall沒有執行….,不過都移除重新安裝了就沒再試了) Continue reading

Posted in Linux | Leave a comment

Install Vim Plugin: YouCompleteMe in CentOS

最近一則fb鬧得沸沸揚揚XD
主要是說我怎麼會用vim編輯php編了兩年…
然後就很多人開始提供說vim才是最好用的~因為有許多plugin可以用….Orz
現在就來安裝一下還蠻多人推的ycm Continue reading

Posted in Linux | Leave a comment

Upgrade Vim version to 7.4

按照官網的說明 (連結),升級vim版本有點簡單
不過可以先檢查vim的版本,以免做白工了 Continue reading

Posted in Linux | Leave a comment

PHP Eclipse Editor

怒了, 還是來裝一下Editor好了
不然vim打得好累……

參考蛙齋的作法1蛙齋的作法2
先到官網下載Eclipse軟體安裝後,利用help=>install new software找到『Web, XML, Java EE and OSGi Enterprise Development』項目
在此項目下就可以看到php的相關plugin

然後再安裝rse,主要是可以讓eclipse支援remote操作(ftp、ssh等)
rse主要在General Purpose Tools下,需要安裝『Remote System Explorer End-User Runtime、Remote System Explorer User Actions』這兩個

安裝完後便可以利用『Remote System Explorer』設定ssh的連線資訊
設定完成後選擇遠端的網頁目錄按右鍵『Create Remote Project』
這時候便可以用php explorer來瀏覽、編輯網頁

註:我比較懶,且不算是生產線上的系統,所以選擇直接編輯
通常最適當做法應該是在本機創模擬環境,確認ok後再上傳

Posted in PHP | Leave a comment

MySQL Trigger 備份

目前MySQL每天都有透過mysqldump將資料倒出備份到另外一台NAS去
就會很害怕trigger會被捨棄掉不備份…..

還好~查了一下trigger是會被照顧的
只有store procedure跟function不會
恰恰好這兩個我都沒用到XD

“mysqldump will backup by default all the triggers but NOT the stored procedures/functions.”
Source

Posted in MySQL | Leave a comment

查詢關鍵字是否存在於以逗號分隔的資料欄位中

這樣有個好處
table的欄位可以開少一點
只是拉出來時如果要個別拆開
就需要程式語言有支援了…. (還有php有支援XD)

只是這邊有一點要小心,逗號前後的空格都有可能會影響比對的部分
Continue reading

Posted in MySQL, PHP | Leave a comment

查詢資料表中重複的資訊

每次要用時都會小忘記一下….
來記錄看以後會不會記得 (謎之聲:不會….)

select * from unit where `schoolid` in 
      (select `schoolid` from unit group by `schoolid` having count(`schoolid`)>1 ) 
      order by `schoolid`
Posted in MySQL | Leave a comment