diff mbox series

[FFmpeg-devel,08/28] ffmpeg: add a helper function to access output file size

Message ID 20220111095830.31542-8-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/28] ffmpeg: pass the muxer context explicitly to some functions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Anton Khirnov Jan. 11, 2022, 9:58 a.m. UTC
Stop accessing muxer internals from outside of ffmpeg_mux.
---
 fftools/ffmpeg.c     | 10 +---------
 fftools/ffmpeg.h     |  1 +
 fftools/ffmpeg_mux.c | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9360c8a475..1b5cf4d9af 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1514,8 +1514,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 = of_filesize(output_files[0]);
     AVCodecContext *enc;
     int frame_number, vid, i;
     double bitrate;
@@ -1544,13 +1543,6 @@  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);
-
     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 279a99cc48..dfcaa875d9 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -695,5 +695,6 @@  void of_close(OutputFile **pof);
 
 void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
                      int unqueue);
+int64_t of_filesize(OutputFile *of);
 
 #endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 538f153484..7c8414ac93 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -347,3 +347,17 @@  int of_muxer_init(OutputFile *of)
 
     return 0;
 }
+
+int64_t of_filesize(OutputFile *of)
+{
+    AVIOContext *pb = of->ctx->pb;
+    int64_t ret = -1;
+
+    if (pb) {
+        ret = avio_size(pb);
+        if (ret <= 0) // FIXME improve avio_size() so it works with non seekable output too
+            ret = avio_tell(pb);
+    }
+
+    return ret;
+}