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