aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-09 00:44:58 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-06-12 11:42:59 +0200
commit17b5fc2e51a3bb5a7fc10cbd177d88ef1c025527 (patch)
treebc81f91c9d8d50e59141b4d7ece6a007a2bc4904 /libavcodec/mpegvideo_enc.c
parent17501b22674ac738847e3d6057c69d0212fc6629 (diff)
downloadffmpeg-17b5fc2e51a3bb5a7fc10cbd177d88ef1c025527.tar.gz
avcodec/mpegvideo_enc: Factor setting length of B frame chain out
It already avoids a goto and will be useful in the future to be able to specify each functions tasks and obligations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index b87f03d303..60710eee98 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1472,13 +1472,15 @@ fail:
return best_b_count;
}
-static int select_input_picture(MpegEncContext *s)
+/**
+ * Determines whether an input picture is discarded or not
+ * and if not determines the length of the next chain of B frames
+ * and puts these pictures (including the P frame) into
+ * reordered_input_picture.
+ */
+static int set_bframe_chain_length(MpegEncContext *s)
{
- int i, ret;
-
- for (int i = 1; i <= MAX_B_FRAMES; i++)
- s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];
- s->reordered_input_picture[MAX_B_FRAMES] = NULL;
+ int i;
/* set next picture type & ordering */
if (!s->reordered_input_picture[0] && s->input_picture[0]) {
@@ -1491,7 +1493,7 @@ static int select_input_picture(MpegEncContext *s)
ff_vbv_update(s, 0);
- goto no_output_pic;
+ return 0;
}
}
@@ -1598,7 +1600,22 @@ static int select_input_picture(MpegEncContext *s)
}
}
}
-no_output_pic:
+
+ return 0;
+}
+
+static int select_input_picture(MpegEncContext *s)
+{
+ int ret;
+
+ for (int i = 1; i <= MAX_B_FRAMES; i++)
+ s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];
+ s->reordered_input_picture[MAX_B_FRAMES] = NULL;
+
+ ret = set_bframe_chain_length(s);
+ if (ret < 0)
+ return ret;
+
av_frame_unref(s->new_pic);
if (s->reordered_input_picture[0]) {