如何缩放和混合音频? [英] How to scale and mux audio?

查看:69
本文介绍了如何缩放和混合音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题是音频重新缩放.我正在尝试重做 doc/examples/transcode_aac.c ,以便它也可以从41100重新采样到48000,其中包含一个警告,提示它无法执行操作.

First problem is with audio rescaling. I'm trying to redo doc/examples/transcode_aac.c so that it also resamples from 41100 to 48000, it contained a warning that it can't do it.

使用 doc/examples/resampling_audio.c 作为参考,我发现在进行 swr_convert 之前,我需要在输出端找到带有像这样的代码:

Using doc/examples/resampling_audio.c as a reference, I saw that before doing swr_convert, I need to find the number of audio samples at the output with the code like this:

    int dst_nb_samples = av_rescale_rnd( input_frame->nb_samples + swr_get_delay(resampler_context, 41100),
                                         48000, 41100, AV_ROUND_UP);

问题是,当我只设置 int dst_nb_samples = input_frame-> nb_samples (它是1024)时,它会正常编码和播放,但是当我这样做时 av_rescale_rnd 事情(导致1196年发生),音频会变慢并失真,就像音频中有跳音一样.

Problem is, when I just set int dst_nb_samples = input_frame->nb_samples (which is 1024), it encodes and plays normally, but when I do that av_rescale_rnd thing (which results in 1196), audio is slowed down and distorted, like there are skips in the audio.

第二个问题是尝试将 webm opus 音频混合.

Second problem is with trying to mux webm with opus audio.

当我将 AVStream-> time_base 设置为 1/48000 ,并将 AVFrame-> pts 增加960时,结果文件在播放器中以更大的文件播放.17秒的音频显示为16毫秒的音频,但可以正常播放.

When I set AVStream->time_base to 1/48000, and increase AVFrame->pts by 960, the resulted file is played in the player as a file that is much bigger. 17 seconds audio shows as 16m11s audio, but it plays normally.

当我将 pts 增大20时,它会正常显示,但是在编码过程中有很多 [libopus @ 00ffa660]队列输入在时间上向后消息.与 pts 30相同,仍然有这些消息.

When I increase pts by 20, it displays normally, but has a lot of [libopus @ 00ffa660] Queue input is backward in time messages during the encoding. Same for pts 30, still has those messages.

我应该尝试 time_scale 1/1000吗? webm 始终具有毫秒级的时间码,而 opus 则具有20ms的数据包大小(在48000 Hz时有960个样本).

Should I try time_scale 1/1000? webm always have timecodes in milliseconds, and opus have packet size of 20ms (960 samples at 48000 Hz).

搜索 pts + = 20;

这是整个文件,我所做的所有修改都用//MINE 标记: http://www.mediafire.com/file/jlgo7x4hiz7bw64/transcode_aac.c

Here is the whole file, all modification I did are marked with //MINE: http://www.mediafire.com/file/jlgo7x4hiz7bw64/transcode_aac.c

这是我在 http://www.mediafire.com上测试过的文件/file/zdy0zarlqw3qn6s/480P_600K_71149981_soundonly.mkv

推荐答案

最简单的方法是使用swr_convert_frame,它获取一帧并将其重新采样为完全不同的帧.您可以在此处了解更多信息: https://ffmpeg.org/doxygen/3.2/swresample_8h_source.html

The easiest way to achieve that is by using swr_convert_frame which take a frame and resample it to a completely different one. You can read more about it here: https://ffmpeg.org/doxygen/3.2/swresample_8h_source.html

这篇关于如何缩放和混合音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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