【发布时间】:2016-06-14 08:34:08
【问题描述】:
我目前正在使用 FFMpeg AutoGen 项目(当然是在 C# 中)从音频文件中解码帧并将它们添加到正在写入视频的新流中。这一切正常,但我想知道如何将两个 AVFrame* 对象混合在一起(在它们被解码之后)。
我以前混合过 PCM 数据,但想知道 FFmpeg 是否有内置 API 可以更有效地完成工作。
这就是我目前的做法:
short* baseFrameBuffer1 = (short*)baseFrame->data_0;
short* baseFrameBuffer2 = (short*)baseFrame->data_1;
short* readFrameBuffer1 = (short*)readFrame->data_0;
short* readFrameBuffer2 = (short*)readFrame->data_1;
for (int frameIndex = 0; frameIndex< 1024; frameIndex++)
{
int dataSample1 = GetInRangeSample(baseFrameBuffer1[frameIndex] + readFrameBuffer1[frameIndex]);
int dataSample2 = GetInRangeSample(baseFrameBuffer2[frameIndex] + readFrameBuffer2[frameIndex]);
baseFrame->data_0[frameIndex] = (byte)dataSample1;
baseFrame->data_1[frameIndex] = (byte)dataSample2;
}
private static int GetInRangeSample(int sample)
{
if (sample > short.MaxValue)
{
sample = short.MaxValue;
}
if (sample < short.MinValue)
{
sample = short.MinValue;
}
return sample;
}
【问题讨论】: