JuliaIO / VideoIO.jl

Reading and writing of video files in Julia via ffmpeg
https://juliaio.github.io/VideoIO.jl/stable
Other
126 stars 53 forks source link

Something wrong with converting rgb to yuv for color videos #284

Closed galenlynch closed 3 years ago

galenlynch commented 3 years ago

I was following up on #283 and noticed that there is something wrong about how VideoIO takes a RGB image and converts it into a YUV420 image. I have noticed that the colors in my own videos look terribly washed out, and chalked it up to chroma downsampling. However, comparing the output of VideoIO to a similarly downsampled video produced by the ffmpeg binary suggests there are other errors in how color is being converted.

Here is a (torture) test 100x100 RGB{N0f8} image that I used for both VideoIO and ffmpeg, saved as a PNG with FileIO:

test

(Note that it looks a bit blurry because I resized it in the html of this post)

Here is the same frame after encoding into h264 (crf=0), yuv444p pixel format, with the ffmpeg binary:

ffmpeg_444

I think this is nearly pixel perfect.

Here is the frame with yuv420p pixel format, also ffmpeg binary:

ffmpeg_420

chroma downsampling has taken its toll, but the hues are still there.

Here is the frame with yuv420p pixel format, but encoded with VideoIO (crf=0, master):

ffmpeg_420

There seems to be something wrong with the chroma particularly near the edges, e.g. the top edge. Perhaps we are using a different chroma sub-sampling strategy.

Once again, for comparison, here is the original:

test
galenlynch commented 3 years ago

This seems to be fixed by some of the changes that I made to #279, which looks better for both yuv420p and also yuv444p. In that PR I have allowed VideoIO to encode in more than just yuv420p.

galenlynch commented 3 years ago

Here is the behavior of VideoIO in #279:

Reference (target) frame:

reference

VideoIO output with yuv444p encoding:

videoio_444

VideoIO output with yuv420p encoding:

videoio_420

If you compare this to the VideoIO output in the post above, you'll find the colors are much improved.