Answers.Body: <p>Use the overlay filter to composite the output image.</p>
  <p><code>ffmpeg -framerate 30 -i 'template %05d.png' -vf &quot;split=2[bg][img];[bg]format=yuv420p,drawbox=c=black:t=fill[bg];[bg][img]overlay=alpha=straight&quot; -pix_fmt yuv420p -c:v libx264 out.mp4</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-23T05:20:07.447Z
Answers.Text: That worked, Thank you!
Answers.UserDisplayName: memo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-22T03:50:55.537Z
Answers.LastActivityDate: 2024-01-22T03:50:55.537Z
Answers.UserDisplayName: Gyan
Body: <p>I have a sequence of pngs <strong>with alpha</strong>, and I'd like to encode to h264 <strong>without alpha</strong>, overlaid on black.</p>
  <p>My usual command for image sequence to h264 is</p>
  <p><code>ffmpeg -r 30 -i 'template %05d.png' -c:v libx264 -pix_fmt yuv420p out.mp4</code></p>
  <p>(unfortunately <code>-pattern_type glob -i '*.png'</code> doesn't work on windows)</p>
  <p>But this seems to be doing something strange, as if treating the alpha as single bit:</p>
  <ul>
  <li>Where the alpha is 1, the output pixels are from my input image (correct and nice).</li>
  <li>Where the alpha is 0, the output pixels in the video is black (correct and nice).</li>
  <li>But anywhere in between, it's as if it's ignoring the alpha for those pixels.</li>
  </ul>
  <p>My alpha is straight (not premultiplied), and I'd like the output to be as if I'd overlaid the images with non-premultiplied alpha on black.</p>
  <p>See image below (from aftereffects. left: alpha, middle: desired output, right: ffmpeg output)</p>
  <p><a href="https://i.sstatic.net/z067L.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/z067L.jpg" alt="enter image description here" /></a></p>
  <p>(Note. Everything I've searched on this topic always comes up with &quot;how to preserve alpha in video&quot;. But that's not what I'm after).</p>
  
Tags: <ffmpeg><alpha>
Title: How to create a video WITHOUT alpha, from a png sequence WITH alpha using ffmpeg
UserDisplayName: memo
ThreadText: # How to create a video WITHOUT alpha, from a png sequence WITH alpha using ffmpeg
  
  (Asked by: username_0 on 2024-01-21)
  
  I have a sequence of pngs **with alpha**, and I'd like to encode to h264 **without alpha**, overlaid on black.
  
  My usual command for image sequence to h264 is
  
  `ffmpeg -r 30 -i 'template %05d.png' -c:v libx264 -pix_fmt yuv420p out.mp4`
  
  (unfortunately `-pattern_type glob -i '*.png'` doesn't work on windows)
  
  But this seems to be doing something strange, as if treating the alpha as single bit:
  
  * Where the alpha is 1, the output pixels are from my input image (correct and nice).
  * Where the alpha is 0, the output pixels in the video is black (correct and nice).
  * But anywhere in between, it's as if it's ignoring the alpha for those pixels.
  
  My alpha is straight (not premultiplied), and I'd like the output to be as if I'd overlaid the images with non-premultiplied alpha on black.
  
  See image below (from aftereffects. left: alpha, middle: desired output, right: ffmpeg output)
  
  [![enter image description here](https://i.sstatic.net/z067L.jpg)](https://i.sstatic.net/z067L.jpg)
  
  (Note. Everything I've searched on this topic always comes up with "how to preserve alpha in video". But that's not what I'm after).
  
  **Tags:** ffmpeg, alpha
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-01-22. Score: 1 | Accepted answer
  
  Use the overlay filter to composite the output image.
  
  `ffmpeg -framerate 30 -i 'template %05d.png' -vf "split=2[bg][img];[bg]format=yuv420p,drawbox=c=black:t=fill[bg];[bg][img]overlay=alpha=straight" -pix_fmt yuv420p -c:v libx264 out.mp4`
  
  > **Comments:**
  > **username_0**: That worked, Thank you!  
  
  ---
  
  