ffmpegのインストール〜HLS-Streaming再生まで

rpmの準備とgitでffmpegをcloneしてくる

sudo yum install nasm git subversion yum-plugin-priorities
sudo rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
vim /etc/yum.repos.d/CentOS-Base.repo
sudo yum -y update rpmforge-release
vim /etc/yum.repos.d/rpmforge.repo
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

x264のインストール

git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-static --enable-shared
make
make install

ffmpegのインストール

./configure --disable-yasm --enable-gpl --enable-libx264
make
make install

ffmpegのインストール確認

ffmpeg -version

nginxのインストール

yum install nginx
service nginx start

nginx.confを編集

vim /etc/nginx/nginx.conf

mime.typesに追記

vim /etc/nginx/mime.types
-------------------------------------
types {
.....
    application/x-mpegURL                 m3u8;
    video/MP2T                            ts;
-------------------------------------

テスト用にHLS再生用プレイヤーをhtmlとして作成

vim /usr/share/nginx/html/test.html
<!DOCTYPE html>
<html>
<head>
        <title>HTTP Live Streaming Demo</title>
        <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet" type="test/css">
        <script src="http://vjs.zencdn.net/c/video.js"></script>
</head>
<body>
        <video id="example_video_1" class="video-js vjs-default-skin" controls autoplay
        width="640" height="360" data-setup="{}">
                <source src="output.m3u8" type="application/x-mpegURL" />
        </video>
</body>
</html>

動画の変換

mp4を持ってくる

mkdir /usr/share/nginx/html/videos/
cp test.mp4 /usr/share/nginx/html/videos/

変換コマンド

ffmpeg -i test.mp4 -b:v 800k -acodec libfaac -b:a 128k -flags +loop-global_header -map 0 -bsf h264_mp4toannexb -f segment -segment_format mpegts -segment_time 10 -segment_list output.m3u8 stream%04d.ts

or

ffmpeg -i test.mp4 -f segment -segment_format mpegts -segment_time 10 -segment_list output.m3u8 stream%04d.ts

アクセスしてみる

http://localhost/test.html
(PCではHLSに対応してるのはSafariだけらしい)


(参考)
NginxとFFmpegを利用したHTTP Live Streaming配信
http://rest-term.com/archives/3008/

【Node.js】FFmpegでHLS配信をしてみる【ffserver】
http://www.fisproject.jp/2014/04/%E3%80%90node-js%E3%80%91ffmpeg%E3%81%A7hls%E9%85%8D%E4%BF%A1%E3%82%92%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B%E3%80%90mp4%E3%80%91/