[FFmpeg-devel] [PATCH]: Avoid duplicate last entry in the pass log file for the last frame

Thierry Foucu tfoucu
Wed Nov 3 17:41:12 CET 2010


On Tue, Nov 2, 2010 at 7:47 PM, Michael Niedermayer <michaelni at gmx.at>wrote:

> On Tue, Nov 02, 2010 at 04:43:09PM -0700, Thierry Foucu wrote:
> > On Tue, Nov 2, 2010 at 3:21 PM, Thierry Foucu <tfoucu at gmail.com> wrote:
> >
> > > $subject
> > >
> > > Before the patch, i was getting this in the log file:
> > >
> > > in:131 out:131 type:2 q:1599 itex:0 ptex:9194 mv:878 misc:1710 fcode:1
> > > bcode:1 mc-var:47056 var:132365 icount:0 skipcount:1 hbits:42;
> > > in:132 out:132 type:2 q:1601 itex:436 ptex:9173 mv:931 misc:1706
> fcode:1
> > > bcode:1 mc-var:49302 var:137777 icount:2 skipcount:1 hbits:42;
> > > in:133 out:133 type:2 q:1600 itex:461 ptex:6090 mv:761 misc:1622
> fcode:1
> > > bcode:1 mc-var:48901 var:133431 icount:3 skipcount:2 hbits:42;
> > > in:134 out:134 type:2 q:1565 itex:379 ptex:14567 mv:951 misc:1749
> fcode:1
> > > bcode:1 mc-var:57528 var:134434 icount:2 skipcount:1 hbits:42;
> > > in:135 out:135 type:1 q:1224 itex:96623 ptex:0 mv:0 misc:1007 fcode:1
> > > bcode:1 mc-var:0 var:143173 icount:300 skipcount:0 hbits:42;
> > > in:135 out:135 type:1 q:1224 itex:96623 ptex:0 mv:0 misc:1007 fcode:1
> > > bcode:1 mc-var:0 var:143173 icount:300 skipcount:0 hbits:42;
> > >
> > >
> > > With the patch, I get this:
> > > in:131 out:131 type:2 q:1599 itex:0 ptex:9194 mv:878 misc:1710 fcode:1
> > > bcode:1 mc-var:47056 var:132365 icount:0 skipcount:1 hbits:42;
> > > in:132 out:132 type:2 q:1601 itex:436 ptex:9173 mv:931 misc:1706
> fcode:1
> > > bcode:1 mc-var:49302 var:137777 icount:2 skipcount:1 hbits:42;
> > > in:133 out:133 type:2 q:1600 itex:461 ptex:6090 mv:761 misc:1622
> fcode:1
> > > bcode:1 mc-var:48901 var:133431 icount:3 skipcount:2 hbits:42;
> > > in:134 out:134 type:2 q:1565 itex:379 ptex:14567 mv:951 misc:1749
> fcode:1
> > > bcode:1 mc-var:57528 var:134434 icount:2 skipcount:1 hbits:42;
> > > in:135 out:135 type:1 q:1224 itex:96623 ptex:0 mv:0 misc:1007 fcode:1
> > > bcode:1 mc-var:0 var:143173 icount:300 skipcount:0 hbits:42;
> > >
> > > Note that before the patch the last frame stats are present twice.
> > >
> > > It seems that at the end of encoding, we output the stats_out twice:
> > >
> > > One at line 1254 in function do_video_out
> > > 1252                 /* if two pass, output log */
> > > 1253                 if (ost->logfile && enc->stats_out) {
> > > 1254                     fprintf(ost->logfile, "%s", enc->stats_out);
> > > 1255                 }
> > >
> > > There is a if statement before that to make sure that the return value
> of
> > > avcodec_encode_video is greater than 0
> > >
> > > the second time we output the last frame stat is in output_packet, but
> we
> > > were not checking to see if the return value of avcodec_encode_video is
> > > greater than 0
> > >
> > > The patch does that.
> > >
> > > Index: ffmpeg.c
> > > ===================================================================
> > > --- ffmpeg.c (revision 25651)
> > > +++ ffmpeg.c (working copy)
> > > @@ -1797,7 +1797,7 @@
> > >                              video_size += ret;
> > >                              if(enc->coded_frame &&
> > > enc->coded_frame->key_frame)
> > >                                  pkt.flags |= AV_PKT_FLAG_KEY;
> > > -                            if (ost->logfile && enc->stats_out) {
> > > +                            if (ost->logfile && enc->stats_out && ret
> > 0)
> > > {
> > >                                  fprintf(ost->logfile, "%s",
> > > enc->stats_out);
> > >                              }
> > >                              break;
> > >
> > >
> > >
> > here is another version to fix the problem where i add a if (ret > 0)
> around
> > the code, instead of just checking the return value for the pass log file
> > Index: ffmpeg.c
> > ===================================================================
> > --- ffmpeg.c (revision 25651)
> > +++ ffmpeg.c (working copy)
> > @@ -1794,12 +1794,14 @@
> >                                  fprintf(stderr, "Video encoding
> failed\n");
> >                                  ffmpeg_exit(1);
> >                              }
> > +                            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);
> >                              }
> > +                            }
> >                              break;
> >                          default:
> >                              ret=-1;
> >
> >
> > If this is the patch you will prefer, i will email another patch
> > for indentation (if needed)
>
> this change is incorrect, the encoder is buggy
>
>
Hi Michael,

do you mind to tell me why this change is incorrect? I was looking at
ffmpeg.c and in the function do_video_out, after calling the function
avcodec_encode_video, we do check for (ret > 0) before logging the
enc->stats_out to the logfile.

I was just trying to do the same thing here

Also, if you want to try to reproduce the problem i have, it is really
simple.
Use the tests/data/lavf/lavf.avi as input

Then run the basic command line to encode a FLV file:
./ffmpeg -i tests/data/lavf/lavf.avi -bf 0 -g 7 -an -pass 1 -passlogfile
/tmp/ffmpeg_log -f flv -y /tmp/test.flv
FFmpeg version SVN-r25651, Copyright (c) 2000-2010 the FFmpeg developers
  built on Nov  2 2010 15:13:54 with gcc 4.4.3
  configuration:
  libavutil     50.32. 5 / 50.32. 5
  libavcore      0. 9. 1 /  0. 9. 1
  libavcodec    52.94. 0 / 52.94. 0
  libavformat   52.84. 0 / 52.84. 0
  libavdevice   52. 2. 2 / 52. 2. 2
  libavfilter    1.53. 0 /  1.53. 0
  libswscale     0.12. 0 /  0.12. 0
Input #0, avi, from 'tests/data/lavf/lavf.avi':
  Duration: 00:00:01.04, start: 0.000000, bitrate: 2534 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 352x288 [PAR 1:1 DAR 11:9], 25 tbr,
25 tbn, 25 tbc
    Stream #0.1: Audio: mp2, 44100 Hz, 1 channels, s16, 64 kb/s
[buffer @ 0x2adc3b0] w:352 h:288 pixfmt:yuv420p
Output #0, flv, to '/tmp/test.flv':
  Metadata:
    encoder         : Lavf52.84.0
    Stream #0.0: Video: flv, yuv420p, 352x288 [PAR 1:1 DAR 11:9], q=2-31,
pass 1, 200 kb/s, 1k tbn, 25 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=   25 fps=  0 q=31.0 Lsize=     266kB time=1.00 bitrate=2176.0kbits/s

video:265kB audio:0kB global headers:0kB muxing overhead 0.224773%


Now, if you look at the passlog file, you will get the last frame (Frame
number 24) duplicated
in:24 out:24 type:2 q:3658 itex:2643 ptex:8169 mv:2169 misc:2513 fcode:1
bcode:1 mc-var:191951 var:714434 icount:13 skipcount:51 hbits:42;
in:24 out:24 type:2 q:3658 itex:2643 ptex:8169 mv:2169 misc:2513 fcode:1
bcode:1 mc-var:191951 var:714434 icount:13 skipcount:51 hbits:42;

With my patch, i just get it once.

The problem happens also if i choose mpeg4 video codec:
example:
/ffmpeg -i tests/data/lavf/lavf.avi -bf 0 -g 7 -an -pass 1 -passlogfile
/tmp/ffmpeg_log -y /tmp/test.mp4

output:
in:24 out:24 type:2 q:3658 itex:2530 ptex:8416 mv:2201 misc:2550 fcode:1
bcode:1 mc-var:200917 var:714434 icount:11 skipcount:49 hbits:55;
in:24 out:24 type:2 q:3658 itex:2530 ptex:8416 mv:2201 misc:2550 fcode:1
bcode:1 mc-var:200917 var:714434 icount:11 skipcount:49 hbits:55;


Now, I though that if the function avcodec_encode_video returns 0, it means
no video frame got encoded. Am I wrong on this assumption?

Thanks for your time.



> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Republics decline into democracies and democracies degenerate into
> despotisms. -- Aristotle
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAkzQzSgACgkQYR7HhwQLD6uZywCfaV4H/NIap7p7voJQ6sMNNb7a
> 9DkAoIVZFv1/QQgpaggGd9ruNMcKIqF9
> =u+XP
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>



More information about the ffmpeg-devel mailing list