[FFmpeg-devel,v2,3/4] fftools/ffmpeg: support variable dimension encode

Submitted by Linjie Fu on July 30, 2019, 4:45 a.m.

Details

Message ID 1564461944-4820-1-git-send-email-linjie.fu@intel.com
State New
Headers show

Commit Message

Linjie Fu July 30, 2019, 4:45 a.m.
Flush encoders when dimension change happens.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 fftools/ffmpeg.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d52430..cb3adb2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -130,6 +130,7 @@  static void do_video_stats(OutputStream *ost, int frame_size);
 static BenchmarkTimeStamps get_benchmark_time_stamps(void);
 static int64_t getmaxrss(void);
 static int ifilter_has_all_input_formats(FilterGraph *fg);
+static void flush_encoders(void);
 
 static int run_as_daemon  = 0;
 static int nb_frames_dup = 0;
@@ -1067,6 +1068,19 @@  static void do_video_out(OutputFile *of,
     InputStream *ist = NULL;
     AVFilterContext *filter = ost->filter->filter;
 
+    /* flush encoders in dynamic resolution encode */
+    if (next_picture && (enc->width != next_picture->width ||
+                         enc->height != next_picture->height)) {
+        flush_encoders();
+        avcodec_flush_buffers(enc);
+
+        if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
+            av_log(NULL, AV_LOG_ERROR, "Dynamic resolution encode "
+                            "is not supported by %s.\n", enc->codec->name);
+            goto error;
+        }
+    }
+
     if (ost->source_index >= 0)
         ist = input_streams[ost->source_index];