How to generate a pure white background video with ffmpeg?

7,371

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.

Share:
7,371

Related videos on Youtube

cdlvcdlv
Author by

cdlvcdlv

Updated on September 18, 2022

Comments

  • cdlvcdlv
    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).

    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?

    • Gyan
      Gyan over 7 years
      With 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
      cdlvcdlv over 7 years
      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.
    • Gyan
      Gyan over 7 years
      What about ffplay -f lavfi -i color=white:640x480:d=3
    • cdlvcdlv
      cdlvcdlv over 7 years
      Nada. Same thing.
    • Gyan
      Gyan over 7 years
      Which OS is this?
    • cdlvcdlv
      cdlvcdlv over 7 years
      Windows XP x64, but the operation of ffmpeg should be the same, I think. I compiled it natively.
    • Gyan
      Gyan over 7 years
      I'm also using a compiled version. Try it with the Zeranoe build, in any case.
    • cdlvcdlv
      cdlvcdlv over 7 years
      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.
    • Gyan
      Gyan over 7 years
      Output to PNG. And try the builds here.
    • cdlvcdlv
      cdlvcdlv over 7 years
      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.
    • Gyan
      Gyan over 7 years
      It 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
      Gyan over 7 years
      BTW, 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
      cdlvcdlv over 7 years
      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.
    • Gyan
      Gyan over 7 years
      What video card are you using?
    • cdlvcdlv
      cdlvcdlv over 7 years
      Nvidia GeForce FX 5200 Bios 4.34.20.80.02
    • Gyan
      Gyan over 7 years
      Ok, 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
      cdlvcdlv over 7 years
      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
      cdlvcdlv over 7 years
      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).
    • Gyan
      Gyan over 7 years
      it 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
      cdlvcdlv over 7 years
      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.