仅延迟 mp4 文件中音频流的一个通道

发布于 2025-01-15 21:52:56 字数 1657 浏览 0 评论 0原文

如何仅对包含立体声音频流的 mp4 的 1 个音频通道应用延迟?


我有一个包含 2 个流的视频 test.mp4

Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 8042 kb/s, 60 fps, 60 tbr, 60k tbn (default)
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)

如您所见AAC 音轨是立体声的。我需要将 2 秒延迟应用于音频流(流 1)中的通道。

下面是一个脚本,可以成功地对两个音频流执行此操作(此处有详细说明):

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map 1:a -c:v copy "test_delay.mp4"

基本上它使用 -map 选项来获取输入 id 0v 视频流(-i "test.mp4"是第一个, id 0 的未延迟输入),以及输入 id 1a 音频流(-itsoffset 2 -i "test. mp4" 是第二个 2 秒延迟的输入,id 为 1),用于构成最终输出。

我想我应该尝试使用 -map_channel ,但我也很困惑如何将其与 -itsoffset 选项合并。

以下结果导致视频没有音频流:

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map_channel 1.1.0:0.0 -map_channel 1.1.1:0.1 -c:v copy "test_delay.mp4"

而以下结果(这次包括 -map 1:a)导致 R ch 成功延迟,但根本没有 L ch(单声道音频流) ):

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map 1:a -map_channel 1.1.0:0.0 -map_channel 1.1.1:0.1 -c:v copy "test_delay.mp4"

有什么建议吗?


该命令将由自动化且不受监控的系统运行,因此如果可能的话,我真的尽力将其限制为仅执行 1 个命令。

How can I apply a delay to only 1 audio channel of an mp4 containing a stereo audio stream?


I have a video test.mp4 with 2 streams:

Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 8042 kb/s, 60 fps, 60 tbr, 60k tbn (default)
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)

As you can see the AAC track is stereo. I need to apply a 2-second delay to just the right channel in the audio stream (stream 1).

Here is a script that successfully does this for both audio streams (detailed description here):

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map 1:a -c:v copy "test_delay.mp4"

Basically it's using the -map option to grab input id 0's v video stream (-i "test.mp4" is the first, undelayed input with id 0), along with input id 1's a audio stream (-itsoffset 2 -i "test.mp4" is the second, 2-sec-delayed input with id 1) to compose the final output.

I think I should be trying to use -map_channel instead, but am confused how to incorporate it with the -itsoffset option as well.

The following results in a video with no audio streams:

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map_channel 1.1.0:0.0 -map_channel 1.1.1:0.1 -c:v copy "test_delay.mp4"

And the following (including -map 1:a this time) results in R ch being delayed successfully, but with no L ch at all (mono audio stream):

ffmpeg -i "test.mp4" -itsoffset 2 -i "test.mp4" -map 0:v -map 1:a -map_channel 1.1.0:0.0 -map_channel 1.1.1:0.1 -c:v copy "test_delay.mp4"

Any tips?


This command is to be run by an automated and unmonitored system so I'm really trying to keep it limited to just 1 command execution, if possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗心人 2025-01-22 21:52:56

使用 adelay 过滤器:

ffmpeg -i "test.mp4" -i "test.mp4" \
  -filter_complex[1:a]adelay=0|2000[out] \
  -map 0:v -c:v copy "test_delay.mp4"

adelay< /code> 采用以毫秒为单位的延迟序列,以 | 分隔,立体声通道布局为 LEFT|RIGHT,因此将第二个延迟设置为 2000 毫秒。

Use adelay filter:

ffmpeg -i "test.mp4" -i "test.mp4" \
  -filter_complex[1:a]adelay=0|2000[out] \
  -map 0:v -c:v copy "test_delay.mp4"

adelay takes a sequence of delays in milliseconds, separated by |, and stereo channel layout is LEFT|RIGHT so set the 2nd delay to be 2000 ms.

烟酉 2025-01-22 21:52:56

及时移动而不是延迟,请参阅此命令,该命令使用过滤器在 test.mp4 中将正确的音频流通道偏移 2 秒:

ffmpeg -i "test.mp4" -filter_complex "[0:a]adelay=2000|0,atrim=start=2:duration=99,asetpts=PTS-STARTPTS[out]" -map "[out]" -map 0:v -c:v copy -shortest "test_delay.mp4

@kesh 的答案是正确的,但如果单个音频通道必须 已知

  • test.mp4 的持续时间短于 99 秒
  • adelay=2000|0 将 LEFT 通道延迟 2000 毫秒,以抵消在跟随过滤器;最终左声道将返回到原来的位置

@kesh's answer is correct but if a single audio channel must be moved earlier in time instead of delayed, see this command which uses filters to offset the right audio stream channel by 2 seconds in test.mp4:

ffmpeg -i "test.mp4" -filter_complex "[0:a]adelay=2000|0,atrim=start=2:duration=99,asetpts=PTS-STARTPTS[out]" -map "[out]" -map 0:v -c:v copy -shortest "test_delay.mp4

Note that

  • test.mp4 is known to be shorter than 99 seconds in duration
  • adelay=2000|0 is delaying the LEFT channel by 2000 millis in order to offset what will happen in the following filters; ultimately the left channel will be returned to its original position
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文