So it can be used by the rate control as a better estimate of it.
Before the time_base was used and that confused some rate-control
algorithms or cause setup failures in some of the encoders.
---
 avtools/avconv.c     |  7 +++++--
 avtools/avconv.h     |  2 ++
 avtools/avconv_opt.c | 10 ++++++++--
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/avtools/avconv.c b/avtools/avconv.c
index ac15464a8d..282cc7ef3d 100644
--- a/avtools/avconv.c
+++ b/avtools/avconv.c
@@ -2045,9 +2045,12 @@ static int init_output_stream_encode(OutputStream *ost)
             ost->filter->filter->inputs[0]->sample_aspect_ratio;
         enc_ctx->pix_fmt = ost->filter->filter->inputs[0]->format;
 
-        enc_ctx->framerate = ost->frame_rate;
+        enc_ctx->framerate = ost->avg_frame_rate;
 
-        ost->st->avg_frame_rate = ost->frame_rate;
+        if (ost->frame_rate.num)
+            ost->st->avg_frame_rate = ost->frame_rate;
+        else
+            ost->st->avg_frame_rate = ost->avg_frame_rate;
 
         if (dec_ctx &&
             (enc_ctx->width   != dec_ctx->width  ||
diff --git a/avtools/avconv.h b/avtools/avconv.h
index 0d24c71a74..b8e2fecac8 100644
--- a/avtools/avconv.h
+++ b/avtools/avconv.h
@@ -378,6 +378,8 @@ typedef struct OutputStream {
 
     /* video only */
     AVRational frame_rate;
+    /* rate-control hint */
+    AVRational avg_frame_rate;
     int force_fps;
     int top_field_first;
 
diff --git a/avtools/avconv_opt.c b/avtools/avconv_opt.c
index a4a225c3e9..1d6d2abaa0 100644
--- a/avtools/avconv_opt.c
+++ b/avtools/avconv_opt.c
@@ -1853,6 +1853,7 @@ loop_end:
          * in such a case, set ost->frame_rate
          */
         if (ost->encoding_needed && ost->enc_ctx->codec_type == 
AVMEDIA_TYPE_VIDEO) {
+            InputStream *ist = ost->source_index >= 0 ? 
input_streams[ost->source_index] : NULL;
             int format_cfr = !(oc->oformat->flags & (AVFMT_NOTIMESTAMPS | 
AVFMT_VARIABLE_FPS));
             int need_cfr = !!ost->frame_rate.num;
 
@@ -1861,8 +1862,6 @@ loop_end:
                 need_cfr = 1;
 
             if (need_cfr && !ost->frame_rate.num) {
-                InputStream *ist = ost->source_index >= 0 ? 
input_streams[ost->source_index] : NULL;
-
                 if (ist && ist->framerate.num)
                     ost->frame_rate = ist->framerate;
                 else if (ist && ist->st->avg_frame_rate.num)
@@ -1882,6 +1881,13 @@ loop_end:
                 int idx = av_find_nearest_q_idx(ost->frame_rate, 
ost->enc->supported_framerates);
                 ost->frame_rate = ost->enc->supported_framerates[idx];
             }
+
+            if (ost->frame_rate.num)
+                ost->avg_frame_rate = ost->frame_rate;
+            else if (ist && ist->framerate.num)
+                ost->avg_frame_rate = ist->framerate;
+            else if (ist && ist->st->avg_frame_rate.num)
+                ost->avg_frame_rate = ist->st->avg_frame_rate;
         }
 
         /* set the filter output constraints */
-- 
2.12.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to