[FFmpeg-devel] [PATCH 1/1] RFC discard all frames when looking for codec parameters

Joakim Plate elupus at ecce.se
Sun Dec 15 17:02:53 CET 2013


Note - fate breaks on many test after this change, so can't be done exactly
as this.

On low end systems where playback is normally handled by hardware decode
decoding large h264 frames in find_stream_info can take very long
time.

This changes so that we request the frames to be skipped, but still
run the parsing code.
---
 libavformat/utils.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 838ee18..d486c69 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2463,6 +2463,9 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, A
     AVFrame *frame = av_frame_alloc();
     AVSubtitle subtitle;
     AVPacket pkt = *avpkt;
+    enum AVDiscard skip_frame       = st->codec->skip_frame
+                 , skip_idct        = st->codec->skip_idct
+                 , skip_loop_filter = st->codec->skip_loop_filter;
 
     if (!frame)
         return AVERROR(ENOMEM);
@@ -2497,6 +2500,10 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, A
         goto fail;
     }
 
+    st->codec->skip_frame       = AVDISCARD_ALL;
+    st->codec->skip_idct        = AVDISCARD_ALL;
+    st->codec->skip_loop_filter = AVDISCARD_ALL;
+
     while ((pkt.size > 0 || (!pkt.data && got_picture)) &&
            ret >= 0 &&
            (!has_codec_parameters(st, NULL)   ||
@@ -2533,6 +2540,9 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, A
         ret = -1;
 
 fail:
+    st->codec->skip_frame       = skip_frame;
+    st->codec->skip_idct        = skip_idct;
+    st->codec->skip_loop_filter = skip_loop_filter;
     avcodec_free_frame(&frame);
     return ret;
 }
-- 
1.8.2



More information about the ffmpeg-devel mailing list