From patchwork Fri Mar 23 05:26:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dixit, Vishwanath" X-Patchwork-Id: 8111 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp19028jad; Thu, 22 Mar 2018 22:26:30 -0700 (PDT) X-Google-Smtp-Source: AG47ELvYnyf886iaC19brmTmQZBUlb2FUiqhuTWBXG0JYaBaPMuA4cBVrcBtzzJJ7SzlR2Epoh/4 X-Received: by 10.223.172.226 with SMTP id o89mr9703107wrc.264.1521782790352; Thu, 22 Mar 2018 22:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521782790; cv=none; d=google.com; s=arc-20160816; b=prApNUZQ4RTQB7K53iWDtXsTW8mxl3JdQ/fGo6nhXM/iGtGLHCkJQw8J19kUty/8At TEnfemBtbOMhR5ij2WZeOh0k1rMkqRClb4IgjYb8eAEpnn3Ern1kN0/QsKVFlPaoHN5T f4ZZZ8KplUixjk6EXkyXCj66a3VqOdUpoVLEUrCG57PV6kmlh/WLYPVmCFNAWaqKyeyY kL3ZaVGzoBns35FA7FodooPn0Vo/pkOIXHHPMQP7b3bJxDp6NkOFh9YLEW/uYE43jlwp E9v45gy+j41UkEqP+MRzX7yiUt0YbgzEbH/uqXdIqhpIEKhYdpA8oozyzPhzFrRdXpe6 hpOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=fD80ZNAdEnG4vib7eDryvR3GTMVX7sNFe5OpmHZVxsw=; b=AjTZf5N5aP0aDSmAVDYzVnU6PiNAAgvGy1mITP5n2NNoG2G5j70pfYl/uTOgBvp088 9F5xV/JIks8XzziPUWg9meVjh0Lxo/4EZJALzGzMoiddJTxPzftwACURzALKpx6hiqEz wZwh4b7dxavGKBFQuXliYEjrJWUimYx11MbOOiFDZX34YL7b1JVTcuGt4NzQplDwyUZe XqsRPxCgSVJRgSHkF56ZWKiQAQ6lcxWZ6ryROtu8mAiubxPekltHvKsW/EHoDL83S7qW SuNYTTeXaZsQwoFNJ8go5P5pQxXG4sxs4coJVUqA5986yRbbzwZb83Yy9anRGymFgX87 hVWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=2Y0Ff2RO; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q10si5731722wrf.62.2018.03.22.22.26.29; Thu, 22 Mar 2018 22:26:30 -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=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=2Y0Ff2RO; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CB4CE689723; Fri, 23 Mar 2018 07:26:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a2i831.smtp2go.com (a2i831.smtp2go.com [103.47.207.63]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E580F6803BD for ; Fri, 23 Mar 2018 07:26:05 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1521783687; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=5BdWsx4C0tO3tdZ+HKUhfeVg/IneCTrrtd9m807Svls=; b=2Y0Ff2RO hR/ovHkoLkwvmm9pj/ZbRVoNW55wHuGFEHChhJOQkLuN/ZSYmDvy5NV7NG5ScdX/rI5F1U7zEdnHq 1at8+odXlCTgXaQRJY6FSqhEtRzHF6bC9bbmwi/bvV33YT6QLQfTrOWvsnEy3TIeBp4juVnoPrmfy vMhdWxDk0hkYEfTf9JnNzIz9tGUq4Yy+MKm90uuY+vdWXAfMG152vL/b0kfcuMfleBxU5Nm+FwKoY kHCrhtUdnPVTYxukea04sELUAFdlIpIwKsNUCg7jxq7NmSbizBgfsd1et9pfTWyerAn7GodtI7pbE 3gpl68Y8ZFXLMhgsyr4AZQk7+w==; From: vdixit@akamai.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Mar 2018 10:56:13 +0530 Message-Id: <1521782773-25778-1-git-send-email-vdixit@akamai.com> X-Mailer: git-send-email 1.9.1 X-Smtpcorp-Track: 1-zFDVNmF8nw65.tuB4_IgVk Feedback-ID: 337386m:337386asVRLGB:337386stx_3c9tfx:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH 02/11] avformat/dashenc: segmentation at the configured segment duration rate 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: Vishwanath Dixit MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Vishwanath Dixit When use_template is enabled and use_timeline is disabled, typically it is required to generate the segments at the configured segment duration rate on an average. This commit is particularly needed to handle the segmentation when video frame rates are fractional like 29.97 or 59.94 fps. --- doc/muxers.texi | 4 +++- libavformat/dashenc.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 65eec92..7130cd0 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -226,7 +226,9 @@ ffmpeg -re -i -map 0 -map 0 -c:a libfdk_aac -c:v libx264 @table @option @item -seg_duration @var{microseconds} -Set the segment length in microseconds. +Set the segment length in microseconds. The value is treated as average segment +duration when use_template is enabled and use_timeline is disabled or as minimum +segment duration for all the other use cases. @item -window_size @var{size} Set the maximum number of segments kept in the manifest. @item -extra_window_size @var{size} diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index bdd5b56..a489f5e 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1257,6 +1257,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) DASHContext *c = s->priv_data; AVStream *st = s->streams[pkt->stream_index]; OutputStream *os = &c->streams[pkt->stream_index]; + int64_t seg_end_duration, elapsed_duration; int ret; ret = update_stream_extradata(s, os, st->codecpar); @@ -1284,10 +1285,18 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) if (os->first_pts == AV_NOPTS_VALUE) os->first_pts = pkt->pts; + if (c->use_template && !c->use_timeline) { + elapsed_duration = pkt->pts - os->first_pts; + seg_end_duration = (int64_t) os->segment_index * c->seg_duration; + } else { + elapsed_duration = pkt->pts - os->start_pts; + seg_end_duration = c->seg_duration; + } + if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written && - av_compare_ts(pkt->pts - os->start_pts, st->time_base, - c->seg_duration, AV_TIME_BASE_Q) >= 0) { + av_compare_ts(elapsed_duration, st->time_base, + seg_end_duration, AV_TIME_BASE_Q) >= 0) { int64_t prev_duration = c->last_duration; c->last_duration = av_rescale_q(pkt->pts - os->start_pts, @@ -1427,7 +1436,7 @@ static const AVOption options[] = { { "adaptation_sets", "Adaptation sets. Syntax: id=0,streams=0,1,2 id=1,streams=3,4 and so on", OFFSET(adaptation_sets), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, { "window_size", "number of segments kept in the manifest", OFFSET(window_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, E }, { "extra_window_size", "number of segments kept outside of the manifest before removing from disk", OFFSET(extra_window_size), AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX, E }, - { "seg_duration", "minimum segment duration (in microseconds)", OFFSET(seg_duration), AV_OPT_TYPE_INT, { .i64 = 5000000 }, 0, INT_MAX, E }, + { "seg_duration", "value in microseconds, average segment duration when use_template is enabled and use_timeline is disabled or minimum segment duration in other cases ", OFFSET(seg_duration), AV_OPT_TYPE_INT, { .i64 = 5000000 }, 0, INT_MAX, E }, { "remove_at_exit", "remove all segments when finished", OFFSET(remove_at_exit), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { "use_template", "Use SegmentTemplate instead of SegmentList", OFFSET(use_template), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, E }, { "use_timeline", "Use SegmentTimeline in SegmentTemplate", OFFSET(use_timeline), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, E },