使用ffmpeg生成破折号清单,它不能由dash.js

时间:2018-01-01 18:06:04

标签: javascript ffmpeg mpeg-dash

我使用ffmpeg通过rtmp协议对输入流进行编码,代码如下:

ffmpeg -re -i rtmp://localhost:1935${StreamPath} -use_timeline 1 /
-use_template 1 -window_size 10 -min_seg_duration 5000 -f dash out.mpd

清单看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:mpeg:dash:schema:mpd:2011"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 
http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-
DASH_schema_files/DASH-MPD.xsd"
    profiles="urn:mpeg:dash:profile:isoff-live:2011"
    type="static"
    mediaPresentationDuration="PT1M36.4S"
    minBufferTime="PT8.3S">
    <ProgramInformation>
    </ProgramInformation>
    <Period start="PT0.0S">
        <AdaptationSet contentType="video" segmentAlignment="true" bitstreamSwitching="true" frameRate="30/1">
        <Representation id="0" mimeType="video/mp4" codecs="avc1.640028" width="1920" height="1080" frameRate="30/1">
            <SegmentTemplate timescale="15360" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="4">
                <SegmentTimeline>
                    <S t="384000" d="128000" />
                    <S d="71680" />
                    <S d="128000" r="4" />
                    <S d="56832" />
                    <S d="128000" />
                    <S d="72704" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
    <AdaptationSet contentType="audio" segmentAlignment="true" bitstreamSwitching="true">
        <Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="128000" audioSamplingRate="44100">
            <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2" />
            <SegmentTemplate timescale="44100" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="4">
                <SegmentTimeline>
                    <S t="1099755" d="367616" />
                    <S d="205824" />
                    <S d="367616" r="4" />
                    <S d="162816" />
                    <S d="367616" />
                    <S d="207872" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
</Period>

当我尝试在dash.js播放器上播放时,发生错误:

[112] Parsing complete: ( xml2json: 3.50ms, objectiron: 1.76ms, total: 0.00526s) Debug.js:127 
[116] SegmentTimeline detected using calculated Live Edge Time Debug.js:127 
[118] MediaSource attached to element.  Waiting on open... Debug.js:127 
[119] Manifest has been refreshed at Tue Jan 02 2018 01:57:35 GMT+0800 [1514829455.1] Debug.js:127 
[155] MediaSource is open! Debug.js:127 
[156] Duration successfully set to: 96.4 Debug.js:127 
[157] Added 0 inline events Debug.js:127 
[158] video codec: video/mp4;codecs="avc1.640028" Stream.js:225 
Uncaught TypeError: Cannot read property 'type' of null
    at z (Stream.js:225)
    at C (Stream.js:285)
    at D (Stream.js:373)
    at E (Stream.js:398)
    at Object.d [as activate] (Stream.js:107)
    at y (StreamController.js:363)
    at MediaSource.c (StreamController.js:342)

然后它无法播放......

是不是因为我没有在ffmpeg上设置参数,或者这是dash.js中的错误?

我真的被困在这里了!

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并在dash.js中调试了实现。

bandwidth="<XYZ>"添加到清单中的<Representation/>标记可以解决此问题,至少它对我有用。 (其中<XYZ>大于0且理想情况正确)

恼人地ffmpeg没有自动将此添加到.mpd文件中,并且当dash.js初始化时,播放器selectInitialTrack(tracks)遍历轨道getTracksWithHighestBitrate(),选择具有最高比特率的轨道/ bandwidth,只有1个没有带宽属性导致空列表,而不是