This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
0013-fftools-ffmpeg-support-variable-resolution-encode.patch
61 lines (53 loc) · 2.15 KB
/
0013-fftools-ffmpeg-support-variable-resolution-encode.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 0642301b19e877d1f13d8331de1464ee63516a94 Mon Sep 17 00:00:00 2001
From: Fei Wang <[email protected]>
Date: Mon, 2 Nov 2020 10:45:29 +0800
Subject: [PATCH] fftools/ffmpeg: support variable resolution encode
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 <[email protected]>
---
fftools/ffmpeg.c | 14 ++++++++++++++
libavcodec/rawenc.c | 1 +
2 files changed, 15 insertions(+)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7a27258758..0038774b81 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;
@@ -1136,6 +1137,19 @@ static void do_video_out(OutputFile *of,
init_output_stream_wrapper(ost, next_picture, 1);
sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
+ /* 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 d181b74570..0cccd21420 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 | AV_CODEC_CAP_ENCODER_FLUSH,
};
--
2.17.1