[FFmpeg-devel] [PATCH 13/47] fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting
Anton Khirnov
anton at khirnov.net
Sat Jul 15 13:45:37 EEST 2023
---
fftools/ffmpeg.c | 4 +++-
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_enc.c | 12 ++++++++----
fftools/ffmpeg_mux.c | 20 +++++++++-----------
4 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 926fdea23a..ddb011741a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1120,7 +1120,9 @@ static int process_input(int file_index)
OutputStream *ost = ist->outputs[oidx];
OutputFile *of = output_files[ost->file_index];
close_output_stream(ost);
- of_output_packet(of, ost, NULL);
+ ret = of_output_packet(of, ost, NULL);
+ if (ret < 0)
+ return ret;
}
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7329df6607..62b56a8cd8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -831,7 +831,7 @@ void of_close(OutputFile **pof);
void of_enc_stats_close(void);
-void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
+int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
/**
* @param dts predicted packet dts in AV_TIME_BASE_Q
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 9ca3940b93..01e1b0656c 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -563,7 +563,9 @@ int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
}
pkt->dts = pkt->pts;
- of_output_packet(of, ost, pkt);
+ ret = of_output_packet(of, ost, pkt);
+ if (ret < 0)
+ return ret;
}
return 0;
@@ -756,8 +758,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_assert0(frame); // should never happen during flushing
return 0;
} else if (ret == AVERROR_EOF) {
- of_output_packet(of, ost, NULL);
- return ret;
+ ret = of_output_packet(of, ost, NULL);
+ return ret < 0 ? ret : AVERROR_EOF;
} else if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc);
return ret;
@@ -794,7 +796,9 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
e->packets_encoded++;
- of_output_packet(of, ost, pkt);
+ ret = of_output_packet(of, ost, pkt);
+ if (ret < 0)
+ return ret;
}
av_assert0(0);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index a6cc824496..24cdf00469 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -330,7 +330,7 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost)
return 0;
}
-void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
+int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
{
Muxer *mux = mux_from_of(of);
MuxStream *ms = ms_from_ost(ost);
@@ -359,7 +359,7 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
while (!bsf_eof) {
ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
if (ret == AVERROR(EAGAIN))
- return;
+ return 0;
else if (ret == AVERROR_EOF)
bsf_eof = 1;
else if (ret < 0) {
@@ -377,16 +377,14 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
goto mux_fail;
}
- return;
+ return 0;
mux_fail:
err_msg = "submitting a packet to the muxer";
fail:
av_log(ost, AV_LOG_ERROR, "Error %s\n", err_msg);
- if (exit_on_error)
- exit_program(1);
-
+ return exit_on_error ? ret : 0;
}
int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
@@ -405,10 +403,8 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
pkt = NULL;
// EOF: flush output bitstream filters.
- if (!pkt) {
- of_output_packet(of, ost, NULL);
- return 0;
- }
+ if (!pkt)
+ return of_output_packet(of, ost, NULL);
if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) &&
!ms->copy_initial_nonkeyframes)
@@ -461,7 +457,9 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
}
}
- of_output_packet(of, ost, opkt);
+ ret = of_output_packet(of, ost, opkt);
+ if (ret < 0)
+ return ret;
ms->streamcopy_started = 1;
--
2.40.1
More information about the ffmpeg-devel
mailing list