Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active May 19, 2022 08:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uupaa/262fa1a98236331571b4 to your computer and use it in GitHub Desktop.
Save uupaa/262fa1a98236331571b4 to your computer and use it in GitHub Desktop.
MP4Box install, setting and usage in Mac.

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

mp4 テスト素材の入手

Mux 用の素材を以下から入手し、pen1.mp4 〜 pen3.mp4 にリネームします。

Usage

MP4Box の詳細なヘルプは MP4Box -h generalMP4Box -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"

Mux

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"

MPD を作成しストリーミング再生する

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment