Convert png sequence to x264 with ffmpeg

5

I am trying to convert a series of pngs into an mp4 video. I am using ffmpeg, and want to encode the video with the H.264 codec. Using the command

ffmpeg -y -r 30 -b 1800k -i _tmp%04d.png -vcodec libx264 out.mp4

I get the following warning message

Incompatible pixel format 'bgra' for codec 'libx264', auto-selecting format 'yuv420p'

My understanding is that there is an alpha channel in the pngs, which the x264 encoder cannot handle. Is there a way to get around this problem? Is there, for example, a way to get the encoder to ignore the alpha channel (my pngs don't actually have any transparent elements)?

I'm aware that I could batch convert the pngs beforehand to strip the alpha channel, but the sequence of images is produced by another program, and having to preprocess the images each time I make a video would be less than optimal.

Edit: After stripping the alpha channel from each frame using the command

convert in.png -background white -flatten +matte out.png

ffmpeg gives the warning message

Incompatible pixel format 'pal8' for codec 'libx264', auto-selecting format 'yuv420p'

so still no dice.

Thucydides411

Posted 2012-12-03T04:39:36.200

Reputation: 151

1The Incompatible pixel format is just a warning, not an error. Does your output actually work, or are there artifacts? Also, please include the full, uncut command line output from FFmpeg dor debugging purposes. // @Louis The OP wants x264, not H.264. – slhck – 2012-12-03T07:38:24.580

@slhck but x264 is a program not a codec. – Louis – 2012-12-03T07:45:23.697

Answers

0

I was thinking of using AVISynth and frame serving to get around the problem, but it looks like ffmpeg now has native support for AVISynth. Meaning you can use AVISynth scripts as input.

So with a script, sequence.avs, you could do:
ffmpeg -i sequence.avs -vcodec libx264 out.mp4

Where sequence.avs is:
ImageSource("_tmp%04d.png", start=0, end=1, fps=30).ConvertToYV12()

Note: The optional start and end parameters reflect that I tested with two images, _tmp0000.png and _tmp0001.png.

See also: More color formats. The ImageSource documentation.

Louis

Posted 2012-12-03T04:39:36.200

Reputation: 18 859