Ubuntu での GPAC (MP4Box) のインストール | MP4Box に基づいた DASH ビデオ システムの構築


1. ソースコードのインストール

OS:Ubuntu16.04

参考:

1.1 ソースコードを取得してコンパイルする

git clone https://github.com/gpac/gpac.git  
cd gpac  
git pull  
sudo ./configure --static-bin --prefix=/usr/local/MP4Box  
sudo make -j 4  
sudo make install   

*注1:make最後のは-j 4マルチコアアクセラレーション用です。追加しなくても問題ありません

*注 2: 指定されたインストール ディレクトリは次のとおりです。/usr/local/MP4Box

※注3:エラーの場合:

error: zlib not found on system or in local libs

参考: MP4BOX を Linux にインストールし、解決します:

sudo apt install zlib1g-dev

1.2 環境変数を追加する

変更します/etc/profile(root が必要です):

MP4BOX_PATH=/usr/local/MP4Box/bin
export PATH=$PATH:$MP4BOX_PATH

保存して終了した直後に有効にします。

source /etc/profile

1.3 インストールの確認

MP4Box -h

MP4Box のコマンドオプションについては、以下を参照してください。


2. MP4Box に基づいて DASH ビデオ システムを構築する

前回の記事DSAH ビデオ システム (サーバー & プレーヤー) 構築では、 Bento4mp4fragmentを通じてビデオの断片化をmp4dash実現しました。を使用してもMP4Box同様の効果が得られます。

DASH ビデオ システムを構築するための手順を完了します。

  1. サーバーを構築する(Nginx)
  2. ソースビデオとオーディオを取得する
  3. エンコーダ(FFmpeg)をインストールする
  4. ビデオエンコーディング
  5. オーディオエンコーディング
  6. ビデオ スライス ツール (MP4Box) をインストールする
  7. ビデオスライス
  8. Web プレーヤー (dash.js) を作成する
  9. サーバーを構成する

このうち、ステップ1~4はDSAHビデオシステム(サーバー&プレーヤー)の構築と全く同じであり、ステップ6については前述したので省略する。一貫性のない操作のみが以下に記録されます

5. オーディオエンコーディング

MP4Box はオーディオを直接処理できるため、flac 形式を m4a 形式に変換するだけでよく、ビデオとオーディオを組み合わせる必要はありません。つまり、次を実行するだけです:

ffmpeg -i ED-CM-St-16bit.flac -c:a libfdk_aac ED.m4a

7. ビデオのスライス

MP4Box を使用して、ビデオとオーディオを複数のビット レートで同時にスライスし、DASH 標準を満たす mpd ファイルを生成します。

具体的なコマンドは次のとおりです。

MP4Box -dash 2000 -rap -dash-profile dashavc264:onDemand -bs-switching no ED1920x1080.mp4 ED1280x720.mp4 ED896x504.mp4 ED640x360.mp4 ED256x144.mp4 ED.m4a -out ed.mpd

オプションの意味:

  • -ダッシュ 2000: セグメント継続時間 2 秒 (各メディア プレゼンテーションが単一のセグメントであるオンデマンド プロファイルの場合)
  • -rap: ビデオ セグメントを強制的にランダム アクセス ポイントから開始します。これは、ビデオ セグメントの検索を許可することを意味します (これが何を意味するかはわかりません)
  • -dash-profile dashavc264:onDemand: ターゲット DASH プロファイルを onDemand として指定します
  • -bs-switching no: ビットストリームスイッチングモードを使用しません(意味がわかりません)
  • -out ed.mpd: 出力mpdファイル名を指定します。

*このステップでプロンプトが表示されます。

[DASH] The difference between the durations of the longest and shortest representations (4.528000) is higher than the segment duration (2.000000)

その理由は、音声がビデオよりも長いためです。このプロンプトは無視してください。

その後、生成されるファイルは次のようになります。

ed.mpd
ED256x144_dashinit.mp4
ED640x360_dashinit.mp4
ED896x504_dashinit.mp4
ED1280x720_dashinit.mp4
ED1920x1080_dashinit.mp4
ED_dashinit.mp4

つまり、mpd ファイル、5 種類の解像度ビデオ、および 1 つのオーディオ トラック付きビデオで、
その中のed.mpd内容は次のとおりです。

<?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 0.8.0-rev122-gc02c9a2-master  at 2019-12-17T14:03:02.488Z-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H10M58.320S" maxSubsegmentDuration="PT0H0M2.005S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011,http://dashif.org/guidelines/dash264">
<ProgramInformation moreInformationURL="http://gpac.io">
  <Title>ed.mpd generated by GPAC</Title>
</ProgramInformation>

<Period duration="PT0H10M58.320S">
  <AdaptationSet segmentAlignment="true" maxWidth="1920" maxHeight="1080" maxFrameRate="24" par="16:9" lang="und" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
   <Representation id="1" mimeType="video/mp4" codecs="avc1.640028" width="1920" height="1080" frameRate="24" sar="1:1" bandwidth="3988497">
    <BaseURL>ED1920x1080_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="899-4854">
     <Initialization range="0-898"/>
    </SegmentBase>
   </Representation>
   <Representation id="2" mimeType="video/mp4" codecs="avc1.64001F" width="1280" height="720" frameRate="24" sar="1:1" bandwidth="1983089">
    <BaseURL>ED1280x720_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="898-4853">
     <Initialization range="0-897"/>
    </SegmentBase>
   </Representation>
   <Representation id="3" mimeType="video/mp4" codecs="avc1.64001F" width="896" height="504" frameRate="24" sar="1:1" bandwidth="1131432">
    <BaseURL>ED896x504_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="898-4853">
     <Initialization range="0-897"/>
    </SegmentBase>
   </Representation>
   <Representation id="4" mimeType="video/mp4" codecs="avc1.64001E" width="640" height="360" frameRate="24" sar="1:1" bandwidth="676676">
    <BaseURL>ED640x360_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="898-4853">
     <Initialization range="0-897"/>
    </SegmentBase>
   </Representation>
   <Representation id="5" mimeType="video/mp4" codecs="avc1.64000C" width="256" height="144" frameRate="24" sar="1:1" bandwidth="147765">
    <BaseURL>ED256x144_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="897-4852">
     <Initialization range="0-896"/>
    </SegmentBase>
   </Representation>
  </AdaptationSet>
  <AdaptationSet segmentAlignment="true" lang="und" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
   <Representation id="6" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="48000" bandwidth="139637">
    <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
    <BaseURL>ED_dashinit.mp4</BaseURL>
    <SegmentBase indexRangeExact="true" indexRange="854-4845">
     <Initialization range="0-853"/>
    </SegmentBase>
   </Representation>
  </AdaptationSet>
</Period>
</MPD>

8. Web プレーヤー (dash.js) を作成します。

コードは基本的に同じですが、mpdのファイル名を変更するだけですed.mpd(14行目)。

9. サーバーの構成

操作は元のテキストと一致しています。つまり、Nginx 構成を変更してファイルを配置します。完了後の html/ 下のファイル ディレクトリ構造は次のようになります。

/usr/local/nginx/html/
    50x.html
    dash.all.min.js
    ed.mpd
	ED256x144_dashinit.mp4
	ED640x360_dashinit.mp4
	ED896x504_dashinit.mp4
	ED1280x720_dashinit.mp4
	ED1920x1080_dashinit.mp4
	ED_dashinit.mp4
    index_bak.html
    index.html

次に、再生するサーバーのアドレスを入力します。再生中に、ファイル転送ステータスを確認できます。
F12
ビデオとオーディオの両方がセグメントで送信され、その中にはED_dashinit.mp4オーディオが含まれ、残りはさまざまな解像度のビデオです。

おすすめ

転載: blog.csdn.net/LvGreat/article/details/103588897