[FFmpeg-devel] [PATCH 3/3] WIP: lavf/utils: try to avoid decoding a frame to get the codec parameters

wm4 nfxjfg at googlemail.com
Wed Oct 28 18:48:31 CET 2015


On Wed, 28 Oct 2015 13:30:59 -0400
"Ronald S. Bultje" <rsbultje at gmail.com> wrote:

> Hi,
> 
> On Sat, Oct 17, 2015 at 4:34 PM, Matthieu Bouron <matthieu.bouron at gmail.com>
> wrote:
> 
> > From: Matthieu Bouron <matthieu.bouron at stupeflix.com>
> >
> > Avoid decoding twice images such as jpeg and png, once in the
> > avformat_find_stream_info and once when the actual decode is made.
> >
> > The decoder must honor the skip_frame option in order to skip
> > decoding. For now the AVDISCARD_ALL flag is only set for the mjpeg and
> > png decoders.
> > ---
> >  libavformat/utils.c | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> >
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index 689473e..67dfffc 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -2676,11 +2676,16 @@ static int has_codec_parameters(AVStream *st,
> > const char **errmsg_ptr)
> >  static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket
> > *avpkt,
> >                              AVDictionary **options)
> >  {
> > +    int i;
> >      const AVCodec *codec;
> >      int got_picture = 1, ret = 0;
> >      AVFrame *frame = av_frame_alloc();
> >      AVSubtitle subtitle;
> >      AVPacket pkt = *avpkt;
> > +    int skip_frame;
> > +    static const enum AVCodecID no_decode_codecs[] = {
> > +        AV_CODEC_ID_MJPEG, AV_CODEC_ID_PNG,
> > +    };
> >
> >      if (!frame)
> >          return AVERROR(ENOMEM);
> > @@ -2719,6 +2724,14 @@ static int try_decode_frame(AVFormatContext *s,
> > AVStream *st, AVPacket *avpkt,
> >          goto fail;
> >      }
> >
> > +    skip_frame = st->codec->skip_frame;
> > +    for (i = 0; i < FF_ARRAY_ELEMS(no_decode_codecs); i++) {
> > +        if (st->codec->codec_id == no_decode_codecs[i]) {
> > +            st->codec->skip_frame = AVDISCARD_ALL;
> > +            break;
> > +        }
> > +    }  
> 
> 
> I tend to find this kind of specific code in general interfaces fairly
> questionable. Why is this necessary?

The intention of this patch is to make these image codecs discard the
frame data (and not to decompress in the first frame), but still have
them set the parameters of the discarded frame.

It's a very ugly hack to make libavformat set the pixfmt field in the
AVStream codec contexts, without decoding image data. (Which would be
huge and take long.)


More information about the ffmpeg-devel mailing list