diff mbox

[FFmpeg-devel,1/4] ffmpeg: pass output stream duration as a hint to the muxer

Message ID 1484660361-21502-2-git-send-email-t.rapp@noa-archive.com
State Accepted
Commit c324e2c5db26cb1ac936b192dc1ac86f7b6db45c
Headers show

Commit Message

Tobias Rapp Jan. 17, 2017, 1:39 p.m. UTC
Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com>
---
 ffmpeg.c               | 9 +++++++++
 libavformat/avformat.h | 3 +++
 2 files changed, 12 insertions(+)

Comments

Michael Niedermayer Jan. 19, 2017, 1:52 a.m. UTC | #1
On Tue, Jan 17, 2017 at 02:39:18PM +0100, Tobias Rapp wrote:
> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com>
> ---
>  ffmpeg.c               | 9 +++++++++
>  libavformat/avformat.h | 3 +++
>  2 files changed, 12 insertions(+)

applied

thx

[...]
diff mbox

Patch

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;