简体   繁体   English

FFmpeg:替换实时视频流中的音频

[英]FFmpeg: replacing audio in live video stream

I'm using FFmpeg to encode and live-stream video captured through a DeckLink capture card.我正在使用 FFmpeg 对通过 DeckLink 采集卡捕获的视频进行编码和直播。 The video from the card comes with an audio stream, but I want to replace the audio stream with another.卡上的视频带有音频流,但我想用另一个音频流替换音频流。 This other audio stream originates from the same source but is ran through an audio processor that adds a fixed delay.另一个音频流来自同一源,但通过添加固定延迟的音频处理器运行。 The audio is fed back in the pc that runs FFmpeg through a virtual soundcard (audio over IP, but to Windows it looks like a sound card).音频通过虚拟声卡在运行 FFmpeg 的 pc 中反馈(IP 音频,但在 Windows 中它看起来像一个声卡)。

I know how to compensate for this fixed delay, but the issue is that audio and video drift slowly out of sync as the stream runs.我知道如何补偿这个固定延迟,但问题是音频和视频在流运行时缓慢地不同步。 I'm assuming this is due to the small difference in clock speeds between the virtual soundcard and the DeckLink card.我假设这是由于虚拟声卡和 DeckLink 卡之间的时钟速度差异很小。

I've tried the vsync option and the aresample filter in FFmpeg in an attempt to get audio and video to stay synced.我已经尝试了 FFmpeg 中的 vsync 选项和 aresample 过滤器,试图让音频和视频保持同步。 However I haven't succeeded in this yet.但是,我还没有成功。 Is there a way to make FFmpeg resample the audio and/or drop/dup frames in order to get both streams to stay in sync?有没有办法让 FFmpeg 重新采样音频和/或丢弃/复制帧,以使两个流保持同步?

Currently I'm running this command, which fails to stay in sync.目前我正在运行这个命令,它无法保持同步。

ffmpeg.exe -f dshow -i audio="WNIP Input  1 (Wheatstone Network Audio (WDM))" -itsoffset 2.3 -f decklink -thread_queue_size 128 -i "DeckLink SDI (3)" -filter_complex "[1:v:0]bwdif,format=yuv420p,setdar=16/9,scale=-1:576:flags=bicubic[vidout];[0:a:0]aresample=min_comp=0.02:comp_duration=15:max_soft_comp=0.005[audioout]" -c:v libx264 -preset slow -crf 25 -maxrate 1200k -bufsize 2400k -map "[vidout]:0" -map "[audioout]:0" -vsync 1 -r 50 -g 90 -keyint_min 90 -sc_threshold 0 -c:a libfdk_aac -b:a 192k -ac 2 -f flv "rtmp://somewhere"

I found the solution is to use the -use_wallclock_as_timestamps 1 flag for both the audio and the video stream ( ffmpeg docs here ).我发现解决方案是对音频和视频流使用-use_wallclock_as_timestamps 1标志( ffmpeg docs here )。 The complete command in my case then becomes:在我的情况下,完整的命令变为:

ffmpeg.exe -f dshow -use_wallclock_as_timestamps 1 -i audio="WNIP Input  1 (Wheatstone Network Audio (WDM))" -itsoffset 2.1 -f decklink -thread_queue_size 128  -use_wallclock_as_timestamps 1 -i "DeckLink SDI (3)" -filter_complex "[1:v:0]bwdif,format=yuv420p,setdar=16/9,scale=-1:576:flags=bicubic[vidout];[0:a:0]aresample=min_comp=0.02:comp_duration=15:max_soft_comp=0.005[audioout]" -c:v libx264 -preset slow -crf 25 -maxrate 1200k -bufsize 2400k -map "[vidout]:0" -map "[audioout]:0" -vsync 1 -r 50 -g 90 -keyint_min 90 -sc_threshold 0 -c:a libfdk_aac -b:a 192k -ac 2 -f flv "rtmp://somewhere"

Then after a few days both streams are still in sync.然后几天后,两个流仍然同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM