サーバーOS | CentOS 6.4 |
Webサーバー | Apache 2.2.15 |
ストリーミング・サーバー | FFmpeg 2.0.1 (ffmpeg & ffserver) |
カメラ | Logicool Webcam C210 (UVC対応) |
FFmpegの導入:
FFmpeg のサイト( http://www.ffmpeg.org/ ) の Download ページの Getting FFmpeg 内に
If you are a distributor, you can find release tarballs below.
という行があるので、その行内の release tarballs below という部分のリンクをクリックすると、FFmpeg Releases に移動する。
その中の FFmpeg 2.0.1 "Nameless" の中にある Download gzip tarball というリンクがソースコードのアーカイブファイルへのリンクになっているのでダウンロードしてくる。
現在は Ver.2.0.1 が最新らしい。
ファイル名は ffmpeg-2.0.1.tar.gz
念のため、ソースのアーカイブファイル http://www.ffmpeg.org/releases/ffmpeg-2.0.1.tar.gz へのリンクを貼っておきます。
以下にインストール手順を記述します。
ソースのアーカイブをダウンロードして適当なディレクトリに展開する。 [root@localhost ~]# cd /usr/local/src [root@localhost src]# wget http://www.ffmpeg.org/releases/ffmpeg-2.0.1.tar.gz [root@localhost src]# tar zxvf ffmpeg-2.0.1.tar.gz 展開すると ffmpeg-2.0.1 というディレクトリが出来るので、 [root@localhost src]# cd ffmpeg-2.0.1 でディレクトリを移動して下記を実行すると [root@localhost ffmpeg-2.0.1]# ./configure yasm not found, use --disable-yasm for a crippled build If you think configure made a mistake, make sure you are using the latest version from Git. If the latest version fails, report the problem to the ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net. Include the log file "config.log" produced by configure as this will help solving the problem. 上記のようなメッセージが出て先に進まないので --disable-yasm をつけて再度実行 [root@localhost ffmpeg-2.0.1]# ./configure --disable-yasm install prefix /usr/local source path . C compiler gcc ARCH x86 (generic) big-endian no : : : Enabled indevs: alsa fbdev oss dv1394 lavfi v4l2 Enabled outdevs: alsa oss v4l2 License: LGPL version 2.1 or later Creating config.mak, config.h, and doc/config.texi... [root@localhost ffmpeg-2.0.1]# 今度はうまくいったようなので、続いてビルドします。 [root@localhost ffmpeg-2.0.1]# make CC libavdevice/alldevices.o CC libavdevice/alsa-audio-common.o CC libavdevice/alsa-audio-dec.o CC libavdevice/alsa-audio-enc.o CC libavdevice/avdevice.o CC libavdevice/dv1394.o CC libavdevice/fbdev.o CC libavdevice/lavfi.o CC libavdevice/oss_audio.o CC libavdevice/timefilter.o CC libavdevice/v4l2-common.o CC libavdevice/v4l2.o libavdevice/v4l2.c: In function ‘mmap_read_frame’: libavdevice/v4l2.c:554: 警告: ‘destruct’ is deprecated (declared at ./libavcodec/avcodec.h:1095) CC libavdevice/v4l2enc.o : : : ffprobe.c: In function ‘opt_show_streams’: ffprobe.c:2031: 警告: dereferencing pointer ‘id’ does break strict-aliasing rules ffprobe.c:2032: 警告: dereferencing pointer ‘id’ does break strict-aliasing rules ffprobe.c:2031: note: initialized from here ffprobe.c:2031: note: initialized from here LD ffprobe_g CP ffprobe STRIP ffprobe CC ffserver.o LD ffserver_g CP ffserver STRIP ffserver [root@localhost ffmpeg-2.0.1]# 警告はたくさん出ますが、一応ビルドはできたようなので、インストールします。 [root@localhost ffmpeg-2.0.1]# make install INSTALL doc/ffmpeg.1 INSTALL doc/ffprobe.1 INSTALL doc/ffserver.1 INSTALL doc/ffmpeg-all.1 INSTALL doc/ffprobe-all.1 INSTALL doc/ffserver-all.1 INSTALL doc/ffmpeg-utils.1 INSTALL doc/ffmpeg-scaler.1 : : : INSTALL libavutil/xtea.h INSTALL libavutil/lzo.h INSTALL libavutil/avconfig.h INSTALL libavutil/libavutil.pc [root@localhost ffmpeg-2.0.1]# インストールが完了すると、/usr/local/bin に ffmpeg, ffprobe, ffserver がコピーされる。
FFmpegの設定:
ffmpeg-2.0.1/doc ディレクトリに ffserver.conf の雛形があるので、それを /usr/local/etc/ffserver.conf にコピーして編集する。
実際の設定例です: ffserver.confの設定内容
起動スクリプトを作成して、ブート時に起動するように設定
起動スクリプト: livecam
起動スクリプトは、実行属性をつけて/etc/init.d に置き、chkconfig等でBOOT時に起動するようにする。
例: # cp livecam /etc/init.d # chmod +x /etc/init.d/livecam # chkconfig --add livecam # chkconfig livecam on というようにすれば良かったと思います。 サービスを開始するには、 # /etc/init.d/livecam start で ffserver と ffmpeg が起動します。
WEBのページを準備:
ストリームデータ用METAファイルの作成
MediaPlayerのストリーム用のMETAファイル xxxx.asx を作成する
テキストファイルで、内容は下記のように記述する。
<ASX version = "3.0"> <Entry> <Ref href="http://www.gusuku.org:8090/test.asf" /> </Entry> </ASX>
同様にRealPlayerのストリーム用のMETAファイル xxxx.rpm を作成する
テキストファイルで、内容は下記のように記述する http://www.gusuku.org:8090/test.rm
[注] www.gusuku.org はffserver が動作しているサーバーを指す。 8090はffserver.conf のPort で指定したポート番号を指定する。 test.asf 及び test.rmは、ffserver.conf のStreamタグで指定した名前 (<Stream test.asf>、<Stream test.rm> 等)を使用する。
HTMLファイルの作成
WEBのページに埋め込んで表示するように、HTMLファイルに以下のタグを記述する
WindowsMediaPlayer用
<embed type="application/x-mplayer2" src="webcam.asx" width="320" height="290" autoplay=true> </embed>
RealPlayer用
<embed src="webcam.rpm" width="320" height="240" CONTROLS="ImageWindow" AUTOSTART="true"> </embed>
<embed src="http://www.gusuku.org:8090/test.swf" width="320" height="240" autoplay="true"> </embed>
JPEG静止画用
<img src="http://www.gusuku.org:8090/test.jpg" width="320" height="240" border="0">
WEBクライアントで表示:
上記のHTMLファイルを表示すれば、カメラの画像が見られるはずです。
以上でした。
参考資料:
FFmpeg のサイトのドキュメント
ffmpeg http://www.ffmpeg.org/ffmpeg.html
ffmpeg-all http://www.ffmpeg.org/ffmpeg-all.html
ffserver http://www.ffmpeg.org/ffserver.html
ffserver-all http://www.ffmpeg.org/ffserver-all.html