fftools/ffmpeg: move writing the trailer to ffmpeg_mux.c

This commit is contained in:
Anton Khirnov 2021-11-10 15:21:47 +01:00
parent 288aa37387
commit 5bc644ea8a
3 changed files with 25 additions and 13 deletions

View File

@ -4450,19 +4450,9 @@ static int transcode(void)
/* write the trailer if needed */ /* write the trailer if needed */
for (i = 0; i < nb_output_files; i++) { for (i = 0; i < nb_output_files; i++) {
os = output_files[i]->ctx; ret = of_write_trailer(output_files[i]);
if (!output_files[i]->header_written) { if (ret < 0 && exit_on_error)
av_log(NULL, AV_LOG_ERROR, exit_program(1);
"Nothing was written into output file %d (%s), because "
"at least one of its streams received no packets.\n",
i, os->url);
continue;
}
if ((ret = av_write_trailer(os)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", os->url, av_err2str(ret));
if (exit_on_error)
exit_program(1);
}
} }
/* dump report by using the first video and audio streams */ /* dump report by using the first video and audio streams */

View File

@ -689,6 +689,7 @@ int hwaccel_decode_init(AVCodecContext *avctx);
/* open the muxer when all the streams are initialized */ /* open the muxer when all the streams are initialized */
int of_check_init(OutputFile *of); int of_check_init(OutputFile *of);
int of_write_trailer(OutputFile *of);
void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
int unqueue); int unqueue);

View File

@ -290,3 +290,24 @@ int of_check_init(OutputFile *of)
return 0; return 0;
} }
int of_write_trailer(OutputFile *of)
{
int ret;
if (!of->header_written) {
av_log(NULL, AV_LOG_ERROR,
"Nothing was written into output file %d (%s), because "
"at least one of its streams received no packets.\n",
of->index, of->ctx->url);
return AVERROR(EINVAL);
}
ret = av_write_trailer(of->ctx);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", of->ctx->url, av_err2str(ret));
return ret;
}
return 0;
}