MP4Box は mp4 ファイルの結合や Mux ができます。
GPAC Nightly Buildsから最新版をダウンロードし、 dmg を実行して、適当な場所(例: /Application)にコピーします。
MP4Box を PATH に追加するか、Osmo4.app/Contents/MacOS/MP4Box コマンドへのエリアスを追加します。
alias MP4Box="/Applications/Osmo4.app/Contents/MacOS/MP4Box"
$ MP4Box -version
> MP4Box - GPAC version 0.5.2-DEV-rev534-g2cc7d80-master
> GPAC Copyright (c) Telecom ParisTech 2000-2012
> GPAC Configuration:
> Features: GPAC_64_BITS GPAC_HAS_SSL GPAC_HAS_SPIDERMONKEY GPAC_HAS_JPEG GPAC_HAS_PNG
Mux 用の素材を以下から入手し、pen1.mp4 〜 pen3.mp4 にリネームします。
- NHKクリエイティブ・ライブラリー
- 素材利用のRule
- Contents
- アデリーペンギン 仲よく腹ばいで滑る
- http://www1.nhk.or.jp/creative/material/84/D0002030833_00000.html
- rename to pen1.mp4
- アデリーペンギン 懸命に腹ばいで滑る
- http://www1.nhk.or.jp/creative/material/3d/D0002030832_00000.html
- rename to pen2.mp4
- ジェンツーペンギンと南極の夕景
- http://www1.nhk.or.jp/creative/material/81/D0002100117_00000.html
- rename to pen3.mp4
- アデリーペンギン 仲よく腹ばいで滑る
MP4Box の詳細なヘルプは MP4Box -h general
や MP4Box -h dash
で表示されます。
$ MP4Box -h
> MP4Box [option] input [option]
> -h general general options help
> -h hint hinting options help
> -h dash DASH segmenter help
> -h import import options help
> -h encode encode options help
> -h meta meta handling options help
> -h extract extraction options help
> -h dump dump options help
> -h swf Flash (SWF) options help
> -h crypt ISMA E&A options help
> -h format supported formats help
> -h rtp file streamer help
> -h live BIFS streamer help
> -h all all options are printed
>
> -nodes lists supported MPEG4 nodes
> -node NodeName gets MPEG4 node syntax and QP info
> -xnodes lists supported X3D nodes
> -xnode NodeName gets X3D node syntax
> -snodes lists supported SVG nodes
> -snode NodeName gets SVG node syntax
> -languages lists supported ISO 639 languages
>
> -quiet quiet mode
> -noprog disables progress
> -v verbose mode
> -logs set log tools and levels, formatted as a ':'-separated list of toolX[:toolZ]@levelX
> -version gets build version
> -- INPUT escape option if INPUT starts with - character
pen1.mp4 と pen2.mp4 を結合した pen1+2.mp4 を生成し、 さらに pen1+2.mp4 と pen3.mp4 を結合した pen_all.mp4 を生成します。
$ MP4Box -brand mp42 -cat "pen1.mp4" -cat "pen2.mp4" -new "pen1+2.mp4"
$ MP4Box -brand mp42 -cat "pen1+2.mp4" -cat "pen3.mp4" -new "pen_all.mp4"
video.mp4 と audio.m4a を mux し movie.mp4 を生成できます。
$ MP4Box -brand mp42 -add "video.mp4"#video -add "audio.m4a"#audio -new "movie.mp4"
トラック情報をダンプします。
$ MP4Box -info "pen_all.mp4"
MPEG-DASH の MPD(Media Presentation Description) を作成します。
この例では、10 秒のセグメントと 1 秒のフラグメントで mpd を作成します。
$ MP4Box -dash 10000 -frag 1000 -rap pen_all.mp4
> DASH-ing file: 10.00s segments 1.00s fragments single sidx per segment
> Spliting segments at GOP boundaries
> DASHing file pen_all.mp4
> [DASH] Generating MPD at time 2015-07-20T16:47:26.965Z
> ls
> pen_all_dash.mpd
> pen_all_dashinit.mp4
dash.js をダウンロードし、pen_all_dash.mpd を index.html で再生してみます。
<!doctype html><html>
<script src="http://cdn.dashjs.org/latest/dash.all.js"></script>
<div>
<video id="videoPlayer" controls="true" />
</div>
<script>
window.onload = function() {
var url = "http://localhost:8999/penguin_dash.mpd";
var context = new Dash.di.DashContext();
var player = new MediaPlayer(context);
player.startup();
player.attachView(document.querySelector("#videoPlayer"));
player.attachSource(url);
};
</script>
</html>