转自:http://blog.csdn.net/woshizhanhun/archive/2009/01/04/3706408.aspx

这是ffmpeg.c里的一段代码,功能是打开文件并绑定音视频流信息到AVFormatContext 这个结构体

  1. static int read_ffserver_streams(AVFormatContext *s, const char *filename)
  2. {
  3.     int i, err;
  4.     AVFormatContext *ic;
  5.     /*打开文件,并将文件相关的信息存到ic中,filename为文件的完整路径*/
  6.     err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL);
  7.     if (err < 0)
  8.         return err;
  9.     /*复制文件里的流信息到输出的AVFormatContext结构体中,一般情况有2个流即nb_streams=2,

        s->streams[0]为 视频流,s->streams[1]为音频流*/

  10.     s->nb_streams = ic->nb_streams;
  11.     for(i=0;i<ic->nb_streams;i++) {
  12.         AVStream *st;
  13.         /*修正:需要一个更优化的解决方案*/
  14.         st = av_mallocz(sizeof(AVStream));
  15.         memcpy(st, ic->streams[i], sizeof(AVStream));
  16.         /*初始化编解码器结构体,将文件所用的编码格式存储到用于输出的AVFormatContext结构体中*/
  17.         st->codec = avcodec_alloc_context();
  18.         memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
  19.         s->streams[i] = st;
  20.     }
  21.     /*打开文件后需要关闭*/
  22.     av_close_input_file(ic);
  23.     return 0;
  24. }
posted on 2010-03-28 23:58 seedshopezhong 阅读(659) 评论(0)  编辑 收藏 引用 所属分类: ffmpeg study
只有注册用户登录后才能发表评论。