- 追加された行はこのように表示されます。
- 削除された行は
このように表示されます。
!!!MinGW+ffmpeg(7)ffmpegのビルド
ようやくffmpegのビルドまでたどり着いた。
付加的な改造は後々行うとして、まずは''ビルドできることを確認''しよう。
事前に、マルチスレッド(pthread-w32)に関する修正が2点ほど、configureに必要だ。
これらの修正は[[MinGW+ffmpeg(1)準備]]で説明したどちらのリビジョンにも必要で、
両リビジョンのconfigureは多少表記が違うが、追加する内容は全く同じ。
リビジョンの違いで迷うことはないだろう。
!!ffmpeg自体のpthread-w32
!!ffmpeg自体のpthread-w32対応
x264と同様にpthread-w32を有効にするが、ffmpegのconfigureは''pthread-w32を考慮していない。''
pthread-w32のライブラリはlibpthreadGC2.aであり、libwsock32.aに依存している。
これらの依存関係をconfigureに追加する。
以下のような箇所を探そう
# check for some common methods of building with pthread support
# do this before the optional library checks as some of them require pthreads
if enabled pthreads; then
if check_func pthread_create; then
:
elif check_func pthread_create -pthread; then
add_cflags -pthread
add_extralibs -pthread
elif check_func pthread_create -pthreads; then
add_cflags -pthreads
add_extralibs -pthreads
elif ! check_lib pthread.h pthread_create -lpthread; then
die "ERROR: can't find pthreads library"
fi
fi
最後のelifの前に、
elif check_func pthread_create -lpthreadGC2 -lwsock32; then
add_extralibs -lpthreadGC2 -lwsock32
という2行を追加し、以下のようにする。
# check for some common methods of building with pthread support
# do this before the optional library checks as some of them require pthreads
if enabled pthreads; then
if check_func pthread_create; then
:
elif check_func pthread_create -pthread; then
add_cflags -pthread
add_extralibs -pthread
elif check_func pthread_create -pthreads; then
add_cflags -pthreads
add_extralibs -pthreads
elif check_func pthread_create -lpthreadGC2 -lwsock32; then
add_extralibs -lpthreadGC2 -lwsock32
elif ! check_lib pthread.h pthread_create -lpthread; then
die "ERROR: can't find pthreads library"
fi
fi
これでffmpeg自体がpthread-w32を使用してビルド可能になる。
!!pthread-w32を使うx264とリンクする
これまでの記事通りに進めていれば、libx264.aはマルチスレッド(pthread-w32)対応版になっているはずだ。
ffmpegのconfigureはlibx264.aが使用可能であるかを事前チェックする。
このチェック時にやはりpthread-w32が必要となるため、configureを修正する。
上記ffmpeg自体のpthread-w32対応で変更した箇所の少し下に、以下の記述がある。
# these are off by default, so fail if requested and not available
enabled liba52 && require liba52 a52dec/a52.h a52_init -la52
enabled libamr_nb && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm
enabled libamr_wb && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
enabled libgsm && require libgsm gsm.h gsm_create -lgsm
enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg
enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
enabled libogg && require libogg ogg/ogg.h ogg_sync_init -logg
enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
enabled libx264 && require x264 x264.h x264_encoder_open -lx264
enabled libxvid && require Xvid xvid.h xvid_global -lxvidcore
enabled dc1394 && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
enabled libfaad && require2 libfaad faad.h faacDecOpen -lfaad
enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
このlibx264の行に、-lpthreadGC2 -lwsock32を追加する。
enabled libx264 && require x264 x264.h x264_encoder_open -lx264 -lpthreadGC2 -lwsock32
!!ビルド
ビルドコマンドは./configureとmakeだけだが、./configureが長い。
あまりに長いので下記では\で改行しているが、もちろん全て続けて書いても良い。
また、./configureに指定するオプションは最近のリビジョンと少し前までのリビジョンで僅かに異なる。
!最近のリビジョン
$ ./configure \
--enable-gpl --enable-pthreads \
--enable-libx264 --enable-libfaac --enable-libfaad --enable-libxvid \
--enable-libmp3lame --enable-liba52 --enable-avisynth \
--enable-postproc --enable-swscale --enable-memalign-hack \
--target-os=mingw32 --cpu=i686 --arch=i686 --disable-debug \
--disable-ffserver --disable-ffplay --disable-network
$ make
!少し前までのリビジョン
$ ./configure \
--enable-gpl --enable-pthreads \
--enable-libx264 --enable-libfaac --enable-libfaad --enable-libxvid \
--enable-libmp3lame --enable-liba52 --enable-avisynth \
--enable-pp --enable-swscaler --enable-memalign-hack \
--target-os=mingw32 --cpu=i686 --arch=i686 --disable-debug \
--disable-ffserver --disable-ffplay --disable-network
$ make
両者の違いは、以下の2点だ。
*--enable-postproc = --enable-'''pp'''
*--enable-swscale = --enable-swscale'''r'''
指定する名前が変わっただけで、本質的には同じだ。
これで晴れてffmpeg.exeが作成される。
!!ffmpeg自体はシングルスレッドにする場合
x264のみpthread-w32を使用させ、ffmpeg自体はシングルスレッドで良い場合にはどうするか。
上記のうち「ffmpeg自体のpthread-w32」のconfigureの修正は不要。
つまり「pthread-w32を使うx264とリンクする」の修正のみ行えばよい。
また、ビルド時の./configureには--enable-pthreadsが不要になる。
ただし、これは''pthread-w32のDLL版を使用する場合に限られる。''
static版をリンクした場合、恐らくビルドは通っても実行時に不正終了するffmpeg.exeになる。
なお、筆者はこの「ffmpeg自体はシングルスレッド版」の確認を行っていない。
理論上は上記の通りのはずだ。