title: Ffmpeg alpha channel video generation
body: <p>I am trying to remove a background from a video using ffmpeg and a PY library that does that, the PY lib (backgroundremover) just creates a matte.mp4 file as an output, having the background as black and the person as white silhouette.</p>
  <p>PY lib: <a href="https://github.com/nadermx/backgroundremover#advance-usage-for-video" rel="nofollow noreferrer">https://github.com/nadermx/backgroundremover#advance-usage-for-video</a></p>
  <p>What I am doing at the moment:</p>
  <p>Shrink &amp; convert the video to MP4</p>
  <pre><code>ffmpeg -i ios.mov -s 320x240 -filter:v fps=30 -vf scale=320:-2 edited.mp4
  </code></pre>
  <p>Create the matte video</p>
  <pre><code>backgroundremover -i edited.mp4 -wn 4 -mk -o matte.mp4
  </code></pre>
  <p>Create video with alpha channel (the problem)</p>
  <pre><code>ffmpeg -i edited.mp4 -i matte.mp4 -filter_complex &quot;[0:v][1:v]alphamerge&quot; -shortest -c:v qtrle -an output.mov
  </code></pre>
  <p>Last command fails with invalid frame sizes, how do I force a frame size or skip this check?</p>
  <p>Error:</p>
  <pre><code>[swscaler @ 0x7ff5c957b000] No accelerated colorspace conversion found from yuv420p to argb.
  [Parsed_alphamerge_0 @ 0x7ff5c4e6d480] Input frame sizes do not match (320x240 vs 426x320).
  [Parsed_alphamerge_0 @ 0x7ff5c4e6d480] Failed to configure output pad on Parsed_alphamerge_0
  Error reinitializing filters!
  Failed to inject frame into filter network: Invalid argument
  </code></pre>
  <p>Answer:</p>
  <pre><code>ffmpeg -y -i edited.mp4 -i matte.mp4 -f lavfi -i color=c=black:s=320x240 -filter_complex &quot;[1:v]scale=320:240,setsar=1:1,split[vs][alpha];[0:v][vs]alphamerge[vt];[2:v][vt]overlay=shortest=1[rgb];[rgb][alpha]alphamerge&quot; -shortest -c:v hevc_videotoolbox -allow_sw 1 -alpha_quality 0.75 -vtag hvc1 -pix_fmt yuva420p -an output.mov
  </code></pre>