[FFmpeg-devel] [PATCH] lavc/libvpxenc: prevent fifo from filling up

James Zern jzern at google.com
Wed Jul 5 22:16:37 EEST 2023


On Wed, Jul 5, 2023 at 12:15 PM James Zern <jzern at google.com> wrote:
>
> Hi,
>

+ffmpeg-dev. I took the wrong email off the reply.

> On Mon, Jul 3, 2023 at 10:08 PM David Lemler <david at lemler.family> wrote:
> >
> > Prevent the fifo used in encoding VPx videos from filling up and stopping
> > encode when it reaches 21845 items, which happens when the video has more
> > than
> > that number of frames.
> >
>
> What failure do you see, a memory allocation error? 21845 sounds
> somewhat arbitrary, maybe specific to your machine, so I'd leave it
> off the comment and commit message.
>
> > This problem occurs when performing the first pass of a 2-pass encode, as
> > otherwise, the fifo is properly drained, preventing it from overflowing.
> >
> > Problem is fixed by manually draining the fifo when performing the first
> > pass
> > of a 2-pass encode.
> >
> > Fixes the regression originally introduced in
> > 5bda4ec6c3cb6f286bb40dee4457c3c26e0f78cb
> >
>
> Anton, any comments here?
>
> > Signed-off-by: David Lemler <david at lemler.family>
> > ---
> >  libavcodec/libvpxenc.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 8833df2d68..e4ab13e6ab 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -1452,6 +1452,12 @@ static int queue_frames(AVCodecContext *avctx, struct
> > vpx_codec_ctx *encoder,
> >              memcpy((uint8_t*)stats->buf + stats->sz,
> >                     pkt->data.twopass_stats.buf,
> > pkt->data.twopass_stats.sz);
> >              stats->sz += pkt->data.twopass_stats.sz;
> > +            /* Drain the fifo if it has any items in it to prevent it from
> > +               filling up when performing the first pass of a 2-pass encode
> > if
> > +               the video has more than 21845 frames. */
> > +            if (av_fifo_can_read(ctx->fifo) > 0) {
>
> Another option would be to avoid calling frame_data_submit() in the first pass.
>
> > +                av_fifo_drain2(ctx->fifo, 1);
> > +            }
> >              break;
> >          }
> >          case VPX_CODEC_PSNR_PKT:
> > --
> > 2.41.0.windows.1
> >


More information about the ffmpeg-devel mailing list