ffmpeg:音频样本的字节序 [英] ffmpeg: Endianness of audio samples

查看:199
本文介绍了ffmpeg:音频样本的字节序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ffmpeg的avcodec从c ++应用程序中的音乐文件中检索原始音频样本.对于文件,我对其进行了测试,看来这些文件样本的字节序为little-endian,但我想知道对于所有我尝试解码的文件来说,这是否总是正确的(即,来自ffmpeg的实现或至少是其架构,具体因为我的计算机的体系结构使用小端).如果没有,我认为这将取决于特定文件的编码格式.在那种情况下,如何检查要解码的每个文件采用哪种字节顺序?我在文档中找不到任何相关信息.

I use ffmpeg's avcodec to retrieve raw audio samples from music files in my c++ application. For files I test it on it appears that these files samples' endianness is little-endian, but I wonder if that will be always true for all files I'd try to decode (i.e. that comes from ffmpeg's implementation or at least it's architecture-specific since mine computer's architecture uses little endian). If not, I assume it would depend on particular file's encoding format. In that case how can I check which endianess applies for each file I'm decoding? I can't find any relevant information in the docs.

推荐答案

内部ffmpeg始终对音频样本使用本地字节序,因为这样可以更轻松地对数据执行各种操作(有关此问题的一些文档,请参见libavutil/samplefmt.h文件);根据文件格式的规定,编解码器的任务是转换为适当的字节序.作为一个简单的例子:有一个用于读/写原始样本的普通音频编解码器,称为pcm_*;例如有pcm_s16lepcm_s16be.在小端架构上,pcm_s16le将不进行任何转换,而pcm_s16be在解码/编码数据时将交换字节.

Internally ffmpeg always uses native endianness for audio samples since it makes it easier to perform various manipulations on the data (see libavutil/samplefmt.h file for some documentation on the matter); it is codec's task to convert to/from an appropriate endianness as dictated by file format. As a simple example of this: there is a family of trivial audiocodecs for reading/writing raw samples called pcm_*; e.g. there are pcm_s16le and pcm_s16be. On little-endian architecture pcm_s16le will do no conversion while pcm_s16be will swap bytes when decoding/encoding data.

这篇关于ffmpeg:音频样本的字节序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆