【发布时间】:2019-05-30 15:08:23
【问题描述】:
我收到一个字节数组 (int8_t*),我想使用 FFMPEG 将其编码为 FLAC。我发现的所有示例都是从文件中读取数据,但对我来说并非如此。根据原始文档(见here),我想出了以下解决方案:
#include "libavcodec/avcodec.h"
// ...
// params:
// audioData: original audio data
// len: length of the byte array (audio data)
// sampleRate: sample rate of the original audio data
// frameSize: frame size of the original data
uint8_t* encodeToFlac(uint8_t* audioData, int len, int sampleRate, int frameSize) {
uint8_t* convertedAudioData;
// Context information
AVCodecContext* context = avcodec_alloc_context();
context->bit_rate = 64000;
context->sample_rate = sampleRate;
context->channels = 2;
context->frame_size = frameSize;
short* samples = malloc(frameSize * 2 * context->channels);
int outAudioDataSize = len * 2;
convertedAudioData = malloc(outAudioDataSize);
int outSize = avcodec_encode_audio(c, convertedAudioData, outAudioDataSize, samples);
return convertedAudioData;
}
我对上述解决方案有两个主要问题:
我没有指定最终的编码应该是什么(例如,MP3、FLAC 等),这让我怀疑我是否正确使用了 FFMPEG 库?
我是否拥有有关源的所有必要信息 - 原始音频数据?我不确定我是否拥有执行编码所需的所有信息。
【问题讨论】:
-
直接使用 libflac 会容易得多。
-
它不是 ffmpeg 的一部分,是吗?恐怕我除了 ffmpeg 没有其他东西可以使用。
-
I'm afraid I do not have anything other than ffmpeg to use你可以下载。 -
是的,但不是这个项目,我不能。