mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-02-18 21:07:01 +00:00
lavf/utils: avoid decoding a frame to get the codec parameters
Avoid decoding a frame to get the codec parameters while the codec supports FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM. This is particulary useful to avoid decoding twice images (once in avformat_find_stream_info and once when the actual decode is made).
This commit is contained in:
parent
f5b7a29ae8
commit
72eaf72623
@ -2695,6 +2695,8 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
|
|||||||
AVFrame *frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
AVSubtitle subtitle;
|
AVSubtitle subtitle;
|
||||||
AVPacket pkt = *avpkt;
|
AVPacket pkt = *avpkt;
|
||||||
|
int do_skip_frame = 0;
|
||||||
|
enum AVDiscard skip_frame;
|
||||||
|
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -2733,6 +2735,12 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (st->codec->codec->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM) {
|
||||||
|
do_skip_frame = 1;
|
||||||
|
skip_frame = st->codec->skip_frame;
|
||||||
|
st->codec->skip_frame = AVDISCARD_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
while ((pkt.size > 0 || (!pkt.data && got_picture)) &&
|
while ((pkt.size > 0 || (!pkt.data && got_picture)) &&
|
||||||
ret >= 0 &&
|
ret >= 0 &&
|
||||||
(!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) ||
|
(!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) ||
|
||||||
@ -2768,6 +2776,10 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
if (do_skip_frame) {
|
||||||
|
st->codec->skip_frame = skip_frame;
|
||||||
|
}
|
||||||
|
|
||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user