AVCodecContext结构的 frame_size 字段含义

  • Post author:
  • Post category:其他

 

AVCodecContext结构的 frame_size 字段含义:  

 /* The following data should not be initialized. */
    /**
     * Samples per packet, initialized when calling ‘init’.
     */
音频处理单元,也就是一个packet里有多少次采样。
比如采样率是48000,而frame_size=1152,
表示:每秒有48000次采样,而每个packet有1152次采样,
所以一个packet的时间是1152/48000 * 1000 = 24毫秒
decoding_encoding.c文件中的mp2音频编码例子:
 for(i=0;i<200;i++) {
        av_init_packet(&pkt);
        pkt.data = NULL; // packet data will be allocated by the encoder
        pkt.size = 0;

        for (j = 0; j < c->frame_size; j++) {
            samples[2*j] = (int)(sin(t) * 10000);

            for (k = 1; k < c->channels; k++)
                samples[2*j + k] = samples[2*j];
            t += tincr;
        }

          /* encode the samples */        ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);

}

时间应该是:200*24 = 4800ms


版权声明:本文为anbinger2013原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。