[FFmpeg-devel] [PATCHv2 4/5] ffmpeg: exit on corrupt packets or decoded frames if exit_on_error flag is present

Marton Balint cus at passwd.hu
Mon Oct 19 01:57:31 CEST 2015


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 ffmpeg.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index fc29ad5..37a819e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1925,13 +1925,20 @@ int guess_input_channel_layout(InputStream *ist)
     return 1;
 }
 
-static void check_decode_result(int *got_output, int ret)
+static void check_decode_result(InputStream *ist, int *got_output, int ret)
 {
     if (*got_output || ret<0)
         decode_error_stat[ret<0] ++;
 
     if (ret < 0 && exit_on_error)
         exit_program(1);
+
+    if (exit_on_error && *got_output && ist) {
+        if (av_frame_get_decode_error_flags(ist->decoded_frame) || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
+            av_log(NULL, AV_LOG_FATAL, "%s: corrupt decoded frame in stream %d\n", input_files[ist->file_index]->ctx->filename, ist->st->index);
+            exit_program(1);
+        }
+    }
 }
 
 static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
@@ -1956,7 +1963,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
         ret = AVERROR_INVALIDDATA;
     }
 
-    check_decode_result(got_output, ret);
+    check_decode_result(ist, got_output, ret);
 
     if (!*got_output || ret < 0)
         return ret;
@@ -2093,7 +2100,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
                    ist->st->codec->has_b_frames);
     }
 
-    check_decode_result(got_output, ret);
+    check_decode_result(ist, got_output, ret);
 
     if (*got_output && ret >= 0) {
         if (ist->dec_ctx->width  != decoded_frame->width ||
@@ -2201,7 +2208,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
     int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
                                           &subtitle, got_output, pkt);
 
-    check_decode_result(got_output, ret);
+    check_decode_result(NULL, got_output, ret);
 
     if (ret < 0 || !*got_output) {
         if (!pkt->size)
@@ -3770,6 +3777,11 @@ static int process_input(int file_index)
     if (ist->discard)
         goto discard_packet;
 
+    if (exit_on_error && (pkt.flags & AV_PKT_FLAG_CORRUPT)) {
+        av_log(NULL, AV_LOG_FATAL, "%s: corrupt input packet in stream %d\n", is->filename, pkt.stream_index);
+        exit_program(1);
+    }
+
     if (debug_ts) {
         av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s "
                "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
-- 
2.1.4



More information about the ffmpeg-devel mailing list