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