I'm trying to convert an 8bit RGB uncompressed to an mpeg2 mxf file (xdcam 422 HD 1080 50i) which is YUV422. With info from the FFMpeg docs and various websites i made the following command:
./ffmpeg -y -i test_lines.mov -pix_fmt yuv422p -vcodec mpeg2video -non_linear_quant 1 -flags +ildct+ilme -top 1 -dc 10 -intra_vlc 1 -qmax 2 -vtag xd5c -rc_max_vbv_use 1 -rc_min_vbv_use 1 -g 12 -b:v 50000k -minrate 50000k -maxrate 50000k -bufsize 8000k -acodec pcm_s24le -ar 48000 -bf 2 -ac 2 lines_HD.mxf
This gave me a result with the colors much brighter than the original.
So i tried adding the options -color_range 1 -colorspace 1 -color_primaries 1 -color_trc 1
but this didn't seem to do anything.
After adding colormatrix=bt601:bt709
i got a way better image, but slightly darker than the original and it also feels weird specifying this option cause the source is also in the REC709 colorspace, so why specify it differently?
Next i regenerated my source image to an YUV codec (prores) and rerun FFMpeg on it with the colors coming out just fine. Therefore i think it has to be an RGB -> YUV problem. Does somebody have an idea how to this properly? I can provide screenshots of the different results on a videoscope as soon as i'm back at the office, if anybody is interested.
Last, i know there are various topics touching this subject but either they go way over my head FFmpeg wise or bring me to the stage where i already am.
Haven't see the images so don't know how much it is deviating but I hope you do realize going from RGB uncompressed to YUV422 uncompressed is irreversible and lossy. 422p implies subsampling of chroma component. Also going from uncompressed to MPEG2 is an additional quantization which is lossy even if your quant parameter is 2.
My suggestion encode to YUV422 y4m first. Ensure you are happy with that. Then change the output codec to mpeg2. That way your color conversion is first ensured to be accurate. Then MPEG2 will add its own loss on top of it.
Old but relevant thread: https://lists.ffmpeg.org/pipermail/ffmpeg-user/2012-July/007833.html
Forgot to mention you do have to add the colormatrix option. That is right. The above link should explain it all hopefully