mirror of https://git.ffmpeg.org/ffmpeg.git
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
Originally committed as revision 4400 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
3d15acf27b
commit
43c0040a65
|
@ -1675,15 +1675,17 @@ static int try_decode_frame(AVStream *st, const uint8_t *data, int size)
|
||||||
{
|
{
|
||||||
int16_t *samples;
|
int16_t *samples;
|
||||||
AVCodec *codec;
|
AVCodec *codec;
|
||||||
int got_picture, ret;
|
int got_picture, ret=0;
|
||||||
AVFrame picture;
|
AVFrame picture;
|
||||||
|
|
||||||
|
if(!st->codec.codec){
|
||||||
codec = avcodec_find_decoder(st->codec.codec_id);
|
codec = avcodec_find_decoder(st->codec.codec_id);
|
||||||
if (!codec)
|
if (!codec)
|
||||||
return -1;
|
return -1;
|
||||||
ret = avcodec_open(&st->codec, codec);
|
ret = avcodec_open(&st->codec, codec);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if(!has_codec_parameters(&st->codec)){
|
if(!has_codec_parameters(&st->codec)){
|
||||||
switch(st->codec.codec_type) {
|
switch(st->codec.codec_type) {
|
||||||
|
@ -1704,7 +1706,6 @@ static int try_decode_frame(AVStream *st, const uint8_t *data, int size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
avcodec_close(&st->codec);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1842,7 +1843,7 @@ int av_find_stream_info(AVFormatContext *ic)
|
||||||
duration_sum[index] += duration;
|
duration_sum[index] += duration;
|
||||||
duration_count[index]+= factor;
|
duration_count[index]+= factor;
|
||||||
}
|
}
|
||||||
if(st->codec_info_nb_frames == 0)
|
if(st->codec_info_nb_frames == 0 && 0)
|
||||||
st->codec_info_duration += duration;
|
st->codec_info_duration += duration;
|
||||||
}
|
}
|
||||||
last_dts[pkt->stream_index]= pkt->dts;
|
last_dts[pkt->stream_index]= pkt->dts;
|
||||||
|
@ -1883,6 +1884,12 @@ int av_find_stream_info(AVFormatContext *ic)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// close codecs which where opened in try_decode_frame()
|
||||||
|
for(i=0;i<ic->nb_streams;i++) {
|
||||||
|
st = ic->streams[i];
|
||||||
|
if(st->codec.codec)
|
||||||
|
avcodec_close(&st->codec);
|
||||||
|
}
|
||||||
for(i=0;i<ic->nb_streams;i++) {
|
for(i=0;i<ic->nb_streams;i++) {
|
||||||
st = ic->streams[i];
|
st = ic->streams[i];
|
||||||
if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
|
if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
|
||||||
|
|
Loading…
Reference in New Issue