0

I am using below commands to overlay two images with scaling in video :

String command="ffmpeg -i /sdcard/videokit/input.mp4 -loop 1 -i /sdcard/videokit/first.png -loop 1 -i /sdcard/videokit/second.png -filter_complex [1:v]scale='if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'[img1];[2:v]scale='if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'[img2];[0:v][img1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[bkg];[bkg][img2]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -c:a copy -preset ultrafast /sdcard/videokit/output.mp4";

String command2="ffmpeg -i /sdcard/videokit/input.mp4 -loop 1 -t 2 -i /sdcard/videokit/first.png -loop 1 -t 2 -i /sdcard/videokit/second.png -filter_complex [1:v]trim=duration=2,fade=in:st=0:d=0.5,fade=out:st=1.5:d=0.5[img1];[2:v]trim=duration=2,fade=in:st=10:d=0.5,fade=out:st=11.5:d=0.5[img2];[0:v][img1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[bkg];[bkg][img2]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -preset ultrafast -c:a copy -preset ultrafast /sdcard/videokit/output.mp4";

First command works perfectly but I want to apply fade in fade out effect to both images for certain time.

I have tried with command2 after referring other answers but it doesn't seem to be working, any help would be appreciated!!!

Aim to achieve : Basically I have video of 12 seconds, first image has to be appear for first 2 seconds and last image for last 2 seconds with effect.

1
  • @Mulvya Any help for this??
    – Nisarg
    Commented Aug 25, 2016 at 6:07

1 Answer 1

1

Try

String command2="ffmpeg -i /sdcard/videokit/input.mp4 -loop 1 -t 2 -i /sdcard/videokit/first.png -loop 1 -t 2 -i /sdcard/videokit/second.png -filter_complex "[0]boxblur=enable='lt(t,2)+gt(t,10)'[vid];[1:v]format=rgba,fade=in:st=0:d=0.5:alpha=1,fade=out:st=1.5:d=0.5:alpha=1[img1];[2:v]format=rgba,fade=in:st=0:d=0.5:alpha=1,fade=out:st=1.5:d=0.5:alpha=1,setpts=PTS+10/TB[img2];[vid][img1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[bkg];[bkg][img2]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -preset ultrafast -c:a copy /sdcard/videokit/output.mp4";
14
  • Thank you so much, Its perfect :) and small issue is first image is slightly appearing after 2 seconds?
    – Nisarg
    Commented Aug 25, 2016 at 9:02
  • Either increase the t of the first image slightly, like to 2.5 or decrease the duration of the fade out.
    – Gyan
    Commented Aug 25, 2016 at 9:07
  • Yup it worked and my video size is 25mb currently it takes 2-3 minutes to process, can we reduce it?
    – Nisarg
    Commented Aug 25, 2016 at 9:15
  • Speed? No. Size? Yes - change preset to medium or slow.
    – Gyan
    Commented Aug 25, 2016 at 9:21
  • I meant processing time?
    – Nisarg
    Commented Aug 25, 2016 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.