1. 8 Bit 單聲道: 數組
採樣1 | 採樣2 |
數據1 | 數據2 |
2. 8 Bit 雙聲道 spa
採樣1 | 採樣2 | ||
聲道1數據1 | 聲道2數據1 | 聲道1數據2 | 聲道2數據2 |
1. 16 Bit 單聲道: ci
採樣1 | 採樣2 | ||
數據1低字節 | 數據1高字節 | 數據1低字節 | 數據1高字節 |
2. 16 Bit 雙聲道 it
採樣1 | |||
聲道1數據1低字節 | 聲道1數據1高字節 | 聲道2數據1低字節 | 聲道2數據1高字節 |
採樣2 | |||
聲道1數據2低字節 | 聲道1數據2高字節 | 聲道2數據2低字節 | 聲道2數據2高字節 |
對於ffmpeg來講,音頻數據會保存在AVFrame中extended_data數組中,若是是打包模式(packed),就只用extended_data[0],若是是planar模式,則每一個channel分別保存在extended_data[i]中。對於音頻,只有linesize[0]有效,打包模式保存整個音頻幀的buff大小,planar模式保存每一個channel的buff大小。 io
ffmpeg中對兩種模式(planar和packed)的說明(在frame.h文件中有詳細說明): table
* For planar audio, each channel has a separate data pointer, and
* linesize[0] contains the size of each channel buffer.
* For packed audio, there is just one data pointer, and linesize[0]
* contains the total size of the buffer for all channels. 音頻
下面是一個小例子來存儲格式數據(利用ffmpeg): ffmpeg
short *sample_buffer_L = pFrame->extended_data[0];//存放着左聲道的數據
short *sample_buffer_R = pFrame->extended_data[1];//存放着右聲道的數據 打包
二者都是16bit,而裸的PCM文件裏的數據是按照 LRLRLRLR 這樣存儲的,因此咱們須要按照這種格式存儲16bit的數據: channel
//Left channel
data[i] = (char)(sample_buffer_L[j] & 0xff);//左聲道低8位
data[i+1] = (char)((sample_buffer_L[j]>>8) & 0xff);;//左聲道高8位
//Right channel
data[i+2] = (char)(sample_buffer_R[j] & 0xff);//右聲道低8位
data[i+3] = (char)((sample_buffer_R[j]>>8) & 0xff);;//右聲道高8位