summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_mux.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-12-13 15:13:37 +0100
committerAnton Khirnov <anton@khirnov.net>2022-07-23 11:53:19 +0200
commitcc1cc2c65e7b776433791adea932e0ea9b1cfd42 (patch)
tree88bb736a3f220de6980442a09fdcef057aafe2bc /fftools/ffmpeg_mux.c
parentcc4964607724980aae242777af9b35567b2fc627 (diff)
fftools/ffmpeg: move closing the file into of_write_trailer()
The current code postpones closing the files until after printing the final report, which accesses the output file size. Deal with this by storing the final file size before closing the file.
Diffstat (limited to 'fftools/ffmpeg_mux.c')
-rw-r--r--fftools/ffmpeg_mux.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 396e91184b..78395bebb4 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -35,6 +35,7 @@
struct Muxer {
/* filesize limit expressed in bytes */
int64_t limit_filesize;
+ int64_t final_filesize;
int header_written;
};
@@ -304,6 +305,17 @@ int of_write_trailer(OutputFile *of)
return ret;
}
+ of->mux->final_filesize = of_filesize(of);
+
+ if (!(of->format->flags & AVFMT_NOFILE)) {
+ ret = avio_closep(&of->ctx->pb);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error closing file %s: %s\n",
+ of->ctx->url, av_err2str(ret));
+ return ret;
+ }
+ }
+
return 0;
}
@@ -360,7 +372,9 @@ int64_t of_filesize(OutputFile *of)
AVIOContext *pb = of->ctx->pb;
int64_t ret = -1;
- if (pb) {
+ if (of->mux->final_filesize)
+ ret = of->mux->final_filesize;
+ else 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);