0

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!

Community
  • 1
  • 1
Luong Truong
  • 1,953
  • 2
  • 27
  • 46
  • I think I know the issue. I've edited the first command in my answer you linked to. Try that. – Gyan Jun 23 '16 at 06:30
  • @Mulvya: I changed the command but the result is still the same. ffmpeg4android cannot recognize the "\" and """, so I remove them from your command. Will it cause any problems? – Luong Truong Jun 23 '16 at 06:52
  • Run the command with `-report` added and share the logfile generated. – Gyan Jun 23 '16 at 06:53
  • @Mulvya: I uploaded the logfile – Luong Truong Jun 23 '16 at 07:05
  • Link gives error. Upload it to pastebin or here. – Gyan Jun 23 '16 at 07:25
  • @Mulvya: it show 404 but you can still download it by clicking the download button on the top right corner. I don't know why but I cannot access pastebin here. The log is extremely long and I cannot pass it normally on stackoverflow. I really sorry for the inconvenience. – Luong Truong Jun 23 '16 at 07:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115381/discussion-between-luongtruong-and-mulvya). – Luong Truong Jun 23 '16 at 07:52
  • Try with a newer version or a different android-ffmpeg binary because it works here properly. – Gyan Jun 23 '16 at 12:58
  • @Mulvya: Actually, I just 1 thing in the command. The answer will be written below. Of course I welcome you to take a look. Thank you a lot for your help. – Luong Truong Jun 24 '16 at 00:51

1 Answers1

0

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!

Luong Truong
  • 1,953
  • 2
  • 27
  • 46
  • @Mulvya: After checking, I realize that the result video is played without audio. Can you give me some suggestion, please? I want to keep the audio of video. – Luong Truong Jun 27 '16 at 03:40
  • @Mulvya: there is an error: No such filter: 'acrossfade'. I think ffmpeg4android do not support this filter. :( – Luong Truong Jun 27 '16 at 07:38