使用C / C ++在ffmpeg中过滤Amerge [英] Amerge filter in ffmpeg with C/C++

查看:116
本文介绍了使用C / C ++在ffmpeg中过滤Amerge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我想用C / C ++将2个音频流合并在一起,我想我必须用户才能这样做。我有2个音频流以16位PCM格式解码,我想将它们合并到一个音频文件中。我四处寻找amerge过滤器示例,但无法找到。有没有人有ffmpeg的示例或教程或示例代码示例,说明如何使用它。



提前谢谢。

Hi There

I want to merge 2 audio streams together in C/C++ and I think I have to user amerge to do so. I have the 2 audio streams decoded in 16 bit PCM format and I want to merge them properly into one audio file. I looked around for amerge filter example but couldnt find any. Does anyone have an example or tutorial or sample code example from ffmpeg that shows how to use this.

Thanks in advance.

推荐答案

问题似乎是你不清楚合并两个音频流意味着什么。您可能的意思是以音频混音器的方式混合两个音频信号。为了实现这一点,两个流的样本必须在相同的时间点进行,即采样时钟必须已经同步。 (如果不是这种情况,你首先必须对流上的一个进行采样率转换,这是另一个故事,不一定适合初学者)。



两个同步音频信号的混合实际上非常简单。如果a(n)和b(n)是流a和b的第n个样本,则输出流c通过以下公式计算:

The problem seems to be that you don't have a clear idea what it means to "merge" two audio streams. What you probably mean is to mix both audio signals in a way that an audio mixer would do. For that to be possible, the samples of both streams must be taken at the same points in time, i.e. the sampling clocks must have been synchronized. (If that is not the case you first must do a sampling rate conversion of one on the streams, which is another story and not necessarily something for a beginner).

The "mixing" of two synchronized audio signals is actually very simple. If a(n) and b(n) are the n-th samples of the streams a and b, the output stream c is calculated by:
c(n) = f * a(n) + g * b(n);



两个因子f和g在[0,1.0]的范围内,并确定每个流混合的体积。通常为f + g不应该超过1.0,否则你可能会产生溢出,这听起来对你的结果非常讨厌。



所以你应该采取以下步骤:



(1)了解PCM格式以及如何访问流的每个样本



(2)创建输出流并分配所需的缓冲区空间



(3)使用上述混合公式在两个流上编程一个简单的循环



(4)将生成的流写入文件。



如果您在上述任何步骤中遇到问题,可能需要放置一个新问题,您现在可以更准确地参考您遇到困难的步骤。


The two factors f und g are in the range of [0, 1.0] and determine volume with which each of the streams is mixed in. Normally f + g should not exceed 1.0, otherwise you might produce overflows, which sound really nasty in your result.

So the steps you should take could be the following:

(1) Understand the PCM format and how you can access each sample of a stream

(2) Create the output stream and allocate the required buffer space

(3) Program a simple loop over both streams with the above mixing formula

(4) Write the generated stream to a file.

If you have problems in any of those steps, you might want to place a new question and you can now refer more precisely to the step in which you have the difficulty.


这篇关于使用C / C ++在ffmpeg中过滤Amerge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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