How to generate a pure white background video with ffmpeg?

1

I want to create with ffmpeg a pure white video to use it as background. I mean a video that, played in a computer, you see as white. (In the examples I will pipe the output to ffplay so you don't need to delete the video later.)

To create a 3s 640x480 video (25 fps by default):

ffmpeg -f lavfi -i color=white:640x480:d=3 -f matroska - | ffplay -autoexit -

This is a small rectangle of the output against superuser page (which in my browser shows as white).

The first output against superuser page

Looking for an answer, I came to this question. The explanation is provided by Mulvya:

The padding is RGB 235, which is the upper limit in conventional video. So, a video player will expand 235 to show white. – Mulvya Oct 23 '15 at 17:44

But I found no player that show it as white. I tried with ffplay, MPC-HC and VLC both piping and creating an intermediate file.

With images as in the question, the solution seems to be adding the -format rgb32 option. But I get the same result with

ffmpeg -f lavfi -i color=white:640x480:d=3 -format rgb32 -f matroska - | ffplay -autoexit -

The -pixel_formatoption doesn't work either.

So... how do you create a pure white background video with ffmpeg?

cdlvcdlv

Posted 2016-12-07T12:00:44.480

Reputation: 703

1With your first command, I get pure white (#FF) as confirmed by Photoshop. I also get white when I output to a webm and play in Firefox. Try adding -color_range 1 just before -f matroska. Also, upgrade your ffmpeg, in case you're using an old version. – Gyan – 2016-12-07T12:30:54.190

My ffplay and ffmpeg are both N-81308-g369ed11, that I compiled in August. Maybe this issue has been corrected? -color_range 1 does not change anything. – cdlvcdlv – 2016-12-07T12:39:44.080

1What about ffplay -f lavfi -i color=white:640x480:d=3 – Gyan – 2016-12-07T12:47:22.100

Nada. Same thing. – cdlvcdlv – 2016-12-07T15:01:47.967

1Which OS is this? – Gyan – 2016-12-07T15:05:50.790

Windows XP x64, but the operation of ffmpeg should be the same, I think. I compiled it natively. – cdlvcdlv – 2016-12-07T15:23:56.813

1I'm also using a compiled version. Try it with the Zeranoe build, in any case. – Gyan – 2016-12-07T15:25:29.257

I'll need a W7 or later to try (Zeranoe's builds are XP incompatible since months). In the mean time, another ideas are welcome. – cdlvcdlv – 2016-12-07T15:37:15.733

1

Output to PNG. And try the builds here.

– Gyan – 2016-12-07T15:51:11.930

Indeed, these builds work in XP. Since they lack ffplay, I created an avi with ffmpeg -f lavfi -i color=white:640x480:d=3 -color_range 1 -format rgb32 -c:v huffyuv o.h.avi and played later, but the output keeps being 235/255. Generated PNG is real white, but I need a variable duration source video because my idea is adding some other inputs to the command and use several filters to add content on the background to generate the output video. But I never thought I wouldn't be able to give this first step. I thought it would be trivial. – cdlvcdlv – 2016-12-07T16:18:06.307

1It is trivial.Don't know why it's not working for you :( You can output to PNG in MOV to get a video e.g. ffmpeg -f lavfi -i color=white:640x480:d=3 -color_range 2 -c:v png video.mov – Gyan – 2016-12-07T16:31:06.583

1BTW, if the idea is to add content on top. You don't need to save the white canvas to file. Just feed it directly to filters. – Gyan – 2016-12-07T16:32:44.133

Exactly. My intention is not to save the white video (the 3 s duration is arbitrary, just to test), but to use it as a source background with some other content and generate a final x264 video all in one command. I didn't include the additional filters I intend to use just to isolate the problem. – cdlvcdlv – 2016-12-07T21:28:59.650

1What video card are you using? – Gyan – 2016-12-09T10:59:05.410

Nvidia GeForce FX 5200 Bios 4.34.20.80.02 – cdlvcdlv – 2016-12-09T18:30:41.373

1Ok, I remember in the Nvidia Control Panel, there being a 'Adjust video color setting'. Which if you allow Nvidia to control instead of the video player lets you set what the input range is. See what that says. – Gyan – 2016-12-09T19:02:39.760

I've been fiddling around with the controls of the NCP but I could see no difference in any player. I managed to test latest Zeranoe build in a W7 with the same results as XP. I think I'll do this thing with avisynth because I've found out several issues with my original command using ffmpeg. 1st, it seems you cannot set pixel_format in color source filter - it's always yuv420p. 2nd, ffplay always convert to color_range 1 (or 2 depending on the documentation).

– cdlvcdlv – 2016-12-12T19:11:33.367

To test, I created an avisynth script with the following line: BlankClip(length=75, width=640, height=480, fps=25, color=$FFFFFF, pixel_type="RGB24").KillAudio, "ffplayed" it and got grey (color_range does nothing here, no matter before -i or after it). Both MPC-HC and VLC (through AVFS) play it as white. So I think my source will be and .avs and will compress the final product with ffmpeg (being very careful and double-cheking).

– cdlvcdlv – 2016-12-12T19:12:57.690

1it seems you cannot set pixel_format in color source filter --> you add a format filter afterwards. -f lavfi -i color=white:640x480:d=3,format=rgb24 – Gyan – 2016-12-12T19:18:53.097

That did work! I found the format option but I thought I should use a colon, not a comma, as separator and got an error. You cannot use ffplay to check the result though; no matter the option you try, ffplay always shows grey. But I can use MPC-HC like this: ffmpeg -hide_banner -f lavfi -i color=white:640x480:d=3,format=rgb24 -c:v rawvideo -f nut - | mpc-hc.exe -. It's a valid answer to my question so, if you write it as answer, I'll accept it. – cdlvcdlv – 2016-12-13T18:36:40.047

Answers

2

As detailed in the comments, converting to a RGB format provides a full-range output.

-f lavfi -i color=white:640x480:d=3,format=rgb24

For other readers, I should note that I get a pure white display when running the OP's original command. I can't diagnose what's happening on OP's setup but there should be no special steps needed to generate a pure white output from ffmpeg other than color=white.

Gyan

Posted 2016-12-07T12:00:44.480

Reputation: 21 016