Log in

View Full Version : yuy2 source - slightly darker encode


cdz
5th June 2012, 10:18
So, I'm still slightly new to the world of video encoding.
I've been trying to convert some raw yuy2 with x264, which results in a slightly darker output.
This is probably because I convert it to rgb24 before feeding it to x264. But what csp should I really use?

Using mencoder atm, with -vf format=rgb24, and x264 with --demuxer raw --input-csp rgb.
I'm using the 10bit version and output to i422, lossless

Results attached.
The system converted the images from png -- but the results are still visible.
First image is from the raw file.

Mencoder opts:

-nosound -ovc raw -of rawvideo -vf format=rgb32 -frames 1


x264 opts:

--preset placebo --crf 0 --input-res 1920x1080 --input-csp rgb --output-csp i422 --demuxer raw --verbose


Original file:

Video
ID : 0
Format : YUV
Codec ID : YUY2
Codec ID/Info : YUV 4:2:2 as for UYVY but with different component ordering within the u_int32 macropixel
Duration : 1s 0ms
Bit rate : 995 Mbps
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 30.000 fps
Color space : YUV
Chroma subsampling : 4:2:2
Compression mode : Lossless
Bits/(Pixel*Frame) : 16.000
Stream size : 119 MiB (100%)


Encoded file:

Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High 4:2:2@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 16 frames
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 25.000 fps
Color space : YUV
Chroma subsampling : 4:2:2
Bit depth : 10 bits
Scan type : Progressive
Writing library : x264 core 120
Encoding settings : cabac=1 / ref=16 / deblock=1:0:0 / analyse=0x3:0x133 / me=tesa / subme=11 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-2 / threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=16 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=60 / rc=crf / mbtree=1 / crf=0.0 / qcomp=0.60 / qpmin=0 / qpmax=81 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00


Thanks!

nm
5th June 2012, 16:34
Looks like a color matrix problem in one of the conversions.

Why do you convert to RGB instead of feeding the original YUY2 video to x264?

cdz
5th June 2012, 19:54
Looks like a color matrix problem in one of the conversions.

Why do you convert to RGB instead of feeding the original YUY2 video to x264?
Because any other combination will spawn a pipe into The Matrix, which yields a snapshot of Megacity - in code.

If I don't specify the --input-csp, I get

resize [warning]: converting from yuv420p to yuv422p


Tried ffmpeg:

ffmpeg -f rawvideo -pix_fmt yuv422p -frames 1
x264 --preset placebo --crf 0 --input-res 1920x1080 --input-csp i422 --output-csp i422

Yields the exact same result as in my initial post.

Basically it's just a guessing game of trying different csp...
It shouldn't matter if I'm on a virtual machine, right?

nm
5th June 2012, 22:12
Have you tried one of the alternatives that don't involve piping raw video to x264. Such as:

1. Give the source video file to x264 directly (there's a choice between different demuxers if needed).
2. Pipe from MPlayer's -vo yuv4mpeg
3. Use libx264 within MEncoder or FFmpeg.

None of these will require specifying input-csp and resolution.

Rumbah
5th June 2012, 23:12
As your videos show a game I guess that the raw wow yuy2 stream is full scale and the conversion to rgb doesn't take that into account. How to get mencoder to convert from full scale yuy2 to rgb I do not know.

nm
6th June 2012, 05:37
As your videos show a game I guess that the raw wow yuy2 stream is full scale

The difference in cdz's sample images doesn't come from full vs studio levels but probably from Rec.601 vs Rec.709 colors. Still, the conversion from YUY2 to RGB and back should be avoided completely.

cdz
9th June 2012, 15:15
[...]conversion[...]from YUY2 to RGB and back[...]avoided completely.
I suppose this is because of the chroma subsampling going wrong when converting back from RGB?


1. Give the source video file to x264 directly (there's a choice between different demuxers if needed).

THIS!

Kinda forgot about that option! Probably time to take a break from the computer..

resize [warning]: converting from yuyv422 to yuv422p

The result seems to be identical to the source!
Some images:

img01 (http://imageshack.us/photo/my-images/526/icrop32hdmi.png/)
Original, captured from an Avermedia C127

img02 (http://imageshack.us/photo/my-images/803/icrop32enci422.png/)
Encoded version

img03 (http://imageshack.us/photo/my-images/850/icrop32fraps.png/)
Fraps (lossless RGB), for comparison


Also, some upscaled images (4x res):
Original (http://imageshack.us/photo/my-images/543/i32scalehdmi.png/)
encoded (http://imageshack.us/photo/my-images/3/i32scaleenc.png/)
Fraps (http://imageshack.us/photo/my-images/525/i32scalefraps.png/)
Seems to be a lot more detail in the fraps version, as should (probably) be expeced.
Kind of makes me wanna drop the capture card.

turab
9th June 2012, 17:37
I suppose this is because of the chroma subsampling going wrong when converting back from RGB?

Not so much the chroma subsampling. If there's a tinge across the whole picture, it's due to the colourspace conversion.