0

我想制作一个小型幻灯片应用程序,它能够使用ffmpeg4android在多个视频之间进行淡入、淡出和交叉淡入淡出等效果。

经过几个小时的研究,我仍然陷入了淡入淡出。按照这个建议,我可以创建一个交叉淡入淡出,但它不能完美地工作。

问题是我想将 5 个视频与它们之间的淡入淡出效果结合起来,每个视频的持续时间为 5 秒。结果,输出文件只有 5 秒而不是 25 秒,并且在输出文件的末尾有一个淡入淡出效果。

这是我的命令:

String commandStr = "ffmpeg " +
                "-y " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-filter_complex " +
                "[0:v]setpts=PTS-STARTPTS[v1];" +
                "[1:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(4/TB)[v2];" +
                "[2:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(8/TB)[v3];" +
                "[3:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(12/TB)[v4];" +
                "[4:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(16/TB)[v5];" +
                "[v1][v2]overlay[v12];[v12][v3]overlay[v123];[v123][v4]overlay[v1234];[v1234][v5]overlay,format=yuv420p[v] " +
                "-map [v] " +
                "/sdcard/videokit/result.mp4";

更新 1:添加日志

请在此处下载日志文件

如果我在命令中做错了什么,请告诉我。任何帮助,将不胜感激。

先感谢您!

4

1 回答 1

0

我的命令错过了一句话:"color=black:1280x720:d=21[v0];".

d = 21 是所有视频的总持续时间减去总淡入淡出时间:
d = video1duration + ... video5duration - fadetime*(totalNumberOfVideo - 1)
就我而言,每个视频的持续时间为 5 秒,并且有 5 个视频,淡入淡出时间为 1 秒。
d = 5 + 5 + 5 + 5 + 5 - 1*(5-1) = 21

String commandStr = "ffmpeg " +
                "-y " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-i /sdcard/videokit/big_buck.mp4 " +
                "-filter_complex " +
                "color=black:1280x720:d=21[v0];" +
                "[0:v]setpts=PTS-STARTPTS[v1];" +
                "[1:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(4/TB)[v2];" +
                "[2:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(8/TB)[v3];" +
                "[3:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(12/TB)[v4];" +
                "[4:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(16/TB)[v5];" +
                "[v0][v1]overlay[v01];[v01][v2]overlay[v012];[v012][v3]overlay[v0123];[v0123][v4]overlay[v01234];[v01234][v5]overlay,format=yuv420p[v] " +
                "-map [v] " +
                "/sdcard/videokit/result.mp4";

希望它可以帮助!

于 2016-06-24T01:03:08.580 回答