Skip to content

Commit

Permalink
baresip: add avcodec: constrain bitrate patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Dec 23, 2022
1 parent 662571a commit 7084c46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ external:
cd external/baresip && \
patch -p1 < ../../patches/baresip_packet_dup_handler.patch && \
patch -p1 < ../../patches/baresip_stream_enable.patch && \
patch -p1 < ../../patches/baresip_video_remove_sendq_empty.patch
patch -p1 < ../../patches/baresip_video_remove_sendq_empty.patch && \
patch -p1 < ../../patches/2365.patch

.PHONY: cloc
cloc:
Expand Down
29 changes: 29 additions & 0 deletions patches/2365.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 8897f63134635868ae0d4cd21f06a58880bc1f9c Mon Sep 17 00:00:00 2001
From: Sebastian Reimers <[email protected]>
Date: Fri, 23 Dec 2022 10:59:04 +0100
Subject: [PATCH] avcodec: constrain bitrate

With rc_buffer_size and rc_max_rate the encoder can better calculate
a constant average bitrate and this avoids large bitrate spikes.

See: https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
---
modules/avcodec/encode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/avcodec/encode.c b/modules/avcodec/encode.c
index 8ce4eb8b5..b45cd0947 100644
--- a/modules/avcodec/encode.c
+++ b/modules/avcodec/encode.c
@@ -164,7 +164,10 @@ static int open_encoder(struct videnc_state *st,

av_opt_set_defaults(st->ctx);

- st->ctx->bit_rate = prm->bitrate;
+ st->ctx->bit_rate = prm->bitrate;
+ st->ctx->rc_max_rate = prm->bitrate;
+ st->ctx->rc_buffer_size = prm->bitrate / 2;
+
st->ctx->width = size->w;
st->ctx->height = size->h;

0 comments on commit 7084c46

Please sign in to comment.