简体   繁体   English

使用 ffmpeg 将 PCM-ALAW 数据转换为音频文件

[英]Converting PCM-ALAW data to an audio file using ffmpeg

In my project, I processed the received RTP packets with the payload, and extracted all the payload to a separate buffer.在我的项目中,我处理接收到的带有负载的 RTP 数据包,并将所有负载提取到单独的缓冲区中。 This payload is - PCM ALAW (Type 8).此有效载荷是 - PCM ALAW(类型 8)。 How do I implement a class that will take as arguments - the file name and a buffer with raw data to create an audio file.我如何实现一个将作为参数的类 - 文件名和带有原始数据的缓冲区来创建音频文件。 Exactly what steps do I have to go through in order to encode raw data into an audio file?为了将原始数据编码为音频文件,我究竟需要经过哪些步骤? As an example, I used this example.作为一个例子,我使用了这个例子。

That sounds way too complex.这听起来太复杂了。 "PCM ALAW" is a bit misleading, but it's pretty clear that G.711 aLaw encoding is meant. “PCM ALAW”有点误导,但很明显 G.711 aLaw 编码的意思。 That's a trivial "compression" which maps each 16 bits PCM sample to an 8 bits value.这是一个微不足道的“压缩”,它将每个 16 位 PCM 样本映射到一个 8 位值。 So a trivial lookup fixes that.所以一个简单的查找就解决了这个问题。

There's even a Free implementation of the aLaw encoding available.甚至还有一个可用的 aLaw 编码的免费实现 Just convert each sample to 16 bits PCM, stuff a standard Microsoft WAVE header in front of it, and call the result .WAV .只需将每个样本转换为 16 位 PCM,在它前面填充一个标准的 Microsoft WAVE 标头,然后调用结果.WAV

You'll need to fill in a few WAV headers based on the RTP type 8. Chiefly, that's "Mono, 8000 Hz, 16 bits per sample".您需要根据 RTP 类型 8 填写一些 WAV 标头。主要是“单声道,8000 Hz,每个样本 16 位”。 One small problem with the header is that you can only write the full header once you know how many samples you have.标题的一个小问题是,您只能在知道有多少样本后才能编写完整的标题。 You could update the header whenever you receive a RTP packet, but that's a bit I/O intensive.您可以在收到 RTP 数据包时更新标头,但这有点 I/O 密集型。 It might be nicer to do that once per 10 packets or so.每 10 包左右执行一次可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM