FFmpeg串联,最终输出中无音频 [英] FFmpeg concatenation, no Audio in Final Output

查看:173
本文介绍了FFmpeg串联,最终输出中无音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ffmpeg中使用以下命令,该命令将黑帧的1秒添加到视频的开头.但是,我在输出视频中丢失了原始视频中的音频.如何调整命令以确保原始音频与最终输出保持一致,或者更好的是,开始时有1秒的空白"音频,因此它与新的输出视频匹配.

I have the following command working in ffmpeg, which adds 1 second of a black frame to the beginning of the video. However, I lose the audio from the original video in the output video. How can I adjust the command to make sure the original audio stays with the final output, or better yet, there is 1 second of "blank" audio at the beginning so it matches the new output video.

ffmpeg -i originalvideo -f lavfi -i color=c=black:s=1920x1080:r=25:sar=1/1 -filter_complex "[0:v] setpts=PTS-STARTPTS [main]; [1:v] trim=end=1,setpts=PTS-STARTPTS [pre]; [pre][main] concat=n=2:v=1:a=0 [out]" -map "[out]" finaloutputvideo.mp4

推荐答案

您需要生成或添加与黑色视频相关联的音频,因为每个串联的部分都需要相同数量的视频和音频流.

You need to generate or add audio to be associated with the black video because each concatenated section needs the same number of video and audio streams.

ffmpeg \
-i originalvideo \
-f lavfi -i color=c=black:s=1920x1080:r=25:sar=1/1:d=1 \
-t 1 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
-filter_complex \
"[0:v]setpts=PTS-STARTPTS[mainv]; \
 [0:a]asetpts=PTS-STARTPTS[maina]; \
 [1:v][2:a][mainv][maina]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -movflags +faststart output.mp4

  • 您可以消除颜色和anullsrc源过滤器的(a)setpts过滤器,因为它们的时间戳始于0.

    • You can eliminate the (a)setpts filters for the color and anullsrc source filters since their timestamps start at 0.

      您可以避免使用修剪滤镜,因为您可以设置每个滤镜的持续时间.

      You can avoid the trim filter because you can set the duration for each filter.

      anullsrc持续时间的-t值只需小于或等于黑色视频的持续时间:concat过滤器将自动使其余部分保持沉默.

      The -t value for the anullsrc duration only needs to be less than or equal to the duration of the black video: the concat filter will automatically pad the rest with silence.

      使用anullsrc确保您匹配主视频的正确频道布局和音频采样率;否则concat可能会自动选择您可能不想要的通用"布局和费率.

      With anullsrc ensure that you match the proper channel layout and audio sample rate of your main video; otherwise concat may automatically choose a "common" layout and rate that may not be what you want.

      这篇关于FFmpeg串联,最终输出中无音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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