[FFmpeg-devel] [PATCH 02/24] ffmpeg: simplify getting output file size

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


Stop calling avio_size()/avio_tell(), which are potentially heavy
operations and may interfere with muxer operation. Use the recently
introduced bytes_written field instead.
---
 fftools/ffmpeg.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index bdeff9a12e..b77531cb7f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1677,8 +1677,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
 {
     AVBPrint buf, buf_script;
     OutputStream *ost;
-    AVFormatContext *oc;
-    int64_t total_size;
+    int64_t total_size = -1;
     AVCodecContext *enc;
     int frame_number, vid, i;
     double bitrate;
@@ -1708,11 +1707,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
     t = (cur_time-timer_start) / 1000000.0;
 
 
-    oc = output_files[0]->ctx;
-
-    total_size = avio_size(oc->pb);
-    if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too
-        total_size = avio_tell(oc->pb);
+    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);
-- 
2.33.0



More information about the ffmpeg-devel mailing list