Add an option to webm_dash_manifest demuxer to specify a value for "bandwidth" field in the DASH manifest. The value is then used by the muxer. Fixes an existing FIXME in the code. Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com> Signed-off-by: James Zern <jzern@google.com>tags/n3.4
| @@ -364,6 +364,9 @@ typedef struct MatroskaDemuxContext { | |||||
| /* WebM DASH Manifest live flag/ */ | /* WebM DASH Manifest live flag/ */ | ||||
| int is_live; | int is_live; | ||||
| /* Bandwidth value for WebM DASH Manifest */ | |||||
| int bandwidth; | |||||
| } MatroskaDemuxContext; | } MatroskaDemuxContext; | ||||
| typedef struct MatroskaBlock { | typedef struct MatroskaBlock { | ||||
| @@ -3912,7 +3915,20 @@ static int webm_dash_manifest_read_header(AVFormatContext *s) | |||||
| av_dict_set_int(&s->streams[0]->metadata, TRACK_NUMBER, tracks[0].num, 0); | av_dict_set_int(&s->streams[0]->metadata, TRACK_NUMBER, tracks[0].num, 0); | ||||
| // parse the cues and populate Cue related fields | // parse the cues and populate Cue related fields | ||||
| return matroska->is_live ? 0 : webm_dash_manifest_cues(s); | |||||
| if (!matroska->is_live) { | |||||
| ret = webm_dash_manifest_cues(s); | |||||
| if (ret < 0) { | |||||
| av_log(s, AV_LOG_ERROR, "Error parsing Cues\n"); | |||||
| return ret; | |||||
| } | |||||
| } | |||||
| // use the bandwidth from the command line if it was provided | |||||
| if (matroska->bandwidth > 0) { | |||||
| av_dict_set_int(&s->streams[0]->metadata, BANDWIDTH, | |||||
| matroska->bandwidth, 0); | |||||
| } | |||||
| return 0; | |||||
| } | } | ||||
| static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt) | static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt) | ||||
| @@ -3923,6 +3939,7 @@ static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
| #define OFFSET(x) offsetof(MatroskaDemuxContext, x) | #define OFFSET(x) offsetof(MatroskaDemuxContext, x) | ||||
| static const AVOption options[] = { | static const AVOption options[] = { | ||||
| { "live", "flag indicating that the input is a live file that only has the headers.", OFFSET(is_live), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, | { "live", "flag indicating that the input is a live file that only has the headers.", OFFSET(is_live), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, | ||||
| { "bandwidth", "bandwidth of this stream to be specified in the DASH manifest.", OFFSET(bandwidth), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, | |||||
| { NULL }, | { NULL }, | ||||
| }; | }; | ||||
| @@ -182,14 +182,19 @@ static int write_representation(AVFormatContext *s, AVStream *stream, char *id, | |||||
| AVDictionaryEntry *cues_end = av_dict_get(stream->metadata, CUES_END, NULL, 0); | AVDictionaryEntry *cues_end = av_dict_get(stream->metadata, CUES_END, NULL, 0); | ||||
| AVDictionaryEntry *filename = av_dict_get(stream->metadata, FILENAME, NULL, 0); | AVDictionaryEntry *filename = av_dict_get(stream->metadata, FILENAME, NULL, 0); | ||||
| AVDictionaryEntry *bandwidth = av_dict_get(stream->metadata, BANDWIDTH, NULL, 0); | AVDictionaryEntry *bandwidth = av_dict_get(stream->metadata, BANDWIDTH, NULL, 0); | ||||
| const char *bandwidth_str; | |||||
| if ((w->is_live && (!filename)) || | if ((w->is_live && (!filename)) || | ||||
| (!w->is_live && (!irange || !cues_start || !cues_end || !filename || !bandwidth))) { | (!w->is_live && (!irange || !cues_start || !cues_end || !filename || !bandwidth))) { | ||||
| return AVERROR_INVALIDDATA; | return AVERROR_INVALIDDATA; | ||||
| } | } | ||||
| avio_printf(s->pb, "<Representation id=\"%s\"", id); | avio_printf(s->pb, "<Representation id=\"%s\"", id); | ||||
| // FIXME: For live, This should be obtained from the input file or as an AVOption. | |||||
| avio_printf(s->pb, " bandwidth=\"%s\"", | |||||
| w->is_live ? (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? "128000" : "1000000") : bandwidth->value); | |||||
| // if bandwidth for live was not provided, use a default | |||||
| if (w->is_live && !bandwidth) { | |||||
| bandwidth_str = (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? "128000" : "1000000"; | |||||
| } else { | |||||
| bandwidth_str = bandwidth->value; | |||||
| } | |||||
| avio_printf(s->pb, " bandwidth=\"%s\"", bandwidth_str); | |||||
| if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_width) | if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_width) | ||||
| avio_printf(s->pb, " width=\"%d\"", stream->codecpar->width); | avio_printf(s->pb, " width=\"%d\"", stream->codecpar->width); | ||||
| if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_height) | if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_height) | ||||
| @@ -70,6 +70,9 @@ fate-webm-dash-manifest-representations: CMD = run $(FFMPEG) -nostdin -f webm_da | |||||
| FATE_VP8-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER) += fate-webm-dash-manifest-live | FATE_VP8-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER) += fate-webm-dash-manifest-live | ||||
| fate-webm-dash-manifest-live: CMD = run $(FFMPEG) -nostdin -f webm_dash_manifest -live 1 -i $(TARGET_SAMPLES)/vp8/dash_live_video_360.hdr -f webm_dash_manifest -live 1 -i $(TARGET_SAMPLES)/vp8/dash_live_audio_171.hdr -c copy -map 0 -map 1 -f webm_dash_manifest -live 1 -adaptation_sets "id=0,streams=0 id=1,streams=1" -chunk_start_index 1 -chunk_duration_ms 5000 -time_shift_buffer_depth 7200 -minimum_update_period 60 -debug_mode 1 - | fate-webm-dash-manifest-live: CMD = run $(FFMPEG) -nostdin -f webm_dash_manifest -live 1 -i $(TARGET_SAMPLES)/vp8/dash_live_video_360.hdr -f webm_dash_manifest -live 1 -i $(TARGET_SAMPLES)/vp8/dash_live_audio_171.hdr -c copy -map 0 -map 1 -f webm_dash_manifest -live 1 -adaptation_sets "id=0,streams=0 id=1,streams=1" -chunk_start_index 1 -chunk_duration_ms 5000 -time_shift_buffer_depth 7200 -minimum_update_period 60 -debug_mode 1 - | ||||
| FATE_VP8-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER) += fate-webm-dash-manifest-live-bandwidth | |||||
| fate-webm-dash-manifest-live-bandwidth: CMD = run $(FFMPEG) -nostdin -f webm_dash_manifest -live 1 -bandwidth 100 -i $(TARGET_SAMPLES)/vp8/dash_live_video_360.hdr -f webm_dash_manifest -live 1 -bandwidth 200 -i $(TARGET_SAMPLES)/vp8/dash_live_audio_171.hdr -c copy -map 0 -map 1 -f webm_dash_manifest -live 1 -adaptation_sets "id=0,streams=0 id=1,streams=1" -chunk_start_index 1 -chunk_duration_ms 5000 -time_shift_buffer_depth 7200 -minimum_update_period 60 -debug_mode 1 - | |||||
| FATE_VP8-$(call DEMDEC, MATROSKA, VP8) += fate-vp8-2451 | FATE_VP8-$(call DEMDEC, MATROSKA, VP8) += fate-vp8-2451 | ||||
| fate-vp8-2451: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp8/RRSF49-short.webm -vsync cfr -an | fate-vp8-2451: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp8/RRSF49-short.webm -vsync cfr -an | ||||
| @@ -0,0 +1,24 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <MPD | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xmlns="urn:mpeg:DASH:schema:MPD:2011" | |||||
| xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011" | |||||
| type="dynamic" | |||||
| minBufferTime="PT1S" | |||||
| profiles="urn:mpeg:dash:profile:isoff-live:2011" | |||||
| availabilityStartTime="" | |||||
| timeShiftBufferDepth="PT7200S" | |||||
| minimumUpdatePeriod="PT60S"> | |||||
| <Period id="0" start="PT0S" > | |||||
| <AdaptationSet id="0" mimeType="video/webm" codecs="vp9" bitstreamSwitching="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1"> | |||||
| <ContentComponent id="1" type="video"/> | |||||
| <SegmentTemplate timescale="1000" duration="5000" media="dash_live_video_$RepresentationID$_$Number$.chk" startNumber="1" initialization="dash_live_video_$RepresentationID$.hdr"/> | |||||
| <Representation id="360" bandwidth="100" width="640" height="360" codecs="vp9" mimeType="video/webm" startsWithSAP="1"></Representation> | |||||
| </AdaptationSet> | |||||
| <AdaptationSet id="1" mimeType="audio/webm" codecs="vorbis" bitstreamSwitching="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1"> | |||||
| <ContentComponent id="1" type="audio"/> | |||||
| <SegmentTemplate timescale="1000" duration="5000" media="dash_live_audio_$RepresentationID$_$Number$.chk" startNumber="1" initialization="dash_live_audio_$RepresentationID$.hdr"/> | |||||
| <Representation id="171" bandwidth="200" audioSamplingRate="32000" codecs="vorbis" mimeType="audio/webm" startsWithSAP="1"></Representation> | |||||
| </AdaptationSet> | |||||
| </Period> | |||||
| </MPD> | |||||