[FFmpeg-devel] [PATCH 1/1] [PATCH] don't duplicate the last frame twice in passlog

Thierry Foucu tfoucu at gmail.com
Wed Nov 28 22:23:47 CET 2012


Some codec will duplicate the last frame because stats_out is not updated,
and the last "frame" will had got_packet=0 to signal EOF

And update video stats log during encode flush.
---
 ffmpeg.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 55b5f86..ed6696e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -920,6 +920,7 @@ static void do_video_out(AVFormatContext *s,
             /* if two pass, output log */
             if (ost->logfile && enc->stats_out) {
                 fprintf(ost->logfile, "%s", enc->stats_out);
+                enc->stats_out[0] = '\0';
             }
         }
     }
@@ -1292,6 +1293,7 @@ static void flush_encoders(void)
                 *size += pkt.size;
                 if (ost->logfile && enc->stats_out) {
                     fprintf(ost->logfile, "%s", enc->stats_out);
+                    enc->stats_out[0] = '\0';
                 }
                 if (!got_packet) {
                     stop_encoding = 1;
@@ -1304,6 +1306,11 @@ static void flush_encoders(void)
                 if (pkt.duration > 0)
                     pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
                 write_frame(os, &pkt, ost);
+                ost->frame_number ++;
+                ost->sync_opts ++;
+                if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) {
+                  do_video_stats(os, ost, pkt.size);
+                }
             }
 
             if (stop_encoding)
-- 
1.7.7.3



More information about the ffmpeg-devel mailing list