DASH 串流和播放清單

本主題說明如何設定 DASH 輸出的工作。

簡介

由於DASH不是特定的視頻格式,編解碼器或與數據無關的打包格式(例如Zip),因此我們引入了一個新選項,名為streaming_delivery_format指定應根據特定標準對媒體文件進行結構化/格式化。選擇“破折號”作為streaming_delivery_format將修改一些默認選項以與DASH兼容,並將輸出媒體文件放入符合DASH要求的目錄結構中。DASH媒體輸出還必須具有type設置為“分段”,以確保媒體已準備好進行DASH流傳輸。

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "streaming_delivery_format": "dash",
        "video_bitrate": 700,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/sbr/rendition.mpd"
    }
    ]
}

輸出的詳細信息streaming_delivery_format設置為“破折號”:

分段DASH輸出的文件結構:

  • mpd訊清單檔案將位於輸出的根層級。
  • 音頻和視頻媒體將各自擁有自己的子目錄-“audio/und“和”video/1“ 分別。
  • 在每個目錄中,都會有一個“init.mp4”和初始化數據。
  • 媒體數據將存儲在名為“seg-N.m4f”(其中N從零開始,並在每個段中增加)。

DASH輸出與streaming_delivery_profile設置為“ on_demand”將使用零碎的媒體文件,而不是分段:

  • mpd訊清單檔案將位於輸出的根層級。
  • 音頻和視頻媒體都將是與清單相同目錄中的單個文件。
  • 媒體文件的名稱將與清單相似,但帶有“-audio“ 要么 ”-video”(根據需要添加了後綴)。

支持的DASH配置:

  • 支持的格式:m4fwebm
  • 支持的視頻編解碼器:h264hevcvp8vp9
  • 支持的音頻編解碼器:aacac3eac3vorbis
  • “”中的輸出webm”格式目前僅支持“ on_demand”streaming_delivery_profile
  • “”中的輸出webm“格式目前不支持DRM

多種比特率

Zencoder生成的DASH輸出將具有自己播放所需的結構,但是要真正受益於此類流送選項,您應該以不同的比特率(格式)生成多個版本,並列出列出格式的“播放列表”類型輸出以便播放器可以根據當前網絡狀況根據需要切換比特率。播放列表輸出是一個從屬輸出-也就是說,它將通過其標籤引用其他輸出,並將使用這些輸出中的數據來生成播放列表的最終格式。請注意,您必須謹慎設置播放列表輸出中的流路徑,以使它們成為移交文件位置的相對路徑。

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "label": "dash-1200",
        "streaming_delivery_format": "dash",
        "video_bitrate": 1200,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/1200k/rendition.mpd"
    },
    {
        "label": "dash-700",
        "streaming_delivery_format": "dash",
        "video_bitrate": 700,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/700k/rendition.mpd"
    },
    {
        "label": "dash-400",
        "streaming_delivery_format": "dash",
        "video_bitrate": 400,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/400k/rendition.mpd"
    },
    {
        "streaming_delivery_format": "dash",
        "type": "playlist",
        "url": "s3://mybucket/dash-examples/mbr/manifest.mpd",
        "streams": [
        { "source": "dash-1200", "path": "1200k" },
        { "source": "dash-700",  "path": "700k" },
        { "source": "dash-400",  "path": "400k" }
        ]
    }
    ]
}

加密

Zencoder還支持生成CENC加密的DASH輸出,並帶有與Marlin或Playready許可證服務器集成所需的標頭。對於每個輸出,只需指定drm選項的哈希即可,包括methodkey_idcontent_key。的key_idcontent_key應該從您的DRM供應商處檢索,或者預先生成並發送給您的DRM供應商。一旦你有了這些密鑰,單個轉譯的 Zencoder API 結構是:

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "streaming_delivery_format": "dash",
        "video_bitrate": 700,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/sbr/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    }
    ]
}

內容將使用content_key.mpd清單文件將包含key_id在其標題中。但是,為確保此輸出可播放,它還需要標頭,指定如何檢索content_key。在多比特率DASH編碼上,這些標頭僅需要添加到播放列表輸出中,但也可以添加到每個副本中,因此副本可以單獨播放。這可以通過添加一個或多個DRM模式來完成:


    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "streaming_delivery_format": "dash",
        "video_bitrate": 700,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/sbr/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0",
            "schemas": [
            { "type": "marlin" },
            { "type": "playready", "license_acquisition_url": "https://playready.example.com/license_server/" }
            ]
        }
    }
    ]
}

然後,我們可以將其放在一起以創建一個多比特率,DRM加密的DASH作業:

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "label": "dash-1200",
        "streaming_delivery_format": "dash",
        "video_bitrate": 1200,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/1200k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "label": "dash-700",
        "streaming_delivery_format": "dash",
        "video_bitrate": 700,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/700k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "label": "dash-400",
        "streaming_delivery_format": "dash",
        "video_bitrate": 400,
        "type": "segmented",
        "url": "s3://mybucket/dash-examples/mbr/400k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "streaming_delivery_format": "dash",
        "type": "playlist",
        "url": "s3://mybucket/dash-examples/mbr/manifest.mpd",
        "streams": [
        { "source": "dash-1200", "path": "1200k" },
        { "source": "dash-700",  "path": "700k" },
        { "source": "dash-400",  "path": "400k" }
        ],
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0",
            "schemas": [
            { "type": "marlin" },
            { "type": "playready", "license_acquisition_url": "https://playready.example.com/license_server/" }
            ]
        }
    }
    ]
}

轉換

當然,生成多種格式的視頻可能會變得既昂貴又浪費。因此,Zencoder支持使用以下命令將相同的編碼流重新打包為不同的格式(稱為轉碼)。copy_videocopy_audio選項。對視頻進行多路復用而不是對其進行編碼的輸出以常規時間的1/4收費。因此,如果您打算製作同一視頻的多種格式(例如,MP4,HLS和DASH),則可以先對每個比特率的MP4版本進行編碼,然後對這些輸出進行多路復用以創建HLS和DASH版本。(請注意,由於視頻不再是單個流,因此我們不支持從分段格式進行多路復用。)

為確保MP4是根據後續分段流格式的約束準備的,還請使用prepare_for_segmenting MP4輸出上的選項。在對MP4的視頻流進行編碼時,這將控制關鍵幀和字幕的默認值,以確保以後與將其轉換為分段格式兼容。

將MP4用作多路復用輸出的源與播放列表輸出類似。您可以指定與另一個輸出的標籤匹配的源選項,但這一次它是輸出的主級別選項的一部分,而不是流哈希中。

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "label": "mp4-700k",
        "prepare_for_segmenting": ["hls", "dash"],
        "video_bitrate": 700,
        "url": "s3://mybucket/transmux-examples/sbr/video.mp4"
    },
    {
        "source": "mp4-700k",
        "copy_video": true,
        "copy_audio": true,
        "type": "segmented",
        "url": "s3://mybucket/transmux-examples/sbr/hls/video.m3u8"
    },
    {
        "source": "mp4-700k",
        "copy_video": true,
        "copy_audio": true,
        "streaming_delivery_format": "dash",
        "type": "segmented",
        "url": "s3://mybucket/transmux-examples/sbr/dash/video.mpd"
    }
    ]
}

優化交付

由於DASH用於流式傳輸,因此我們建議控制每個再現中的比特率峰值,以避免播放器重新緩衝或不必要地切換到較低比特率編碼。根據解碼器/播放器可以處理的內容控制編碼流的可變性的選項是

我們的一般建議是將視訊串流decoder_bitrate_cap的最大位元速率設定為可用的最大位元速率。請記住,您需要考慮音頻以及文件格式的一些開銷。技術上應該符合解碼裝置上可用的視訊緩衝區記憶體,但通常會更好地用來控制可預先緩衝的內容量。decoder_buffer_size它的作用是decoder_bitrate_cap,例如decoder_bitrate_cap是500(每秒千比特),並且decoder_buffer_size是1000(千位),則緩衝區可以存儲2秒的視頻。我們還建議設置video_bitratedecoder_bitrate_cap,編碼器可以使用更多的數據來編碼複雜的場景,而在簡單的場景中使用更少的數據。一個體面的起點是假設高達 10% 的文件格式開銷,設置比低video_bitrate 10%decoder_bitrate_cap,並允許大約 1.5 秒的視頻被緩衝。

假設有1000 Kbps的連接可供客戶使用:

  • 1000 * 0.90 = 減去 10% 的格式額外負荷後可用的 900 千比。
  • 900-128 = 772 Kbps視頻decoder_bitrate_cap減去128 Kbps的音頻後。
  • 772 * 1.5 = 1158 Kb decoder_buffer_size(價值1.5秒的視頻)。
  • 772 * 0.90 = 695 Kbps目標視頻比特率(比標準視頻比特率低10%decoder_bitrate_cap)。

因此,對於更正確的流編碼示例:

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "label": "mp4-1000k",
        "prepare_for_segmenting": ["hls", "dash"],
        "audio_bitrate": 128,
        "decoder_bitrate_cap": 772,
        "decoder_buffer_size": 1158,
        "video_bitrate": 695,
        "url": "s3://mybucket/transmux-examples/sbr/video.mp4"
    },
    {
        "source": "mp4-1000k",
        "copy_video": true,
        "copy_audio": true,
        "type": "segmented",
        "url": "s3://mybucket/transmux-examples/sbr/hls/video.m3u8"
    },
    {
        "source": "mp4-1000k",
        "copy_video": true,
        "copy_audio": true,
        "streaming_delivery_format": "dash",
        "type": "segmented",
        "url": "s3://mybucket/transmux-examples/sbr/dash/video.mpd"
    }
    ]
}

全部放在一起

{
    "input": "http://s3.amazonaws.com/zencodertesting/test.mov",
    "outputs": [
    {
        "label": "mp4-1500k",
        "prepare_for_segmenting": ["hls", "dash"],
        "audio_bitrate": 128,
        "decoder_bitrate_cap": 1222,
        "decoder_buffer_size": 1833,
        "video_bitrate": 1100,
        "size": "1280x720",
        "url": "s3://mybucket/full-examples/mp4/1500.mp4"
    },
    {
        "label": "mp4-1000k",
        "prepare_for_segmenting": ["hls", "dash"],
        "audio_bitrate": 128,
        "decoder_bitrate_cap": 772,
        "decoder_buffer_size": 1158,
        "video_bitrate": 695,
        "size": "960x540",
        "url": "s3://mybucket/full-examples/mp4/1000.mp4"
    },
    {
        "label": "mp4-500k",
        "prepare_for_segmenting": ["hls", "dash"],
        "audio_bitrate": 128,
        "decoder_bitrate_cap": 322,
        "decoder_buffer_size": 483,
        "video_bitrate": 290,
        "size": "640x360",
        "url": "s3://mybucket/full-examples/mp4/500.mp4"
    },
    {
        "label": "hls-1500k",
        "source": "mp4-1500k",
        "copy_video": true,
        "copy_audio": true,
        "type": "segmented",
        "url": "s3://mybucket/full-examples/hls/1500.m3u8"
    },
    {
        "label": "hls-1000k",
        "source": "mp4-1000k",
        "copy_video": true,
        "copy_audio": true,
        "type": "segmented",
        "url": "s3://mybucket/full-examples/hls/1000.m3u8"
    },
    {
        "label": "hls-500k",
        "source": "mp4-500k",
        "copy_video": true,
        "copy_audio": true,
        "type": "segmented",
        "url": "s3://mybucket/full-examples/hls/500.m3u8"
    },
    {
        "type": "playlist",
        "url": "s3://mybucket/full-examples/hls/multi_bitrate_playlist.m3u8",
        "streams": [
        { "path": "1000.m3u8", "source": "hls-1000k" },
        { "path": "1500.m3u8", "source": "hls-1500k" },
        { "path": "500.m3u8", "source": "hls-500k" }
        ]
    },
    {
        "label": "dash-1500k",
        "source": "mp4-1500k",
        "copy_video": true,
        "copy_audio": true,
        "streaming_delivery_format": "dash",
        "type": "segmented",
        "url": "s3://mybucket/full-examples/dash/1500k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "label": "dash-1000k",
        "source": "mp4-1000k",
        "copy_video": true,
        "copy_audio": true,
        "streaming_delivery_format": "dash",
        "type": "segmented",
        "url": "s3://mybucket/full-examples/dash/1000k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "label": "dash-500k",
        "source": "mp4-500k",
        "copy_video": true,
        "copy_audio": true,
        "streaming_delivery_format": "dash",
        "type": "segmented",
        "url": "s3://mybucket/full-examples/dash/500k/rendition.mpd",
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0"
        }
    },
    {
        "streaming_delivery_format": "dash",
        "type": "playlist",
        "url": "s3://mybucket/full-examples/dash/manifest.mpd",
        "streams": [
            { "source": "dash-1500k", "path": "1500k" },
            { "source": "dash-1000k", "path": "1000k" },
            { "source": "dash-500k",  "path": "500k" }
        ],
        "drm": {
            "method": "cenc",
            "key_id": "d57d416ccd454d5a08d05bff0742ee76",
            "content_key": "f15cae8f4e48a023056e1960ff2228b0",
            "schemas": [
                { "type": "marlin" },
                { "type": "playready", "license_acquisition_url": "https://playready.example.com/license_server/" }
            ]
        }
    }
    ]
}