diff options
author | Janne Grunau <janne-libav@jannau.net> | 2012-01-18 20:32:32 +0100 |
---|---|---|
committer | Janne Grunau <janne-libav@jannau.net> | 2012-01-20 09:41:46 +0100 |
commit | 59297ad63dbd7f9a587e742e1d5b0e94ae125fff (patch) | |
tree | dc75fcdb02bdbd4e38eda776a5d8b4b83ab23a53 | |
parent | b89f8774f2778c5aad4633a98e3a12597344730a (diff) | |
download | ffmpeg-59297ad63dbd7f9a587e742e1d5b0e94ae125fff.tar.gz |
lavf: force single-threaded decoding in avformat_find_stream_info
The H.264 decoder needs SPS and PPS for initialization during
multi-threaded decoding. When probed single-threaded SPS and PPS are
copied to extradata and are available for proper initialization of
the decoder before the first frame is decoded.
-rw-r--r-- | libavformat/utils.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index b1832ba717..22ee13b51f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2138,10 +2138,18 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option AVPacket pkt = *avpkt; if(!st->codec->codec){ + AVDictionary *thread_opt = NULL; + codec = avcodec_find_decoder(st->codec->codec_id); if (!codec) return -1; - ret = avcodec_open2(st->codec, codec, options); + + /* force thread count to 1 since the h264 decoder will not extract SPS + * and PPS to extradata during multi-threaded decoding */ + av_dict_set(options ? options : &thread_opt, "threads", "1", 0); + ret = avcodec_open2(st->codec, codec, options ? options : &thread_opt); + if (!options) + av_dict_free(&thread_opt); if (ret < 0) return ret; } @@ -2281,6 +2289,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) for(i=0;i<ic->nb_streams;i++) { AVCodec *codec; + AVDictionary *thread_opt = NULL; st = ic->streams[i]; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || @@ -2300,16 +2309,24 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) assert(!st->codec->codec); codec = avcodec_find_decoder(st->codec->codec_id); + /* force thread count to 1 since the h264 decoder will not extract SPS + * and PPS to extradata during multi-threaded decoding */ + av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); + /* Ensure that subtitle_header is properly set. */ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && codec && !st->codec->codec) - avcodec_open2(st->codec, codec, options ? &options[i] : NULL); + avcodec_open2(st->codec, codec, options ? &options[i] + : &thread_opt); //try to just open decoders, in case this is enough to get parameters if(!has_codec_parameters(st->codec)){ if (codec && !st->codec->codec) - avcodec_open2(st->codec, codec, options ? &options[i] : NULL); + avcodec_open2(st->codec, codec, options ? &options[i] + : &thread_opt); } + if (!options) + av_dict_free(&thread_opt); } for (i=0; i<ic->nb_streams; i++) { |