ffmpeg_struct: AVSampleFormat

在使用FFMPEG处理音频的时候,经常会有AV_SAMPLE_FMT_S16和AV_SAMPLE_FMT_S16P之间的转换,特别是在使用SDL的时候需要转换,今天就要好好研究下。


下面是ffmpeg2.7.1中AVSampleFormat的定义。

/**
 * Audio sample formats
 *
 * - The data described by the sample format is always in native-endian order.
 *   Sample values can be expressed by native C types, hence the lack of a signed
 *   24-bit sample format even though it is a common raw audio data format.
 *
 * - The floating-point formats are based on full volume being in the range
 *   [-1.0, 1.0]. Any values outside this range are beyond full volume level.
 *
 * - The data layout as used in av_samples_fill_arrays() and elsewhere in FFmpeg
 *   (such as AVFrame in libavcodec) is as follows:
 *
 * @par
 * For planar sample formats, each audio channel is in a separate data plane,
 * and linesize is the buffer size, in bytes, for a single plane. All data
 * planes must be the same size. For packed sample formats, only the first data
 * plane is used, and samples for each channel are interleaved. In this case,
 * linesize is the buffer size, in bytes, for the 1 plane.
 *
 */
enum AVSampleFormat {
    AV_SAMPLE_FMT_NONE = -1,
    AV_SAMPLE_FMT_U8,          ///< unsigned 8 bits
    AV_SAMPLE_FMT_S16,         ///< signed 16 bits
    AV_SAMPLE_FMT_S32,         ///< signed 32 bits
    AV_SAMPLE_FMT_FLT,         ///< float
    AV_SAMPLE_FMT_DBL,         ///< double

    AV_SAMPLE_FMT_U8P,         ///< unsigned 8 bits, planar
    AV_SAMPLE_FMT_S16P,        ///< signed 16 bits, planar
    AV_SAMPLE_FMT_S32P,        ///< signed 32 bits, planar
    AV_SAMPLE_FMT_FLTP,        ///< float, planar
    AV_SAMPLE_FMT_DBLP,        ///< double, planar

    AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
};


首先看下planar的含义:

planar 详细»
['pleɪnə]想启用英文朗读功能吗?请先安装flash插件! ['plenɚ]想启用英文朗读功能吗?请先安装flash插件!

  • adj. 平面的;二维的;平坦的

网络释义┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

  • 平面曲面平坦普兰纳

这样就知道AV_SAMPLE_FMT_S16P是平面格式,而AV_SAMPLE_FMT_S16是非平面格式,也可称为交错格式。

那到底平面格式和非平面格式有什么区别呢?


假设现在有2个通道channel1, channel2.

那么AV_SAMPLE_FMT_S16在内存的格式就为: c1, c2, c1, c2, c1, c2, ....

而AV_SAMPLE_FMT_S16P在内存的格式为: c1, c1, c1,... c2, c2, c2,...


现在就先理解到这里,够用的了。






// 参考:
//1. http://www.xuebuyuan.com/1624234.html
//2. http://stackoverflow.com/questions/18888986/what-is-the-difference-between-av-sample-fmt-s16p-and-av-sample-fmt-s16

AV_SAMPLE_FMT_S16P is planar signed 16 bit audio, i.e. 2 bytes for each sample which is same for AV_SAMPLE_FMT_S16.

The only difference is in AV_SAMPLE_FMT_S16 samples of each channel are interleaved i.e. if you have two channel audio then the samples buffer will look like

c1 c1 c2 c2 c1 c1 c2 c2...

where c1 is a sample for channel1 and c2 is sample for channel2.

while for one frame of planar audio you will have something like

c1 c1 c1 c1 .... c2 c2 c2 c2 ..

now how is it stored in AVFrame:

for planar audio:

data[i] will contain the data of channel i (assuming channel 0 is first channel).

however if you have more channels then 8 then data for rest of the channels can be found in extended_data attribute of AVFrame.

for non-planar audio

data[0] will contain the data for all channels in an interleaved manner.


//3. http://bbs.csdn.net/topics/390700255?page=1




  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
CMake是一个跨平台的开源构建工具,可用于自动化管理项目的编译过程。FFmpeg是一个开源的音视频处理库,可以用来处理多种格式的音视频文件。而最后的下载的文件opencv_ffmpeg_64.dll是OpenCV库所需的FFmpeg动态链接库。 当我们在使用CMake构建一个项目时,可能会用到FFmpeg库来进行音视频处理。其中,OpenCV是一个广泛使用的计算机视觉库,它也能够使用FFmpeg进行音视频的编解码与处理。而opencv_ffmpeg_64.dll是OpenCV库所需的FFmpeg依赖库,这个库在运行OpenCV相关功能时需要被加载。 如果在使用CMake构建一个依赖于OpenCV和FFmpeg的项目时,若缺少opencv_ffmpeg_64.dll文件,可以通过下载获得该文件。可以通过在网上搜索opencv_ffmpeg_64.dll文件的下载链接,并将其下载到本地。下载完成后,将该文件放置在项目中指定的位置,一般来说是与其他的动态链接库(.dll文件)放在一起的。然后重新进行CMake构建,以确保项目能够正确加载该库文件。 需要注意的是,下载的文件必须与你的系统和项目的架构相匹配。例如,如果你的系统是64位的,那么你需要下载64位的opencv_ffmpeg_64.dll文件,而不是32位的。如果下载的文件与你的系统不匹配,可能会导致项目构建失败或运行时错误。 总结来说,下载opencv_ffmpeg_64.dll文件是为了满足OpenCV库在进行音视频处理时所依赖的FFmpeg库的加载需求。在使用CMake构建项目时,下载并正确放置该文件,可以确保项目能够正确运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值