[FFmpeg-devel] [PATCH, v3 2/3] fftools/ffmpeg: support variable resolution encode
Linjie Fu
linjie.fu at intel.com
Wed Jul 31 08:05:38 EEST 2019
Flush encoders when resolution change happens.
Use AV_CODEC_CAP_PARAM_CHANGE flag for encoder to indicate whether
it supports variable/dynamic resolution encoding.
Signed-off-by: Linjie Fu <linjie.fu at intel.com>
---
[v3]: use AV_CODEC_CAP_PARAM_CHANGE flag
fftools/ffmpeg.c | 14 ++++++++++++++
libavcodec/rawenc.c | 1 +
2 files changed, 15 insertions(+)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d52430..35b0f89 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_PARAM_CHANGE)) {
+ 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];
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index d181b74..9e8cb57 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -92,4 +92,5 @@ AVCodec ff_rawvideo_encoder = {
.id = AV_CODEC_ID_RAWVIDEO,
.init = raw_encode_init,
.encode2 = raw_encode,
+ .capabilities = AV_CODEC_CAP_PARAM_CHANGE,
};
--
2.7.4
More information about the ffmpeg-devel
mailing list