@@ -4348,7 +4348,6 @@ static int transcode_step(void)
static int transcode(void)
{
int ret, i;
- AVFormatContext *os;
OutputStream *ost;
InputStream *ist;
int64_t timer_start;
@@ -4417,18 +4416,6 @@ static int transcode(void)
/* dump report by using the first video and audio streams */
print_report(1, timer_start, av_gettime_relative());
- /* close the output files */
- for (i = 0; i < nb_output_files; i++) {
- os = output_files[i]->ctx;
- if (os && os->oformat && !(os->oformat->flags & AVFMT_NOFILE)) {
- if ((ret = avio_closep(&os->pb)) < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error closing file %s: %s\n", os->url, av_err2str(ret));
- if (exit_on_error)
- exit_program(1);
- }
- }
- }
-
/* close each encoder */
for (i = 0; i < nb_output_streams; i++) {
ost = output_streams[i];
@@ -35,6 +35,7 @@
struct Muxer {
/* filesize limit expressed in bytes */
uint64_t limit_filesize;
+ uint64_t final_filesize;
int header_written;
};
@@ -318,6 +319,17 @@ int of_write_trailer(OutputFile *of)
return ret;
}
+ if (!(of->format->flags & AVFMT_NOFILE)) {
+ of->mux->final_filesize = of->ctx->pb->bytes_written;
+
+ 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;
}
@@ -375,5 +387,6 @@ int of_finished(OutputFile *of)
int64_t of_bytes_written(OutputFile *of)
{
AVIOContext *pb = of->ctx->pb;
- return pb ? pb->bytes_written : -1;
+ return of->mux->final_filesize ? of->mux->final_filesize :
+ pb ? pb->bytes_written : -1;
}