Log in

View Full Version : Can jpegs be in YUY2 Format?


tateu
8th October 2005, 00:09
I am writing an OMF import (and hopefully, one day, export) filter for Avisynth. The uncompressed OMFs I am working with are in CCIR601 (16-235 range) YUY2 format with each field written sequentially in the file. I have no trouble reading these files. I create a YUY2 PVideoframe and copy the OMF data directly to it. When I open a script with an uncompressed OMF file in VirtualDub, the levels are correctly expanded back out to 0-255.

The compressed OMFs I have are sequential fields of jpeg data, 16-235 range, but I'm not sure if they are RGB or YUY2. It looks like they are probably RGB, though. If I use a hex editor to copy one field of data to a new file I end up with a 720x248 jpg that can be opened by any program capable of reading jpegs. The file properties list it as 24-bit RGB. My current method of reading this data into Avisynth is to copy the jpeg data for 2 fields into memory and then I use an image library (CxImage) to convert it to uncompressed RGB data which I then copy to a new RGB PVideoframe. I probably should have used DevIL since it is already used in Avisynth but we just bought an AVID at work and I needed to get a working import filter done quickly. I was already familiar with the interface to CxImage so it was easier for me to get done fast.

There are two problems with my current method for compressed OMFs:
1) If the jpeg data is originally in YUY2 format, I'd like to skip the step of converting it to RGB with the image library.
2) When I convert the jpeg data to uncompressed RGB, it still only has a luminance range of 16-235. When I load compressed OMFs into After FX, it expands them back out to a range of 0-255. As a fix, I took the code from Avisynth's Levels.cpp and modified it to work on a PVideoframe instead of a PClip and I use that to expand the levels back to 0-255 before I send the PVideoframe back to Avisynth.

It seems that I have probably answered my own question by looking at the jpeg properties of one of the fields. I just wanted to check and see if anyone knew for sure or had any suggestions for.

IanB
8th October 2005, 03:03
I think you are confusing what format your library decodes the image to, with the fundamental way the technology hold the image.

You should not think in terms of YUY2 but rather think of a YUV colour space with 2:1 horizontal chroma subsampling. In the AVS 2.6 development we have a new YV16 format which has the same information content as YUY2 but the memory layout is planar (each channel is in its own contiguous block of memory) rather than interleaved (channels sequentially stored in memory).

You can chose a decompression library that returns data in the format your current application needs for maximum convienience. Or chose one that returns data in a format without any levels processing or chroma upscaling to give you the most control. Control can be very important where interlaced images are concerned.

For example, QuickTime Sorenson, don't think a library that returns [0..255] RGB24 format is "better" than a library that return [16..235] YUV9 format. Sorenson is fundamentally [16..235] YUV colour space with 411 chroma subsampling, i.e. YUV9.

IanB