summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-12-11 14:44:38 +0100
committerAnton Khirnov <anton@khirnov.net>2022-07-23 11:53:19 +0200
commit9fe62a545f02c63ebae3a2fe26e4018e4be1e655 (patch)
treebcc55b05d9d97cdda2636eb6fe9734281bf82355
parent6a23be92d2a0b1f5100afa0fd3ff33e8510b6eb3 (diff)
fftools/ffmpeg: add a helper function to access output file size
Stop accessing muxer internals from outside of ffmpeg_mux.
-rw-r--r--fftools/ffmpeg.c10
-rw-r--r--fftools/ffmpeg.h1
-rw-r--r--fftools/ffmpeg_mux.c14
3 files changed, 16 insertions, 9 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ed3075f6e6..d9b512ce59 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1516,8 +1516,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 vid, i;
double bitrate;
@@ -1546,13 +1545,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 2798fc830c..cab21e8170 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -705,5 +705,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 e47a55c4e9..83558f7f7d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -333,3 +333,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;
+}