diff mbox series

[FFmpeg-devel,6/9] fftools/ffmpeg: stop using AVStream.nb_frames in do_video_stats()

Message ID 20220511081654.15127-6-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/9] fftools/ffmpeg: share the code encoding a single frame between video and audio | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 11, 2022, 8:16 a.m. UTC
Its use for muxing is not documented, in practice it is incremented per
each packet successfully passed to the muxer's write_packet(). Since
there is a lot of indirection between ffmpeg receiving a packet from the
encoder and it actually being written (e.g. bitstream filters, the
interleaving queue), using nb_frames here is incorrect.

Add a new counter for packets received from encoder instead.
---
 fftools/ffmpeg.c | 4 +++-
 fftools/ffmpeg.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ae3cc57bef..c15d1486dd 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -851,7 +851,7 @@  static void do_video_stats(OutputStream *ost, int frame_size)
     }
 
     enc = ost->enc_ctx;
-    frame_number = ost->st->nb_frames;
+    frame_number = ost->packets_encoded;
     if (vstats_version <= 1) {
         fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
                 ost->quality / (float)FF_QP2LAMBDA);
@@ -945,6 +945,8 @@  static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
         if (enc->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename)
             do_video_stats(ost, pkt->size);
 
+        ost->packets_encoded++;
+
         output_packet(of, pkt, ost, 0);
 
         /* if two pass, output log */
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9f0c093e34..7326193caf 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -551,6 +551,8 @@  typedef struct OutputStream {
     // number of frames/samples sent to the encoder
     uint64_t frames_encoded;
     uint64_t samples_encoded;
+    // number of packets received from the encoder
+    uint64_t packets_encoded;
 
     /* packet quality factor */
     int quality;