【发布时间】:2016-09-06 04:51:26
【问题描述】:
我正在使用 FFmpeg 库来解码和(可能)修改一些音频。
我设法使用以下函数来遍历音频文件的所有帧:
avformat_open_input // Obtains formatContext
avformat_find_stream_info
av_find_best_stream // The argument AVMEDIA_TYPE_AUDIO is fed in to find the audio stream
avcodec_open2 // Obtains codecContext
av_init_packet
// The following is used to loop through the frames
av_read_frame
avcodec_decode_audio4
最后,我在每次迭代中都有这三个值
int dataSize; // return value of avcodec_decode_audio4
AVFrame* frame;
AVCodecContext* codecContext; // Codec context of the best stream
我认为这样的循环可以用来遍历所有样本:
for (int i = 0; i < frame->nb_samples; ++i)
{
// Bytes/Sample is known to be 4
// Extracts audio from Channel 1. There are in total 2 channels.
int* sample = (int*)frame->data[0] + dataSize * i;
// Now *sample is accessible
}
但是,当我使用gnuplot 绘制数据时,并没有得到预期的波形,并且某些值达到了 32 位整数的限制:(音频流在前几秒内没有静音)
我想某种形式的量化正在进行,以防止数据被数学解释。我应该怎么做才能去量化?
【问题讨论】:
-
在 44.1kHz 的典型采样率下,18,000 个样本大约需要 4.3 秒,因此您当然看不到典型波形。尝试放大,看看它是否与您预期的不同。
-
@Linuxios 我放大到大约
100ms(4410 个样本),图表确实显示了一些周期性,但幅度并不反映音频的音量,因为它经常达到 +/- 2147483647 -
这不一定是真的。有些东西可以覆盖 24 位音频的全部范围,并且仍然可以安静地播放。如果您以 Audacity 之类的方式打开原始文件,如果您查看波形的同一部分,您会看到什么?
-
@Linuxios 第一个
80ms沉默,[80,100]ms范围有一点波动。 -
好的。这很奇怪:)。别管我……
标签: c++ audio ffmpeg signal-processing libavcodec