Answers.Body: <p>Breaking the process into two steps worked for me.</p>
  
  <p>See my output using the commands below at <a href="http://sendvid.com/g56xjz04" rel="nofollow">http://sendvid.com/g56xjz04</a></p>
  
  <p>The commands I used:</p>
  
  <pre><code>ffmpeg -y -i "video for overlay.mov" -vf "format=bgra, perspective=x0=0:y0=0:x1=W:y1=180, fade=in:10:1:alpha=1, fade=out:200:1:alpha=1, scale=-1:80, rotate=-0.1745:c=none:ow=rotw(-0.1745):oh=roth(-0.1745)" -c:v qtrle overlay.mov
  
  ffmpeg -y -i "base.mov" -i "overlay.mov" -filter_complex "[0:v][1:v] overlay=100:100:eof_action=pass [v]" -map "[v]" final_out.mov
  </code></pre>
  
  <p>I suspect that in the single command complex filterchain, there is some bug or nuance regarding the alpha channel operations that is generating a garbled alpha channel.</p>
  
  <p>If you need a single command, I think your best way forward is to submit a <a href="https://ffmpeg.org/bugreports.html" rel="nofollow">bug report</a> to the ffmpeg team, including the commands and output of both the single command and two-step process.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T10:04:30.447Z
Answers.Text: Also, ensure that you're using the latest or a fairly recent ffmpeg build.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T12:55:07.667Z
Answers.Text: I just tested the two commands with these versions: `N-76452-ga97f1e7` and `N-76045-g97be5d4`. Can you tell me which version you are using? Because I'm still getting the flickering.
Answers.UserDisplayName: Dhavan Vaidya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:01:27.127Z
Answers.Text: I have the N-75573-g1d0487f 64-bit static build from 29/09/2015, taken from this site: http://ffmpeg.zeranoe.com/builds/
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:02:33.633Z
Answers.Text: From the numbers, it seems mine is newer.
Answers.UserDisplayName: Dhavan Vaidya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:03:02.363Z
Answers.Text: Did you compile it yourself?
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:04:48.653Z
Answers.Text: I compiled `N-76452-ga97f1e7` and added `N-76045-g97be5d4` from here - https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media
Answers.UserDisplayName: Dhavan Vaidya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:07:34.047Z
Answers.Text: Try the latest version from the original source: https://www.ffmpeg.org/download.html
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T13:29:38.647Z
Answers.Text: Should I go for 2.8.1 (downloadable tar) or pull from git? Oh, I just compiled 2.8.1 and it says `No such filter: 'perspective'`
Answers.UserDisplayName: Dhavan Vaidya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-15T00:48:43.817Z
Answers.Text: @DhavanVaidya Always use git, not release.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-16T05:24:08.697Z
Answers.Text: @LordNeckbeard Okay. I'll do that and post what happens.
Answers.UserDisplayName: Dhavan Vaidya
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T10:03:06.423Z
Answers.LastActivityDate: 2015-11-07T10:20:13.020Z
Answers.LastEditDate: 2015-11-07T10:20:13.020Z
Answers.UserDisplayName: Gyan
Body: <p>I'm new to ffmpeg (video encoding in general).</p>
  
  <p>I have two videos one larger than the other. I want to rotate, resize and overlay the shorter video on the larger one at defined coordinates.</p>
  
  <p>So far, I'm doing this:</p>
  
  <ol>
  <li>Add alpha channel to both the videos: <code>ffmpeg -i demo.mov -vcodec qtrle -pix_fmt argb demo.mov</code></li>
  <li>Define fadein, fadeout, scale, overlay, perspective and rotation then output the video: <code>ffmpeg -y -i demo.mov -i demo2.mov -filter_complex  "[1:v] fade=in:10:1:alpha=1, fade=out:500:1:alpha=1, scale=80:80, perspective=x0=0:y0=0:x1=W:y1=40, rotate=-0.1745:c=none [ov]; [0:v][ov] overlay=100:100 [v]" -map "[v]" out.mov</code></li>
  </ol>
  
  <p>In this process, I'm facing a few problems:</p>
  
  <ol>
  <li>Am I adding alpha channels the right way?</li>
  <li>The final output has flickering background in the place where the rotated video has margins.</li>
  <li>The overlay remains a square. I do not want it to be square, but of the dimension specified by <code>perspective</code> filter.</li>
  </ol>
  
  <p>Some of the parameters in the above commands (such as <code>perspective</code>,<code>fade</code>) are arbitrary.</p>
  
  <p>To give a better perspective of what I'm trying to do: trying to add a video as though it was being played on a phone that is moving.</p>
  
  <p>I have asked about problems on IRC and got this far. I don't know how to proceed from here.</p>
  
  <p>Here is the output: https://youtu.be/yd4UWq5NO5M</p>
  
  <p>Any help would be great.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-04T13:56:43.607Z
Comments.Text: Can you upload the raw inputs?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T03:43:40.893Z
Comments.Text: @Mulvya Sure. http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mov_480x360.mov
  I'm using the same source for both - background and overlay for convenience.
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T03:51:06.317Z
Comments.Text: I added alpha channel on this input.
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T08:03:56.980Z
Comments.Text: I'll have a closer look later, but there is no alpha channel. The pixel format is yuv420p. Mind you, you don't need an alpha channel for what you're trying to do. In any case, what would the alpha channel be populated with?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T08:06:22.647Z
Comments.Text: Also, since you're "trying to add a video as though it was being played on a phone that is moving", this is best done in a compositing app with a tracker. Look into Natron - http://natron.fr/ or Fusion - https://www.blackmagicdesign.com/in/products/fusion if you're looking for a free solution. else After Effects.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T11:56:30.273Z
Comments.Text: **Why I add alpha channel:** when I tried to overlay the video without alpha channel, a black background remained when I faded it out. Adding alpha channel removed it. So, I'm adding the channel so that there are no remains of the overlay when it fades out.
  
  I need to integrate this functionality into my app, so not using third party solutions is nicer :)
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-05T13:06:52.080Z
Comments.Text: No need for alpha channel. Your last filter should be [0:v][ov] overlay=100:100:eof_action=pass [v]
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T03:51:53.903Z
Comments.Text: Yep! That worked! Now I don't have to worry about large sized intermediate videos. Thanks!
  However the flickering issue is still there.
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T10:51:06.090Z
Comments.Text: The weird thing is the flickering almost completely vanishes if I perform the task in two commands i.e. one ffmpeg command to output a MOV with the transformed video with the fades and one command to perform the overlay of that MOV on top of the original. But the identical filterchain for the first step when integrated into a single command, gives flickering.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T13:22:53.917Z
Comments.Text: I have tried multiple videos. All have been giving the flickering. I haven't tried separating the filter chains though.
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T13:30:16.380Z
Comments.Text: Try this for the first command :  ffmpeg -y -i "input.mov" -vf "format=bgra, perspective=x0=0:y0=0:x1=W:y1=180, fade=in:10:1:alpha=1, fade=out:200:1:alpha=1, scale=-1:80, rotate=-0.1745:c=none:ow=rotw(iw):oh=roth(ih)" -c:v qtrle output.mov
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T13:31:36.990Z
Comments.Text: And 2nd: ffmpeg -y -i "input.mov" -i "output.mov" -filter_complex "[0:v][1:v] overlay=100:100:eof_action=pass [v]" -map "[v]" final_out.mov
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-07T03:47:02.453Z
Comments.Text: Flickering a lot. Here: https://youtu.be/ZzLBVRGfn60
Comments.UserDisplayName: Dhavan Vaidya
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-07T05:24:26.277Z
Comments.Text: Let me check here again.
Comments.UserDisplayName: Gyan
Tags: <video><ffmpeg><editing><codec>
Title: ffmpeg: overlay rotated video with transparency
UserDisplayName: Dhavan Vaidya
ThreadText: # ffmpeg: overlay rotated video with transparency
  
  (Asked by: username_0 on 2015-11-04)
  
  I'm new to ffmpeg (video encoding in general).
  
  I have two videos one larger than the other. I want to rotate, resize and overlay the shorter video on the larger one at defined coordinates.
  
  So far, I'm doing this:
  
  1. Add alpha channel to both the videos: `ffmpeg -i demo.mov -vcodec qtrle -pix_fmt argb demo.mov`
  2. Define fadein, fadeout, scale, overlay, perspective and rotation then output the video: `ffmpeg -y -i demo.mov -i demo2.mov -filter_complex "[1:v] fade=in:10:1:alpha=1, fade=out:500:1:alpha=1, scale=80:80, perspective=x0=0:y0=0:x1=W:y1=40, rotate=-0.1745:c=none [ov]; [0:v][ov] overlay=100:100 [v]" -map "[v]" out.mov`
  
  In this process, I'm facing a few problems:
  
  1. Am I adding alpha channels the right way?
  2. The final output has flickering background in the place where the rotated video has margins.
  3. The overlay remains a square. I do not want it to be square, but of the dimension specified by `perspective` filter.
  
  Some of the parameters in the above commands (such as `perspective`,`fade`) are arbitrary.
  
  To give a better perspective of what I'm trying to do: trying to add a video as though it was being played on a phone that is moving.
  
  I have asked about problems on IRC and got this far. I don't know how to proceed from here.
  
  Here is the output: https://youtu.be/yd4UWq5NO5M
  
  Any help would be great.
  
  **Tags:** video, ffmpeg, editing, codec
  
  > **Comments:**
  > **username_1**: Can you upload the raw inputs?  
  > **username_0**: @Mulvya Sure. http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mov_480x360.mov I'm using the same source for both - background and overlay for convenience.  
  > **username_0**: I added alpha channel on this input.  
  > **username_1**: I'll have a closer look later, but there is no alpha channel. The pixel format is yuv420p. Mind you, you don't need an alpha channel for what you're trying to do. In any case, what would the alpha channel be populated with?  
  > **username_1**: Also, since you're "trying to add a video as though it was being played on a phone that is moving", this is best done in a compositing app with a tracker. Look into Natron - http://natron.fr/ or Fusion - https://www.blackmagicdesign.com/in/products/fusion if you're looking for a free solution. else After Effects.  
  > **username_0**: **Why I add alpha channel:** when I tried to overlay the video without alpha channel, a black background remained when I faded it out. Adding alpha channel removed it. So, I'm adding the channel so that there are no remains of the overlay when it fades out.  I need to integrate this functionality into my app, so not using third party solutions is nicer :)  
  > **username_1**: No need for alpha channel. Your last filter should be [0:v][ov] overlay=100:100:eof_action=pass [v]  
  > **username_0**: Yep! That worked! Now I don't have to worry about large sized intermediate videos. Thanks! However the flickering issue is still there.  
  > **username_1**: The weird thing is the flickering almost completely vanishes if I perform the task in two commands i.e. one ffmpeg command to output a MOV with the transformed video with the fades and one command to perform the overlay of that MOV on top of the original. But the identical filterchain for the first step when integrated into a single command, gives flickering.  
  > **username_0**: I have tried multiple videos. All have been giving the flickering. I haven't tried separating the filter chains though.  
  > **username_1**: Try this for the first command :  ffmpeg -y -i "input.mov" -vf "format=bgra, perspective=x0=0:y0=0:x1=W:y1=180, fade=in:10:1:alpha=1, fade=out:200:1:alpha=1, scale=-1:80, rotate=-0.1745:c=none:ow=rotw(iw):oh=roth(ih)" -c:v qtrle output.mov  
  > **username_1**: And 2nd: ffmpeg -y -i "input.mov" -i "output.mov" -filter_complex "[0:v][1:v] overlay=100:100:eof_action=pass [v]" -map "[v]" final_out.mov  
  > **username_0**: Flickering a lot. Here: https://youtu.be/ZzLBVRGfn60  
  > **username_1**: Let me check here again.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-07. Score: 1
  
  Breaking the process into two steps worked for me.
  
  See my output using the commands below at <http://sendvid.com/g56xjz04>
  
  The commands I used:
  
  ```
  ffmpeg -y -i "video for overlay.mov" -vf "format=bgra, perspective=x0=0:y0=0:x1=W:y1=180, fade=in:10:1:alpha=1, fade=out:200:1:alpha=1, scale=-1:80, rotate=-0.1745:c=none:ow=rotw(-0.1745):oh=roth(-0.1745)" -c:v qtrle overlay.mov
  
  ffmpeg -y -i "base.mov" -i "overlay.mov" -filter_complex "[0:v][1:v] overlay=100:100:eof_action=pass [v]" -map "[v]" final_out.mov
  
  ```
  
  I suspect that in the single command complex filterchain, there is some bug or nuance regarding the alpha channel operations that is generating a garbled alpha channel.
  
  If you need a single command, I think your best way forward is to submit a [bug report](https://ffmpeg.org/bugreports.html) to the ffmpeg team, including the commands and output of both the single command and two-step process.
  
  > **Comments:**
  > **username_1**: Also, ensure that you're using the latest or a fairly recent ffmpeg build.  
  > **username_0**: I just tested the two commands with these versions: `N-76452-ga97f1e7` and `N-76045-g97be5d4`. Can you tell me which version you are using? Because I'm still getting the flickering.  
  > **username_1**: I have the N-75573-g1d0487f 64-bit static build from 29/09/2015, taken from this site: http://ffmpeg.zeranoe.com/builds/  
  > **username_0**: From the numbers, it seems mine is newer.  
  > **username_1**: Did you compile it yourself?  
  > **username_0**: I compiled `N-76452-ga97f1e7` and added `N-76045-g97be5d4` from here - https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media  
  > **username_1**: Try the latest version from the original source: https://www.ffmpeg.org/download.html  
  > **username_0**: Should I go for 2.8.1 (downloadable tar) or pull from git? Oh, I just compiled 2.8.1 and it says `No such filter: 'perspective'`  
  > **username_2**: @username_0 Always use git, not release.  
  > **username_0**: @LordNeckbeard Okay. I'll do that and post what happens.  
  
  ---
  
  