How to generate a pure white background video with ffmpeg?
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
.
Related videos on Youtube
cdlvcdlv
Updated on September 18, 2022Comments
-
cdlvcdlv almost 2 years
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).
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 withffmpeg -f lavfi -i color=white:640x480:d=3 -format rgb32 -f matroska - | ffplay -autoexit -
The
-pixel_format
option doesn't work either.So... how do you create a pure white background video with ffmpeg?
-
Gyan over 7 yearsWith 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. -
cdlvcdlv over 7 yearsMy
ffplay
andffmpeg
are bothN-81308-g369ed11
, that I compiled in August. Maybe this issue has been corrected?-color_range 1
does not change anything. -
Gyan over 7 yearsWhat about
ffplay -f lavfi -i color=white:640x480:d=3
-
cdlvcdlv over 7 yearsNada. Same thing.
-
Gyan over 7 yearsWhich OS is this?
-
cdlvcdlv over 7 yearsWindows XP x64, but the operation of
ffmpeg
should be the same, I think. I compiled it natively. -
Gyan over 7 yearsI'm also using a compiled version. Try it with the Zeranoe build, in any case.
-
cdlvcdlv over 7 yearsI'll need a W7 or later to try (Zeranoe's builds are XP incompatible since months). In the mean time, another ideas are welcome.
-
Gyan over 7 yearsOutput to PNG. And try the builds here.
-
cdlvcdlv over 7 yearsIndeed, these builds work in XP. Since they lack
ffplay
, I created an avi withffmpeg -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. -
Gyan over 7 yearsIt 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 over 7 yearsBTW, 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.
-
cdlvcdlv over 7 yearsExactly. 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.
-
Gyan over 7 yearsWhat video card are you using?
-
cdlvcdlv over 7 yearsNvidia GeForce FX 5200 Bios 4.34.20.80.02
-
Gyan over 7 yearsOk, 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.
-
cdlvcdlv over 7 yearsI'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 setpixel_format
incolor
source filter - it's alwaysyuv420p
. 2nd,ffplay
always convert tocolor_range 1
(or2
depending on the documentation). -
cdlvcdlv over 7 yearsTo 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). -
Gyan over 7 yearsit 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
-
cdlvcdlv over 7 yearsThat 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.
-