<p>Try</p>

<pre><code>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";
</code></pre>

CC BY-SA 3.0
2016-08-25T09:02:40.683Z
Thank you so much, Its perfect :) and small issue is first image is slightly appearing after 2 seconds?
Nisarg
CC BY-SA 3.0
2016-08-25T09:07:07.030Z
Either increase the `t` of the first image slightly, like to `2.5` or decrease the duration of the fade out.
Gyan
CC BY-SA 3.0
2016-08-25T09:15:27.103Z
Yup it worked and my video size is 25mb currently it takes 2-3 minutes to process, can we reduce it?
Nisarg
CC BY-SA 3.0
2016-08-25T09:21:10.980Z
Speed? No. Size? Yes - change preset to medium or slow.
Gyan
CC BY-SA 3.0
2016-08-25T09:22:09.357Z
I meant processing time?
Nisarg
CC BY-SA 3.0
2016-08-25T09:26:03.657Z
No, ultrafast is fastest possible.
Gyan
CC BY-SA 3.0
2016-08-25T09:41:42.260Z
Okay fine, can we apply blur background behind first and second images when they visible?
Nisarg
CC BY-SA 3.0
2016-08-25T10:02:24.057Z
Add `[0]boxblur=enable='lt(t,2)+gt(t,10)'[vid]` to the filter_complex and use `[vid]` for first overlay.
Gyan
CC BY-SA 3.0
2016-08-25T10:22:00.733Z
Can you update your answer with that?
Nisarg
CC BY-SA 3.0
2016-08-26T06:58:32.350Z
I have applied rotation to video, can you guide me for images in above command?
Nisarg
CC BY-SA 3.0
2016-08-26T07:02:47.840Z
You want to rotate the pics? Which direction?
Gyan
CC BY-SA 3.0
2016-08-26T07:04:47.743Z
Yes pics, I want to rotate pics as per video orientation
Nisarg
CC BY-SA 3.0
2016-08-26T07:10:12.040Z
Insert the transpose filter after the format filter for each image. e.g. `transpose=1` for 90 deg clockwise `2` for CCW.
Gyan
CC BY-SA 3.0
2016-08-26T07:15:39.150Z
Okay let me try
Nisarg
CC BY-SA 3.0
2016-08-25T08:35:54.840Z
2016-08-25T11:23:56.223Z
2016-08-25T11:23:56.223Z
Gyan
<p>I am using below commands to overlay two images with scaling in video :</p>

<pre><code>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";
</code></pre>

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

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

<p><strong>Aim to achieve</strong> : 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.</p>

CC BY-SA 3.0
2016-08-25T06:07:49.780Z
@Mulvya   Any help for this??
Nisarg
<video><ffmpeg>
Apply scale and fade effect to Images together
Nisarg
# Apply scale and fade effect to Images together

(Asked by: username_0 on 2016-08-25)

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.

**Tags:** video, ffmpeg

> **Comments:**
> **username_0**: @Mulvya   Any help for this??  

---

## 1 answers

### Answer by username_1 on 2016-08-25. Score: 1 | Accepted answer

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

> **Comments:**
> **username_0**: Thank you so much, Its perfect :) and small issue is first image is slightly appearing after 2 seconds?  
> **username_1**: Either increase the `t` of the first image slightly, like to `2.5` or decrease the duration of the fade out.  
> **username_0**: Yup it worked and my video size is 25mb currently it takes 2-3 minutes to process, can we reduce it?  
> **username_1**: Speed? No. Size? Yes - change preset to medium or slow.  
> **username_0**: I meant processing time?  
> **username_1**: No, ultrafast is fastest possible.  
> **username_0**: Okay fine, can we apply blur background behind first and second images when they visible?  
> **username_1**: Add `[0]boxblur=enable='lt(t,2)+gt(t,10)'[vid]` to the filter_complex and use `[vid]` for first overlay.  
> **username_0**: Can you update your answer with that?  
> **username_0**: I have applied rotation to video, can you guide me for images in above command?  
> **username_1**: You want to rotate the pics? Which direction?  
> **username_0**: Yes pics, I want to rotate pics as per video orientation  
> **username_1**: Insert the transpose filter after the format filter for each image. e.g. `transpose=1` for 90 deg clockwise `2` for CCW.  
> **username_0**: Okay let me try  

---

