[FFmpeg-devel] [PATCH] Fix 2 pass mjpeg encoding

Bobby Bingham uhmmmm
Sat Dec 4 06:41:55 CET 2010


On Sat, 4 Dec 2010 05:16:01 +0100
Michael Niedermayer <michaelni at gmx.at> wrote:

> On Fri, Dec 03, 2010 at 09:33:27PM -0600, Bobby Bingham wrote:
> > Two fixes which together make 2pass mjpeg encoding actually try to
> > match the requested bitrate.
> > 
> > The first patch makes the mjpeg encoder count macroblock data towards
> > i_tex_bits instead of misc_bits.
> > 
> > The second patch makes it so ffmpeg doesn't output the last frame's
> > stats twice when the last frame isn't delayed.
> > -- 
> > Bobby Bingham
> > ??????????????????????
> 
> >  mjpegenc.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 5d6dd07206e4469cdc3e3470b8c9be917e52d5dd  01-itex_stats.patch
> > Count non-header data towards intra block bit count in MJPEG encoder
> > 
> > From: Bobby Bingham <uhmmmm at gmail.com>
> 
> lgtm

Applied

> 
> [...]
> >  ffmpeg.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 05a100018f136d03018bbf451c5e13b8bb7e133f  02-eof_stats.patch
> > Don't output duplicate stats for the last frame
> > 
> > From: Bobby Bingham <uhmmmm at gmail.com>
> > 
> > 
> > ---
> >  ffmpeg.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/ffmpeg.c b/ffmpeg.c
> > index e58e7b5..f5c8d30 100644
> > --- a/ffmpeg.c
> > +++ b/ffmpeg.c
> > @@ -1803,13 +1803,14 @@ static int output_packet(AVInputStream *ist, int ist_index,
> >                              if (ret < 0) {
> >                                  fprintf(stderr, "Video encoding failed\n");
> >                                  ffmpeg_exit(1);
> > -                            }
> > +                            } else if(ret > 0) {
> >                              video_size += ret;
> >                              if(enc->coded_frame && enc->coded_frame->key_frame)
> >                                  pkt.flags |= AV_PKT_FLAG_KEY;
> >                              if (ost->logfile && enc->stats_out) {
> >                                  fprintf(ost->logfile, "%s", enc->stats_out);
> >                              }
> > +                            }
> 
> stats_out should be null if a encoder doesnt mean to output stats
> otherwise it would become impossible to output something at the end
> 

Here's what I'm seeing.  If I do

ffmpeg -i source.png -pass 1 pass1.jpg

the pass1 stats file contains two identical lines. The first is written
by do_video_out when the frame is actually encoded. The second is
written by the code I changed. It calls avcodec_encode_video, which
doesn't actually call into the codec because
avctx->codec->capabilities & CODEC_CAP_DELAY || pict is false.

AFAICS, it never actually calls into the encoder after writing the
stats out the first time.  I don't see where the encoder has a chance
to set this to null before ffmpeg writes the stats out a second time.

> [...]


-- 
Bobby Bingham
??????????????????????



More information about the ffmpeg-devel mailing list