From patchwork Wed Apr 12 04:33:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Venkat X-Patchwork-Id: 3371 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp98917vsd; Tue, 11 Apr 2017 21:33:48 -0700 (PDT) X-Received: by 10.223.165.14 with SMTP id i14mr859782wrb.7.1491971628475; Tue, 11 Apr 2017 21:33:48 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e69si6116273wmc.151.2017.04.11.21.33.47; Tue, 11 Apr 2017 21:33:48 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC4446883DA; Wed, 12 Apr 2017 07:33:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f51.google.com (mail-pg0-f51.google.com [74.125.83.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9F971688338 for ; Wed, 12 Apr 2017 07:33:31 +0300 (EEST) Received: by mail-pg0-f51.google.com with SMTP id x125so8645364pgb.0 for ; Tue, 11 Apr 2017 21:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=FqQoEg5/P0MxgoL5Ugbpo0an9LXAy4A5WeUiG1SivDk=; b=pwGv3B8tlJ9zN/J8GgDiGpvZEM2MCq6pKPEomB9YOi7h1csxAXX5EuCqFSTbxLyqNo U7OretFl1b0uncK0kw2/PRlHrgZSQSsBt2jGeeep43M3P90siA3ln9YkANVtPe9tbxxq gJbKzRVFBYL8Eh8+k+PfINJCxDrCFh1Nzx93SEEuOBfrE/5n13vaxGaLBWdnIbxnBGQR E9UlAtd+eg5Fuhu+gLfzaSA/OHVcT5O9C9cXJs6JgLdF/AHzyIe0/scofDNpRjX6cti2 l4UJELkcd5ZKrXaHRTjIDy/GmL62nZ8x1SoWDcR/whFC/FTeu3TfoYQzZX7+6faI6lTm xtug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FqQoEg5/P0MxgoL5Ugbpo0an9LXAy4A5WeUiG1SivDk=; b=XvP8C8r0LCTzVSxaEIDAxtFtY056NMNyGVVYcK7YwfjZScQAlK4qjHRMGHHBGk7jcH tT6yrgalHybzBOznVnF3L6i+FJ97wbxLGRTbLTaM4/sNXSf7czySPBBDoLlLFeT6+Bd4 W7W5m3cKdkXsTO7wX/vxiDwWrDgXZ95bcSMG840yzodFxO+kh+8vjFrfwMMTqbM68m4M ++kDNA0NcEVkqCueGfsSUgOMnMmOtxfFdE1ilML/BbaAaWwA0WAbZQQqjcSAmrTTaWSn 6DYWyZ5XPNfEBqekGa8D8YHFqeIdIW3V+mcwUJN/zfTZUkKlokf8ZmovYOaslhHxTD0c +P+A== X-Gm-Message-State: AFeK/H0ZZubeDp27WxPR6u2HU3MUnFzaY6SKj6qxOuIICfYZvmlYdJ2L+usmEPOeQc6fzQoj X-Received: by 10.98.79.90 with SMTP id d87mr64649844pfb.126.1491971615305; Tue, 11 Apr 2017 21:33:35 -0700 (PDT) Received: from vigneshv2.mtv.corp.google.com ([100.98.112.31]) by smtp.gmail.com with ESMTPSA id e123sm12672620pfa.92.2017.04.11.21.33.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 21:33:34 -0700 (PDT) From: Vignesh Venkatasubramanian To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Apr 2017 21:33:28 -0700 Message-Id: <20170412043328.21470-1-vigneshv@google.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog Subject: [FFmpeg-devel] [PATCH] webm_dash_manifest: Add option to specify bandwidth X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Vignesh Venkatasubramanian MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavformat/matroskadec.c | 19 ++++++++++++++++++- libavformat/webmdashenc.c | 11 ++++++++--- tests/fate/vpx.mak | 3 +++ tests/ref/fate/webm-dash-manifest-live-bandwidth | 24 ++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tests/ref/fate/webm-dash-manifest-live-bandwidth 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..02e7ec8afc 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 provied, 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) diff --git a/tests/fate/vpx.mak b/tests/fate/vpx.mak index 46658ec2f1..2662bd2bd8 100644 --- a/tests/fate/vpx.mak +++ b/tests/fate/vpx.mak @@ -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-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-2451: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp8/RRSF49-short.webm -vsync cfr -an diff --git a/tests/ref/fate/webm-dash-manifest-live-bandwidth b/tests/ref/fate/webm-dash-manifest-live-bandwidth new file mode 100644 index 0000000000..18b8951283 --- /dev/null +++ b/tests/ref/fate/webm-dash-manifest-live-bandwidth @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + +