[FFmpeg-cvslog] lavf: Add an option to discard corrupted frames

Zohar Kelrich git at videolan.org
Tue Aug 2 22:24:36 CEST 2011


ffmpeg | branch: master | Zohar Kelrich <lumimies at gmail.com> | Sun Jul 24 17:28:33 2011 +0300| [73e8e8dbf969b9a0bc1591abcfeba474a42e47bc] | committer: Luca Barbato

lavf: Add an option to discard corrupted frames

Signed-off-by: Zohar Kelrich <lumimies at gmail.com>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

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

 libavformat/avformat.h |    1 +
 libavformat/options.c  |    1 +
 libavformat/utils.c    |    9 +++++++++
 3 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index cfdbd11..2f68aba 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -750,6 +750,7 @@ typedef struct AVFormatContext {
 #define AVFMT_FLAG_RTP_HINT     0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
 #endif
 #define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
+#define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
 
 #if FF_API_LOOP_INPUT
     /**
diff --git a/libavformat/options.c b/libavformat/options.c
index c2729b7..9611628 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -79,6 +79,7 @@ static const AVOption options[]={
 #if FF_API_FLAG_RTP_HINT
 {"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"},
 #endif
+{"discardcorrupt", "discard corrupted frames", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
 {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
 {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
 {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c4d7623..b848ebb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -719,6 +719,15 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
                 s->streams[i]->probe_packets = 0;
             continue;
         }
+
+        if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
+            (pkt->flags & AV_PKT_FLAG_CORRUPT)) {
+            av_log(s, AV_LOG_WARNING,
+                   "Dropped corrupted packet (stream = %d)\n",
+                   pkt->stream_index);
+            continue;
+        }
+
         st= s->streams[pkt->stream_index];
 
         switch(st->codec->codec_type){



More information about the ffmpeg-cvslog mailing list