4

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.

14
  • Can you upload the raw inputs?
    – Gyan
    Nov 4, 2015 at 13:56
  • @Mulvya Sure. download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/… I'm using the same source for both - background and overlay for convenience. Nov 5, 2015 at 3:43
  • I added alpha channel on this input. Nov 5, 2015 at 3:51
  • 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?
    – Gyan
    Nov 5, 2015 at 8:03
  • 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 - natron.fr or Fusion - blackmagicdesign.com/in/products/fusion if you're looking for a free solution. else After Effects.
    – Gyan
    Nov 5, 2015 at 8:06

1 Answer 1

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 to the ffmpeg team, including the commands and output of both the single command and two-step process.

10
  • Also, ensure that you're using the latest or a fairly recent ffmpeg build.
    – Gyan
    Nov 7, 2015 at 10:04
  • 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. Nov 7, 2015 at 12:55
  • I have the N-75573-g1d0487f 64-bit static build from 29/09/2015, taken from this site: ffmpeg.zeranoe.com/builds
    – Gyan
    Nov 7, 2015 at 13:01
  • From the numbers, it seems mine is newer. Nov 7, 2015 at 13:02
  • Did you compile it yourself?
    – Gyan
    Nov 7, 2015 at 13:03

Your Answer

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

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