android - ffmpeg - making crossfade between 5 videos

1.1k views Asked by At

I want to make a small slideshow app which is able to do some effect like fade in, fade out, and crossfade between multiple videos by using ffmpeg4android.

After a few hours researching, I am still getting stuck in doing crossfade. Following this suggestion, I am able to create a crossfade but it is not work perfectly.

The problem is that I want to combine 5 videos with crossfade effect between them and the duration of each video is 5 seconds. As a result, the output file is only 5 seconds instead of 25 seconds and there is a crossfade effect in the end of output file.

Here is my command:

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";

UPDATE 1: ADD LOG

Please download the log file here

Please let me know if I did something wrong in my command. Any help would be appreciated.

Thank you in advance!

1

There are 1 answers

2
Luong Truong On

My command miss one sentence: "color=black:1280x720:d=21[v0];".

The d = 21 is the total duration of all video minus total crossfade time:
d = video1duration + ... video5duration - fadetime*(totalNumberOfVideo - 1).
In my case, each video's duration is 5 second and there are 5 videos, fadetime is 1 second.
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";

Hope it may help!