av_find_stream_info还没有理解透彻?

来源:互联网 发布:教师资格证网络课程 编辑:程序博客网 时间:2024/06/02 13:52
int av_find_stream_info(AVFormatContext *ic){//1.初始化parserfor(i=0;i<ic->nb_streams;i++) {st = ic->streams[i];if (!st->parser) {st->parser = av_parser_init(st->codec->codec_id);if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;}}}for(;;) {for(i=0;i<ic->nb_streams;i++) {st = ic->streams[i];if (!has_codec_parameters(st->codec))break;}if (i == ic->nb_streams) {/* if we found the info for all the codecs, we can stop */break;}//2.如果codec参数还存在无效的,则读取一个Packetret = av_read_frame_internal(ic, &pkt1);if(st->parser && st->parser->parser->split && !st->codec->extradata){int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);if(i){st->codec->extradata_size= i;st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);}}if (!has_codec_parameters(st->codec) /)//3.如果codec参数还存在无效的,则通过解码来获取信息try_decode_frame(st, pkt->data, pkt->size);if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic-ax_analyze_duration)   break;count++;}return ret;}


视频解码为H264时的跟踪:

1. for(;;)中count执行了206次才退出
2. 第206次退出的地方:
if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) 
  break;
 满足了av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration导致退出

 av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration还得研究?

3. 设置数据断点发现st->codec->pix_fmt设置为PIX_FMT_YUV420P的地方:
函数堆栈try_decode_frame()->avcodec_open()->avctx->codec->init()->H264.c中的decode_init()下的
avctx->pix_fmt= avctx->get_format(avctx, avctx->codec->pix_fmts);

4.当前流退出av_find_stream_info的判断不仅是has_codec_parameters:
if (!has_codec_parameters(st->codec))
 break;
if(   tb_unreliable(st->codec)
   && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
   break;
if(st->parser && st->parser->parser->split && !st->codec->extradata)
 break;
if(st->first_dts == AV_NOPTS_VALUE)
 break;


 

原创粉丝点击