when using ffmpeg to merge pngs to mp4, transparent background becomes green unexpectedly

Viewed 621

Command:

./ffmpeg -i ./img/%3d.png  -pix_fmt yuv420p  -vcodec libx264 -profile:v main -level 4.0 -bf 0  -bufsize 2000k -y ./raw.mp4

Here is my input and output

-- input: http://106.15.63.56/image/greenbackground.zip
-- output:http://106.15.63.56/image/green_output.mp4

I tried in Linux and macOS; the result is the same.

1 Answers

The color channels of the PNG contain the background color that you see in the MP4 since the video codec H.264 does not support alpha.

To set a background color of your choice, use

./ffmpeg -i ./img/%3d.png -vf "split=2[clr][bg];[bg]drawbox=c=black:t=fill[bg];[bg][clr]overlay" -pix_fmt yuv420p -c:v libx264 -profile:v main -level 4.0 -bf 0 -bufsize 2000k -y ./raw.mp4

Change the drawbox color to one you prefer.

Related