[FFmpeg-devel] [PATCH 13/24] ffmpeg: add a helper function to access output file size

Anton Khirnov anton at khirnov.net
Mon Dec 13 17:20:31 EET 2021


Stop accessing muxer internals from outside of ffmpeg_mux.
---
 fftools/ffmpeg.c     | 6 +-----
 fftools/ffmpeg.h     | 1 +
 fftools/ffmpeg_mux.c | 6 ++++++
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c01ff2fa92..b7f26fe288 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1512,7 +1512,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
 {
     AVBPrint buf, buf_script;
     OutputStream *ost;
-    int64_t total_size = -1;
+    int64_t total_size = of_bytes_written(output_files[0]);
     AVCodecContext *enc;
     int frame_number, vid, i;
     double bitrate;
@@ -1541,10 +1541,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
 
     t = (cur_time-timer_start) / 1000000.0;
 
-
-    if (output_files[0]->ctx->pb)
-        total_size = output_files[0]->ctx->pb->bytes_written;
-
     vid = 0;
     av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
     av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 4aed24c2a7..c1990561af 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -694,5 +694,6 @@ void of_close(OutputFile **pof);
 void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
                      int unqueue);
 int of_finished(OutputFile *of);
+int64_t of_bytes_written(OutputFile *of);
 
 #endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index dcba02b8a3..3ae20fdeeb 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -371,3 +371,9 @@ int of_finished(OutputFile *of)
         return 1;
     return 0;
 }
+
+int64_t of_bytes_written(OutputFile *of)
+{
+    AVIOContext *pb = of->ctx->pb;
+    return pb ? pb->bytes_written : -1;
+}
-- 
2.33.0



More information about the ffmpeg-devel mailing list