简体   繁体   English

循环播放视频不会重复音频FFMpeg

[英]Looping video doesn't repeat audio FFMpeg

I try to overlay two videos. 我尝试覆盖两个视频。 The first one is a background video with the audio track. 第一个是带有音轨的背景视频。 For this, I use the following command 为此,我使用以下命令

 command = arrayOf("-i", background, "-i", video,
       "-c:v", "libx264", "-preset", "ultrafast", "-filter_complex",
       "[1]crop=iw:ih/2:0:0[rgb];[1]crop=iw:ih/2:0:ih/2[alp];" +
        "[rgb][alp]alphamerge[va];[0]scale=$sw:$sh[bs];" +
        "[bs]loop=10:1000:0[bsl];[bsl][va]overlay=x=$startX:y=$startY:shortest=1",
        outPutPath)

But video plays the first cycle with audio, all the next cycles without. 但是视频会先播放音频,然后播放所有音频。 How to make video looping with audio? 如何使视频与音频循环播放?

The following command allows me to repeat audio. 以下命令允许我重复音频。

 arrayOf("-i", A.mp4, "-i", B.mp4,
     "-c:v", "libx264", "-preset", "ultrafast", "-filter_complex",
     "amovie=$A.mp4:loop=3,asetpts=N/SAMPLE_RATE/TB[a];" +
     [0]scale=$videoWidth:$videoHeight[bs];[bs]loop=10:1000:0,setpts=N/FRAME_RATE/TB[bsl];" +
     "[bsl][1]overlay=x=$startX:y=$startY:shortest=1[v]", "-map",
     "[v]", "-map", "[a]", "-shortest", outPutPath)

In this case, video repeats two times and stuck but audio still playing. 在这种情况下,视频重复两次并停滞,但音频仍在播放。 How do I trim the audio by length of the video? 如何按视频长度修整音频?

Main issue is that you need to add aloop and -map the appropriate filter outputs: 主要问题是您需要添加aloop-map适当的过滤器输出:

command = arrayOf("-i", background, "-i", video,
       "-c:v", "libx264", "-preset", "ultrafast", "-filter_complex",
       "[1]crop=iw:ih/2:0:0[rgb];[1]crop=iw:ih/2:0:ih/2[alp];" +
        "[rgb][alp]alphamerge[va];[0]scale=$sw:$sh[bs];" +
        "[bs]loop=10:1000:0,setpts=N/FRAME_RATE/TB[bsl];[1:a]aloop=10:1000:0,asetpts=N/SAMPLE_RATE/TB[a];[bsl][va]overlay=x=$startX:y=$startY:shortest=1[v]",
        "-map", "[v]", "-map", "[a]",
        outPutPath)

You will need to adjust the size parameter in the aloop filter. 您将需要在aloop过滤器中调整size参数。 1000 is just a placeholder. 1000只是一个占位符。 See the filter documentation. 请参阅过滤器文档。

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

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