diff mbox series

[FFmpeg-devel,22/33] fftools/ffmpeg_enc: return errors from enc_subtitle() instead of aborting

Message ID 20230713105553.21052-22-anton@khirnov.net
State Accepted
Commit c328bff4daac260336665745d48059903d4bb203
Headers show
Series [FFmpeg-devel,01/33] fftools/ffmpeg_mux_init: return errors from of_open() instead of aborting | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov July 13, 2023, 10:55 a.m. UTC
---
 fftools/ffmpeg.h     |  2 +-
 fftools/ffmpeg_dec.c |  4 +++-
 fftools/ffmpeg_enc.c | 16 ++++++++--------
 3 files changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fdee20d6b2..bcd9cc584e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -804,7 +804,7 @@  int enc_alloc(Encoder **penc, const AVCodec *codec);
 void enc_free(Encoder **penc);
 
 int enc_open(OutputStream *ost, AVFrame *frame);
-void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub);
+int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub);
 void enc_frame(OutputStream *ost, AVFrame *frame);
 void enc_flush(void);
 
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 85bf8dc536..a1d811f512 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -439,7 +439,9 @@  static int process_subtitle(InputStream *ist, AVFrame *frame)
         if (!ost->enc || ost->type != AVMEDIA_TYPE_SUBTITLE)
             continue;
 
-        enc_subtitle(output_files[ost->file_index], ost, subtitle);
+        ret = enc_subtitle(output_files[ost->file_index], ost, subtitle);
+        if (ret < 0)
+            return ret;
     }
 
     return 0;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 4029501313..b35dbb6290 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -462,7 +462,7 @@  static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
     return 1;
 }
 
-void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
+int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
 {
     Encoder *e = ost->enc;
     int subtitle_out_max_size = 1024 * 1024;
@@ -473,13 +473,11 @@  void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
 
     if (sub->pts == AV_NOPTS_VALUE) {
         av_log(ost, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
-        if (exit_on_error)
-            exit_program(1);
-        return;
+        return exit_on_error ? AVERROR(EINVAL) : 0;
     }
     if (ost->finished ||
         (of->start_time != AV_NOPTS_VALUE && sub->pts < of->start_time))
-        return;
+        return 0;
 
     enc = ost->enc_ctx;
 
@@ -501,11 +499,11 @@  void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
         AVSubtitle local_sub = *sub;
 
         if (!check_recording_time(ost, pts, AV_TIME_BASE_Q))
-            return;
+            return 0;
 
         ret = av_new_packet(pkt, subtitle_out_max_size);
         if (ret < 0)
-            report_and_exit(AVERROR(ENOMEM));
+            return AVERROR(ENOMEM);
 
         local_sub.pts = pts;
         // start_display_time is required to be 0
@@ -525,7 +523,7 @@  void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
         subtitle_out_size = avcodec_encode_subtitle(enc, pkt->data, pkt->size, &local_sub);
         if (subtitle_out_size < 0) {
             av_log(ost, AV_LOG_FATAL, "Subtitle encoding failed\n");
-            exit_program(1);
+            return subtitle_out_size;
         }
 
         av_shrink_packet(pkt, subtitle_out_size);
@@ -544,6 +542,8 @@  void enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
 
         of_output_packet(of, ost, pkt);
     }
+
+    return 0;
 }
 
 void enc_stats_write(OutputStream *ost, EncStats *es,