Mercurial > libavformat.hg
comparison utils.c @ 6227:78ee17447ff3 libavformat
In av_find_stream_info, decode at least 4 h.264 frames to be able to guess delay.
| author | bcoudurier |
|---|---|
| date | Sat, 03 Jul 2010 03:07:33 +0000 |
| parents | f5cb0b79f58c |
| children | 322e7096671d |
comparison
equal
deleted
inserted
replaced
| 6226:7b81ef3e7d99 | 6227:78ee17447ff3 |
|---|---|
| 2017 break; | 2017 break; |
| 2018 } | 2018 } |
| 2019 return enc->codec_id != CODEC_ID_NONE && val != 0; | 2019 return enc->codec_id != CODEC_ID_NONE && val != 0; |
| 2020 } | 2020 } |
| 2021 | 2021 |
| 2022 static int has_decode_delay_been_guessed(AVStream *st) | |
| 2023 { | |
| 2024 return st->codec->codec_id != CODEC_ID_H264 || | |
| 2025 st->codec_info_nb_frames >= 4 + st->codec->has_b_frames; | |
| 2026 } | |
| 2027 | |
| 2022 static int try_decode_frame(AVStream *st, AVPacket *avpkt) | 2028 static int try_decode_frame(AVStream *st, AVPacket *avpkt) |
| 2023 { | 2029 { |
| 2024 int16_t *samples; | 2030 int16_t *samples; |
| 2025 AVCodec *codec; | 2031 AVCodec *codec; |
| 2026 int got_picture, data_size, ret=0; | 2032 int got_picture, data_size, ret=0; |
| 2033 ret = avcodec_open(st->codec, codec); | 2039 ret = avcodec_open(st->codec, codec); |
| 2034 if (ret < 0) | 2040 if (ret < 0) |
| 2035 return ret; | 2041 return ret; |
| 2036 } | 2042 } |
| 2037 | 2043 |
| 2038 if(!has_codec_parameters(st->codec)){ | 2044 if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)){ |
| 2039 switch(st->codec->codec_type) { | 2045 switch(st->codec->codec_type) { |
| 2040 case AVMEDIA_TYPE_VIDEO: | 2046 case AVMEDIA_TYPE_VIDEO: |
| 2041 avcodec_get_frame_defaults(&picture); | 2047 avcodec_get_frame_defaults(&picture); |
| 2042 ret = avcodec_decode_video2(st->codec, &picture, | 2048 ret = avcodec_decode_video2(st->codec, &picture, |
| 2043 &got_picture, avpkt); | 2049 &got_picture, avpkt); |
| 2315 | 2321 |
| 2316 /* if still no information, we try to open the codec and to | 2322 /* if still no information, we try to open the codec and to |
| 2317 decompress the frame. We try to avoid that in most cases as | 2323 decompress the frame. We try to avoid that in most cases as |
| 2318 it takes longer and uses more memory. For MPEG-4, we need to | 2324 it takes longer and uses more memory. For MPEG-4, we need to |
| 2319 decompress for QuickTime. */ | 2325 decompress for QuickTime. */ |
| 2320 if (!has_codec_parameters(st->codec)) | 2326 if (!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)) |
| 2321 try_decode_frame(st, pkt); | 2327 try_decode_frame(st, pkt); |
| 2322 | 2328 |
| 2323 count++; | 2329 count++; |
| 2324 } | 2330 } |
| 2325 | 2331 |
