From patchwork Thu Mar 12 19:01:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Martin X-Patchwork-Id: 18140 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0E9FF44BD3E for ; Thu, 12 Mar 2020 21:01:38 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DFBC768A777; Thu, 12 Mar 2020 21:01:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6557768A76C for ; Thu, 12 Mar 2020 21:01:31 +0200 (EET) Received: by mail-wm1-f49.google.com with SMTP id f7so7606982wml.4 for ; Thu, 12 Mar 2020 12:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FAVI7Y13FoPSVUXQ3ykYoPZ2ClljqJJQ/h4jkiwd8n4=; b=m5isQT7+qYIb6fieP3m1YFVgux6xjP3Zdq11zRzadIIxe9BJu1bjaabEHkmY33nh/q lc3nRHX+SLLo2IJs2xw/yYEbo/4N/uTz7zxN3XK6/RfkxmDg2Hxlkbxq2VXXltw4G8Iy vDBsZCR0TSrr1cG8WtpdToQIpUNk5PKwIqa5ugBJtGdeKB+ZKCpO8kwYpHjK8ZJIq9T0 jQIHxrt8B2/eNStSFsvrD9+sf50BiekNxFeSZ4r98IZU/lvgu0vyIak7BIL9y4uQR7z2 GBu92Bua2Ku/nW/SJvNh/l9wDVPhpeq4fo6o52UkjzPK1SZxEP8PgcvjBB+88d7AV1yn zPww== 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:mime-version :content-transfer-encoding; bh=FAVI7Y13FoPSVUXQ3ykYoPZ2ClljqJJQ/h4jkiwd8n4=; b=I+kjlwAkzqq3H7tct8X+lSSK1MddicgzzpP8Uux1gkePEK2NvHABJ+Mfl9i12uvQ+L ZRKUyTBOXRK59qaNL+0yEqL6T78jz+dXF9LZCtinHFuoa1MX/d+dbLyFpQgbj2DkXcQx ViLOWDCxq+WSyckBp8glEzW4IV3Rjd+i3AdZjUPXPJWBW8LdoLYKMqes7cDw9IXtpo/0 1jdOUkm6tMYy/5wobLd/jFuAESBaxcMIbJ/UpBrwsAr678fmruzBr2bGhd6vJ/alXYRA 38LXqiyha7FopnLpGAwYSWWZonzGGCQFBzTUhUxD+jKB5N0Zjfj/lbkLoEjztMuoIkoL hFPw== X-Gm-Message-State: ANhLgQ09DrddRrG/se5VmFLRI2AIIISXoSJynv/8U4lUgjqeyZ8u3IK/ gazmLx0ZI/TTF++siem5kdODMKVlIUM= X-Google-Smtp-Source: ADFU+vsBeeo4U46YAbfN1VcWsZ2xX6Y3z1z2GVxOFRoI1HlwNPahY3xVS62B2NTGFZQRA3h9bqSj8Q== X-Received: by 2002:a1c:7214:: with SMTP id n20mr6074205wmc.24.1584039690301; Thu, 12 Mar 2020 12:01:30 -0700 (PDT) Received: from fon.dmdo-fon (139.red-79-153-143.dynamicip.rima-tde.net. [79.153.143.139]) by smtp.gmail.com with ESMTPSA id x17sm37611715wrt.31.2020.03.12.12.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 12:01:29 -0700 (PDT) From: David Martin To: ffmpeg-devel@ffmpeg.org Date: Thu, 12 Mar 2020 20:01:26 +0100 Message-Id: <20200312190126.48034-1-davimdo@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavf/dashenc: add dash SegmentBase manifest generator 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: David Martin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Support to generate dash SegmentBase manifests, by adding "use_segmentbase" option to dash muxer. SegmentBase manifest is defined in ISO DASH Specification section 5.3.9.2 and has as prerequisite the option "global_sidx" as players will use this box to have a reference to all fragments in the media. Signed-off-by: David Martin --- doc/muxers.texi | 5 +++++ libavformat/dashenc.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/doc/muxers.texi b/doc/muxers.texi index d304181671..fbaa357f2d 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -309,6 +309,11 @@ escaped. @item global_sidx @var{global_sidx} Write global SIDX atom. Applicable only for single file, mp4 output, non-streaming mode. +@item use_segmentbase @var{use_segmentbase} +Generates a dash SegmentBase manifest as defined in section 5.3.9.2 of the ISO +DASH specification. Only applicable when global sidx is enabled since the player +uses it to have a reference of all the segments in the media + @item dash_segment_type @var{dash_segment_type} Possible values: @table @option diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 94d463972a..39286e9e11 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -193,6 +193,8 @@ typedef struct DASHContext { int profile; int64_t target_latency; int target_latency_refid; + int use_segmentbase; + int64_t sidx_size; } DASHContext; static struct codec_string { @@ -694,6 +696,12 @@ static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont avio_printf(out, "\t\t\t\t\t\n"); } avio_printf(out, "\t\t\t\t\n"); + } else if (c->single_file && c->use_segmentbase && final) { + avio_printf(out, "\t\t\t\t%s\n", os->initfile); + int64_t init_segment_size = os->init_start_pos + os->init_range_length; + avio_printf(out, "\t\t\t\t\n", init_segment_size - c->sidx_size, init_segment_size - 1, AV_TIME_BASE); + avio_printf(out, "\t\t\t\t\t\n", os->init_start_pos, init_segment_size - c->sidx_size - 1); + avio_printf(out, "\t\t\t\t\n"); } else if (c->single_file) { avio_printf(out, "\t\t\t\t%s\n", os->initfile); avio_printf(out, "\t\t\t\t\n", AV_TIME_BASE, FFMIN(os->seg_duration, os->last_duration), start_number); @@ -1389,6 +1397,12 @@ static int dash_init(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "Global SIDX option will be ignored as streaming is enabled\n"); c->global_sidx = 0; } + + if (c->use_segmentbase && !c->global_sidx) { + av_log(s, AV_LOG_WARNING, "SegmentBase manifest signaling option will be ignored as global SIDX is not enabled\n"); + c->use_segmentbase = 0; + } + if (c->frag_type == FRAG_TYPE_NONE && c->streaming) { av_log(s, AV_LOG_VERBOSE, "Changing frag_type from none to every_frame as streaming is enabled\n"); c->frag_type = FRAG_TYPE_EVERY_FRAME; @@ -1981,6 +1995,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream) if (c->global_sidx) { int j, start_index, start_number; int64_t sidx_size = avio_tell(os->ctx->pb) - file_size; + c->sidx_size = sidx_size; get_start_index_number(os, c, &start_index, &start_number); if (start_index >= os->nb_segments || os->segment_type != SEGMENT_TYPE_MP4) @@ -2350,6 +2365,7 @@ static const AVOption options[] = { { "index_correction", "Enable/Disable segment index correction logic", OFFSET(index_correction), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { "format_options","set list of options for the container format (mp4/webm) used for dash", OFFSET(format_options), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, E}, { "global_sidx", "Write global SIDX atom. Applicable only for single file, mp4 output, non-streaming mode", OFFSET(global_sidx), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, + { "use_segmentbase", "Use SegmentBase in Representation", OFFSET(use_segmentbase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { "dash_segment_type", "set dash segment files type", OFFSET(segment_type_option), AV_OPT_TYPE_INT, {.i64 = SEGMENT_TYPE_AUTO }, 0, SEGMENT_TYPE_NB - 1, E, "segment_type"}, { "auto", "select segment file format based on codec", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_AUTO }, 0, UINT_MAX, E, "segment_type"}, { "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MP4 }, 0, UINT_MAX, E, "segment_type"},