CentOSにm3u8-segmenterをインストールする

環境

CentOS 6.3 x86_64

Require

ffmpegがインストール済みであること

インストールしてない場合は、CentOS6.xにFFmpegをインストールするを参考にしてみてください。

m3u8-segmenterのインストール

この記事を見ている方は恐らくHLSの知識がある方が多いと思うので、HLSとはなんぞやという説明は省きます。

オープンソースのsegmenterはいくつかありますが、今回は m3u8-segmenterを試すことにします。

1
2
3
$ cd /usr/local/src/
$ git clone https://github.com/johnf/m3u8-segmenter.git
$ cd m3u8-segmenter

Configure Error

configureを実行すると以下のエラーが発生

1
2
3
4
5
6
7
8
9
10
11
configure: error: Package requirements (libavformat libavcodec libavutil) were not met:
No package 'libavformat' found
No package 'libavcodec' found
No package 'libavutil' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively,  you may set the environment variables FFMPEG_CFLAGS
and FFMPEG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

以前、CentOSにHttpSegmenterをインストールするでも似たエラーが発生してたので同じ方法で解決できる。

1
2
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
$ ./configure

インストール

1
2
$ make
$ make install

segmentしてみる

1
2
3
$ mkdir tmp
$ ffmpeg -i big_buck_bunny.mp4 -f mpegts - | \
  m3u8-segmenter -i - -d 10 -p tmp/big_buck_bunny -m tmp/big_buck.m3u8 -u http://localhost/segment

簡単にオプションの説明をすると、

オプション -d
何秒毎に分割するか。上記のコマンドの場合、10秒
オプション -p
分割されたtsファイルの出力先 & 出力ファイル名。出力先にbig_buck_bunny-1.ts ... big_buck_bunny-50.ts ... と連番でファイルが作成される
オプション -m
m3u8の出力先
オプション -u
m3u8に記載されるファイルのURL

出力されたm3u8を確認する

現時点でのm3u8-segmenterは以下のようなm3u8ファイルを出力します。

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXTINF:10,
http://localhost/segmenttmp/big_buck_bunny-1.ts
#EXTINF:10,
http://localhost/segmenttmp/big_buck_bunny-2.ts
#EXTINF:10,
http://localhost/segmenttmp/big_buck_bunny-3.ts
#EXTINF:10,

・・・ 省略 ・・・

http://localhost/segmenttmp/big_buck_bunny-58.ts
#EXTINF:10,
http://localhost/segmenttmp/big_buck_bunny-59.ts
#EXT-X-ENDLIST

今まで試したオープンソースのsegmenterでは一番良い感じだと思います。

関連

FFMpegでHttp Live Streaming(HLS)向けにセグメント化する

Comments