From patchwork Wed Jan 18 09:27:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Rapp X-Patchwork-Id: 2243 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp931615vsb; Wed, 18 Jan 2017 01:27:29 -0800 (PST) X-Received: by 10.28.203.75 with SMTP id b72mr2213462wmg.110.1484731649004; Wed, 18 Jan 2017 01:27:29 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r24si3852590wrr.241.2017.01.18.01.27.28; Wed, 18 Jan 2017 01:27:28 -0800 (PST) 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; 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 5896D68A242; Wed, 18 Jan 2017 11:27:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from p1002.netstorage.at (p1002.netstorage.at [89.207.146.186]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9009068A1F3 for ; Wed, 18 Jan 2017 11:26:53 +0200 (EET) Received: from mailix (noaport.de [46.237.252.213]) by p1002.netstorage.at (Postfix) with ESMTPA id 9403B81A28 for ; Wed, 18 Jan 2017 10:27:03 +0100 (CET) Received: from frogstar-a.kuhnle.local (frogstar-a.kuhnle.local [192.168.0.26]) by mailix with ESMTPA ; Wed, 18 Jan 2017 10:27:03 +0100 From: Tobias Rapp To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Jan 2017 10:27:01 +0100 Message-Id: <1484731623-21636-2-git-send-email-t.rapp@noa-archive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484731623-21636-1-git-send-email-t.rapp@noa-archive.com> References: <1484731623-21636-1-git-send-email-t.rapp@noa-archive.com> X-PPP-Message-ID: <20170118092703.17432.73637@p1002.netstorage.at> X-PPP-Vhost: noa-archive.com Subject: [FFmpeg-devel] [PATCH 1/3] ffmpeg: pass output stream duration as a hint to the muxer 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Tobias Rapp --- ffmpeg.c | 9 +++++++++ libavformat/avformat.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index 6d1e358..977708c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2908,6 +2908,10 @@ static int init_output_stream_streamcopy(OutputStream *ost) if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); + // copy estimated duration as a hint to the muxer + if (ost->st->duration <= 0 && ist->st->duration > 0) + ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); + // copy disposition ost->st->disposition = ist->st->disposition; @@ -3333,6 +3337,11 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) // copy timebase while removing common factors if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); + + // copy estimated duration as a hint to the muxer + if (ost->st->duration <= 0 && ist && ist->st->duration > 0) + ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); + ost->st->codec->codec= ost->enc_ctx->codec; } else if (ost->stream_copy) { ret = init_output_stream_streamcopy(ost); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index af257e4..ebb0e05 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -930,6 +930,9 @@ typedef struct AVStream { * Decoding: duration of the stream, in stream time base. * If a source file does not specify a duration, but does specify * a bitrate, this value will be estimated from bitrate and file size. + * + * Encoding: May be set by the caller before avformat_write_header() to + * provide a hint to the muxer about the estimated duration. */ int64_t duration;