summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-04-01 10:03:46 +0200
committerAnton Khirnov <anton@khirnov.net>2022-07-23 11:53:19 +0200
commit52bc8a842e037214e1644f61962982c73a175eca (patch)
tree567f5458a8f7327f0b3fb9829fad63b2e1a21b76 /fftools/ffmpeg.c
parentff593c6c882791451199e3accd80304bcb8f0413 (diff)
fftools/ffmpeg_mux: return errors from of_submit_packet()
Do not call exit_program(), as that would conflict with moving this code into a separate thread.
Diffstat (limited to 'fftools/ffmpeg.c')
-rw-r--r--fftools/ffmpeg.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cee5b1cbcf..90e14aba25 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -713,6 +713,7 @@ static void close_output_stream(OutputStream *ost)
static void output_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost, int eof)
{
+ const char *err_msg;
int ret = 0;
if (!eof && pkt->dts != AV_NOPTS_VALUE)
@@ -720,28 +721,49 @@ static void output_packet(OutputFile *of, AVPacket *pkt,
/* apply the output bitstream filters */
if (ost->bsf_ctx) {
+ int bsf_eof = 0;
+
ret = av_bsf_send_packet(ost->bsf_ctx, eof ? NULL : pkt);
+ if (ret < 0) {
+ err_msg = "submitting a packet for bitstream filtering";
+ goto fail;
+ }
+
+ while (!bsf_eof) {
+ ret = av_bsf_receive_packet(ost->bsf_ctx, pkt);
+ if (ret == AVERROR(EAGAIN))
+ return;
+ else if (ret == AVERROR_EOF)
+ bsf_eof = 1;
+ else if (ret < 0) {
+ err_msg = "applying bitstream filters to a packet";
+ goto fail;
+ }
+
+ ret = of_submit_packet(of, bsf_eof ? NULL : pkt, ost);
+ if (ret < 0)
+ goto mux_fail;
+ }
+ } else {
+ ret = of_submit_packet(of, eof ? NULL : pkt, ost);
if (ret < 0)
- goto finish;
- while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0)
- of_submit_packet(of, pkt, ost);
- if (ret == AVERROR_EOF)
- of_submit_packet(of, NULL, ost);
- if (ret == AVERROR(EAGAIN))
- ret = 0;
- } else
- of_submit_packet(of, eof ? NULL : pkt, ost);
+ goto mux_fail;
+ }
if (eof)
ost->finished |= MUXER_FINISHED;
-finish:
- if (ret < 0 && ret != AVERROR_EOF) {
- av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "
- "packet for stream #%d:%d.\n", ost->file_index, ost->index);
- if(exit_on_error)
- exit_program(1);
- }
+ return;
+
+mux_fail:
+ err_msg = "submitting a packet to the muxer";
+
+fail:
+ av_log(NULL, AV_LOG_ERROR, "Error %s for output stream #%d:%d.\n",
+ err_msg, ost->file_index, ost->index);
+ if (exit_on_error)
+ exit_program(1);
+
}
static int check_recording_time(OutputStream *ost)