[FFmpeg-cvslog] fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting

Anton Khirnov git at videolan.org
Thu Jul 20 21:56:44 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Jul 13 13:34:32 2023 +0200| [e0f4259689357182e8d555d093e8843f7bf19e5f] | committer: Anton Khirnov

fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e0f4259689357182e8d555d093e8843f7bf19e5f
---

 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 506deaa0f3..36e8867fd5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -830,7 +830,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 0edbe19136..d842bc7df4 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -559,7 +559,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;
@@ -752,8 +754,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;
@@ -790,7 +792,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;
 



More information about the ffmpeg-cvslog mailing list