av_find_stream_info

int av_find_stream_info(AVFormatContext *ic)

{

 
  1.     for(i=0;i<ic->nb_streams;i++) {  
  2.         分析AVCodecContext的每个AVStream  
  3.         st = ic->streams[i];  
  4.         if(st->codec->codec_type == CODEC_TYPE_VIDEO){  
  5. /*            if(!st->time_base.num) 
  6.                 st->time_base= */  
  7.             if(!st->codec->time_base.num)  
  8.                 st->codec->time_base= st->time_base;  
  9.         }  
  10.         //only for the split stuff   
  11.         if (!st->parser) {  
  12.             寻找AVStream的parser,  
  13.             st->parser = av_parser_init(st->codec->codec_id);  
  14.             if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){  
  15.                 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;  
  16.             }  
  17.         }  
  18.     }  

 

av_parser_init根据AVStream的codec_id找到对应的parser,所有的parser在libavcodec/all_codec.c中注册,例如mpegvideo_parser在(libavcodec/mpegvideo_parser.c):

 
  1. AVCodecParser mpegvideo_parser = {  
  2.     { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },  
  3.     sizeof(ParseContext1),  
  4.     NULL,  
  5.     mpegvideo_parse,  
  6.     ff_parse1_close,  
  7. };  

 

 如果AVStream对应的codec根本没有媒体的信息,比如采样率等(has_codec_parameters(st->codec)返回0),那么需要读取AVStream的数据来获取媒体的信息。读取AVStream一个packet的函数是av_read_frame_internal

在av_read_frame_internal返回后,ffmpeg从媒体数据中获取到了一个packet的数据,如果这个时候还是不知道媒体的格式(codec已经知道),那么可能需要解码媒体数据来获取媒体格式,这个时候调用try_decode_frame来解码frame

}

posted @ 2011-12-16 14:49  general001  阅读(784)  评论(0)    收藏  举报