From 62c27fdba43def4cdc2fb6f2df60c7ac87918d6c Mon Sep 17 00:00:00 2001 From: Vignesh Venkatasubramanian Date: Tue, 11 Apr 2017 21:33:28 -0700 Subject: webm_dash_manifest: Add option to specify bandwidth 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 Signed-off-by: James Zern --- libavformat/matroskadec.c | 19 ++++++++++++++++++- libavformat/webmdashenc.c | 11 ++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'libavformat') diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3ec1636584..d42113be94 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -364,6 +364,9 @@ typedef struct MatroskaDemuxContext { /* WebM DASH Manifest live flag/ */ int is_live; + + /* Bandwidth value for WebM DASH Manifest */ + int bandwidth; } MatroskaDemuxContext; 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); // 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) @@ -3923,6 +3939,7 @@ static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt) #define OFFSET(x) offsetof(MatroskaDemuxContext, x) 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 }, + { "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 }, }; diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c index d4b3146790..602726caf9 100644 --- a/libavformat/webmdashenc.c +++ b/libavformat/webmdashenc.c @@ -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 *filename = av_dict_get(stream->metadata, FILENAME, NULL, 0); AVDictionaryEntry *bandwidth = av_dict_get(stream->metadata, BANDWIDTH, NULL, 0); + const char *bandwidth_str; if ((w->is_live && (!filename)) || (!w->is_live && (!irange || !cues_start || !cues_end || !filename || !bandwidth))) { return AVERROR_INVALIDDATA; } avio_printf(s->pb, "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) avio_printf(s->pb, " width=\"%d\"", stream->codecpar->width); if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_height) -- cgit v1.2.3