Color settings for Hamoid Video Export library (FFMPEG)

Hello all,

I’m using the Hamoid Video Export library. It uses FFMPEG to export a video directly from Processing. I now have the problem that the colours don’t match up. It understand this has probably more to do with FFMPEG than Processing, but I hope someone here can help me.

This is a comparison (left is processing, right is a MP4 rendered from the same sketch):

Now, reading the docs on Github it says you can change the JSON settings file in the library. But whatever I try I just make it stop rendering videos completely. Googling what settings to use doesn’t help me since I understand absolutely reading it. So, is there anyone who can shed some light on this?

These are the (default) settings I’m using:

"encode_video": [
    "[ffmpeg]",
    "-y",
    "-f",
    "rawvideo",
    "-vcodec",
    "rawvideo",
    "-s",
    "[width]x[height]",
    "-pix_fmt",
    "rgb24",
    "-r",
    "[fps]",
    "-i",
    "-",
    "-an",
    "-vcodec",
    "h264",
    "-pix_fmt",
    "yuv420p",
    "-crf",
    "[crf]",
    "-metadata",
    "comment=[comment]",
    "[output]"
  ],

Thanks!

Hi! What happens if you replace yuv420p with rgb24? I haven’t tried…

You can see the available formats with ffmpeg -pix_fmts. I think you need one with the letter O in the column (for output).

Here something related: https://forum.videohelp.com/threads/380610-Change-in-color-while-reencoding-with-ffmpeg
There are so many options in ffmpeg that it’s not simple to figure out the right ones.

Which video player did you use? Did you try with VLC?

Hey Hamoid,

Thanks for replying! The library itself works really good, thanks for that!

The rgb24 is the first thing I tried. I first thought it didn’t work anymore, since I couldnt quick-view the mp4’s in finder anymore, but they are playing in VLC. Although with the same colour change. I tried some of the different formats shown with -pix_fmts, but they give me the same color.

Left is the PDF generated, right the MP4 with rgb24 (in VLC):

You’re welcome! :slight_smile:

Does this help?

Sounds like it should help a lot. But I don’t really get how the json with settings translates to the final ffmpeg function. Like, can I just add/remove settings? How would I go about this?

{
  "encode_video": [
    "[ffmpeg]",
    "-y",
    "-f",
    "rawvideo",
    "-vcodec",
    "rawvideo",
    "-s",
    "[width]x[height]",
    "-pix_fmt",
    "rgb24",
    "-r",
    "[fps]",
    "-i",
    "-",
    "-an",
    "-vcodec",
    "h264",
    "-pix_fmt",
    "yuv420p",
    "-crf",
    "[crf]",
    "-metadata",
    "comment=[comment]",
    "[output]"
  ],
  "encode_audio": [
    "[ffmpeg]",
    "-y",
    "-i",
    "[inputvideo]",
    "-i",
    "[inputaudio]",
    "-filter_complex",
    "[1:0]apad",
    "-shortest",
    "-vcodec",
    "copy",
    "-acodec",
    "aac",
    "-b:a",
    "[bitrate]k",
    "-metadata",
    "comment=[comment]",
    "-strict",
    "-2",
    "[output]"
  ],
  "ffmpeg_path": "/usr/bin/ffmpeg"
}

It’s very simple actually. The json, if you look at the encode_video part, is just an array of strings. It will be concatenated with spaces.

The parts in square brackets are replaced by variables by the library (the path of the executable, width, height, fps, the crf quality, a comment and the output file path).

Everything else is passed as it is. You can completely change it any way you want: add, remove and change the order of the strings.

If I remember right you should be able to see the command that is executed in the debug txt file that is produced.

Update: actually the command is not written to the debug txt file, but it would be useful if it was! :slight_smile:

1 Like

Hey,

Thanks for the explanation. Clear on how to change the settings then. Still not getting the right colours (always the same washed magenta), but I at least know how to play around with the settings.

Tried a couple of suggestions of the previous link you sent as well, but no luck yet.

For now I will just render to separate frames and combine them in another app. Thanks again!

Something to try: run

$ ffmpeg -i videoA.mp4
$ ffmpeg -i videoB.mp4

videoA.mp4 has the washed out colors, videoB.mp4 created with your other program, and see if you notice some differences in the output. Maybe you discover something?

On the meaning of “420”:

I think I found the solution:

"-vcodec",
"libx264rgb",

That gives me the exact same hue. I’ve been told the video will not play back on every platform though.

Hey Hamoid,

Changing the codec works for me too! Bit of a shame though, because for most uses you’ll need h264 anyway.
I noticed the same color fade occurs when I take the ‘correct’ generated libx264rgb movie and put it through handbrake to convert it back to h264. That at least shows the problem is in the codec, not the colorspace, right?

would playing around with the saturation, brightness and contrast in FFmpeg filters help at all. I found some of my videos a little washed out at times so used filters like this…

[
“[ffmpeg]”,
“-y”,
“-f”,
“rawvideo”,
“-vcodec”,
“rawvideo”,
“-s”,
“[width]x[height]”,
“-pix_fmt”,
“rgb24”,
“-r”,
“[fps]”,
“-i”,
“-”,
“-vf”,
“eq=saturation=1.2:brightness=1.0:contrast=2.0”,
“-an”,
“-vcodec”,
“h264”,
“-pix_fmt”,
“yuv420p”,
“-crf”,
“[crf]”,
“-metadata”,
“comment=[comment]”,
“[output]”
]

1 Like

Hey poboyd,

That is actually pretty smart, never thought about that. I notice bumping the saturation a bit is quite helpful! I still can’t exactly match the magenta, and changing brightness/contrast will mess with my black and white. But the script has 4 colours and they all look pretty good right now! Thanks so much, both of you!

1 Like

Hi there,
I have the same Problem. Dull, washed out colors. However I am super new to Processing, so I have no idea where to even change the FFmpeg filters?

Could you elaborate a bit where I find the setting and where to enter what? So sorry, I am just a bit lost here :slight_smile:

Thanks alot!