Viewing YUY2 video in IJ

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Viewing YUY2 video in IJ

Seth Pappas
Greetings,
I am currently using the Quicktime plugin to view live video from a USB camera.
The data coming out of the camera is in YUY2 format....sort of (two bytes per
pixel...but its a 12 bit camera output so we dropped the least 4 bits into the U
byte). Using the Quicktime Capture scheme to view video, the code translates
YUY2 into RGB.... and it is difficult to recover the U term.
Is there a way to view video directly as YUY2? I tried the VirtualDub approach
and IJ did not like it....was not able to open the AVI file.
Even if it did work, you have to view/capture/save the video in VirtualDub first
and then open IJ. I want to do it all in IJ.

Any insight would be much appreciated.

Thanks,

Seth Pappas


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Viewing YUY2 video in IJ

Michael Schmid
Hi Seth,

recent versions of ImageJ can open uncompressed YUV-based avi files with 12 bits/pixels (YV12, I420, NV12, NV21). If it is a different format, use ffmpeg to convert it to an YUY2-type format like NV12:

  ffmpeg -i infile.avi -pix_fmt nv12 -f avi -vcodec rawvideo outfile.avi

To get the the Y and U bytes, you can take the AVI_Reader from the ImageJ source and modify it to get an external plugin (replace 'package ij.plugin;' by 'import ij.plugin.*;'. Then modify writeRGBfromYUV in a suitable way, e.g.:
  int r=u, g=y, b=v;
the resulting image will have the raw u in the red channel, y in the green channel and v in the blue channel.

What does ImageJ say in debug mode when you open the file created by capturing with VirtualDub? (Edit>Options>Misc, 'debug' on)
Avoiding any conversion would be the cleanest way to access the original data.

---
By the way, the 12bit/pixel video files do not drop bits. Color information is stored only for blocks of 2x2 pixels. This gives you 4 bytes grayscale and 2 bytes color for each block of 4x4 pixels, i.e. 6 bytes for 4 pixels.

Michael
________________________________________________________________
On Jun 10, 2013, at 15:44, Seth Pappas wrote:

> Greetings,
> I am currently using the Quicktime plugin to view live video from a USB camera.
> The data coming out of the camera is in YUY2 format....sort of (two bytes per
> pixel...but its a 12 bit camera output so we dropped the least 4 bits into the U
> byte). Using the Quicktime Capture scheme to view video, the code translates
> YUY2 into RGB.... and it is difficult to recover the U term.
> Is there a way to view video directly as YUY2? I tried the VirtualDub approach
> and IJ did not like it....was not able to open the AVI file.
> Even if it did work, you have to view/capture/save the video in VirtualDub first
> and then open IJ. I want to do it all in IJ.
>
> Any insight would be much appreciated.
>
> Thanks,
>
> Seth Pappas

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Viewing YUY2 video in IJ

Seth Pappas
Michael,
Thanks for the information.
I see how the method you described would work...modify the avi reader....but
I was trying to avoid having to make an avi file outside of IJ. And since the Quicktime utility runs well: displays the live video and lets me store a still image, I wanted to try to do everything in IJ.

In an ideal situation, I could go into the Quicktime plugin and modify it to NOT convert the 8 bit data stream to RGB. Instead, I want it to display the stream as YUY2 and then capture a single frame in the same format...but since QT is a Directshow type of viewer, I am not sure if it is possible (even after reading your email....since I am not opening pre-existing avi files).

So the best thing for me would be to saved a single frame of the RGB image from the QT plugin and convert it during the save operation. I see the process as follows after performing steps 1 and 2:

1. Open the live video using file/import/video
2. Press the space bar to capture a single frame.
now:
3. Modify the existing save routinewhich would take the RGB and reconvert it into the format it came in as: YUY2. There are several documents that explain how to extract YUY2 data from the RGB info in addition to the example you mentioned, so I would try one of those equations.....I have been able to do it in MATLAB and although I don't think the 12 bit values are exactly what they should be, the final image that is rendered  is very good.

(might be a good time to mention that I have 0 Java experience...but I am a pretty good code hijacker and was hoping to just find some that I could modify).

Regarding the error message for reading the avi filer made by VirtualDub with AVI reader, it says An error occurred.....AVI file must be uncompressed.

I would completely understand if you wanted to terminate this email conversation....

Thanks,
Seth


 

 

 

-----Original Message-----
From: Michael Schmid <[hidden email]>
To: IMAGEJ <[hidden email]>
Sent: Mon, Jun 10, 2013 10:55 am
Subject: Re: Viewing YUY2 video in IJ


Hi Seth,

recent versions of ImageJ can open uncompressed YUV-based avi files with 12
bits/pixels (YV12, I420, NV12, NV21). If it is a different format, use ffmpeg to
convert it to an YUY2-type format like NV12:

  ffmpeg -i infile.avi -pix_fmt nv12 -f avi -vcodec rawvideo outfile.avi

To get the the Y and U bytes, you can take the AVI_Reader from the ImageJ source
and modify it to get an external plugin (replace 'package ij.plugin;' by 'import
ij.plugin.*;'. Then modify writeRGBfromYUV in a suitable way, e.g.:
  int r=u, g=y, b=v;
the resulting image will have the raw u in the red channel, y in the green
channel and v in the blue channel.

What does ImageJ say in debug mode when you open the file created by capturing
with VirtualDub? (Edit>Options>Misc, 'debug' on)
Avoiding any conversion would be the cleanest way to access the original data.

---
By the way, the 12bit/pixel video files do not drop bits. Color information is
stored only for blocks of 2x2 pixels. This gives you 4 bytes grayscale and 2
bytes color for each block of 4x4 pixels, i.e. 6 bytes for 4 pixels.

Michael
________________________________________________________________
On Jun 10, 2013, at 15:44, Seth Pappas wrote:

> Greetings,
> I am currently using the Quicktime plugin to view live video from a USB
camera.
> The data coming out of the camera is in YUY2 format....sort of (two bytes per
> pixel...but its a 12 bit camera output so we dropped the least 4 bits into the
U
> byte). Using the Quicktime Capture scheme to view video, the code translates
> YUY2 into RGB.... and it is difficult to recover the U term.
> Is there a way to view video directly as YUY2? I tried the VirtualDub approach

> and IJ did not like it....was not able to open the AVI file.
> Even if it did work, you have to view/capture/save the video in VirtualDub
first
> and then open IJ. I want to do it all in IJ.
>
> Any insight would be much appreciated.
>
> Thanks,
>
> Seth Pappas

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

 

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Viewing YUY2 video in IJ

Michael Schmid
Hi Seth,

if you want to try in the QuickTime_Capture.java plugin, you could have a look at the pixel formats.
You might try replacing QDGraphics.kDefaultPixelFormat or k32BGRAPixelFormat by something else like kYVYU422PixelFormat, see the constants in
  http://quicktimeforjava.zzl.org/quicktime/qd/QDConstants.html

But I can't say whether this works.

Michael
________________________________________________________________
On Jun 10, 2013, at 18:31, Seth Pappas wrote:

> Michael,
> Thanks for the information.
> I see how the method you described would work...modify the avi reader....but
> I was trying to avoid having to make an avi file outside of IJ. And since the Quicktime utility runs well: displays the live video and lets me store a still image, I wanted to try to do everything in IJ.
>
> In an ideal situation, I could go into the Quicktime plugin and modify it to NOT convert the 8 bit data stream to RGB. Instead, I want it to display the stream as YUY2 and then capture a single frame in the same format...but since QT is a Directshow type of viewer, I am not sure if it is possible (even after reading your email....since I am not opening pre-existing avi files).
>
> So the best thing for me would be to saved a single frame of the RGB image from the QT plugin and convert it during the save operation. I see the process as follows after performing steps 1 and 2:
>
> 1. Open the live video using file/import/video
> 2. Press the space bar to capture a single frame.
> now:
> 3. Modify the existing save routinewhich would take the RGB and reconvert it into the format it came in as: YUY2. There are several documents that explain how to extract YUY2 data from the RGB info in addition to the example you mentioned, so I would try one of those equations.....I have been able to do it in MATLAB and although I don't think the 12 bit values are exactly what they should be, the final image that is rendered  is very good.
>
> (might be a good time to mention that I have 0 Java experience...but I am a pretty good code hijacker and was hoping to just find some that I could modify).
>
> Regarding the error message for reading the avi filer made by VirtualDub with AVI reader, it says An error occurred.....AVI file must be uncompressed.
>
> I would completely understand if you wanted to terminate this email conversation....
>
> Thanks,
> Seth
>
>
>
>
>
>
>
>
> -----Original Message-----
> From: Michael Schmid <[hidden email]>
> To: IMAGEJ <[hidden email]>
> Sent: Mon, Jun 10, 2013 10:55 am
> Subject: Re: Viewing YUY2 video in IJ
>
>
> Hi Seth,
>
> recent versions of ImageJ can open uncompressed YUV-based avi files with 12
> bits/pixels (YV12, I420, NV12, NV21). If it is a different format, use ffmpeg to
> convert it to an YUY2-type format like NV12:
>
>  ffmpeg -i infile.avi -pix_fmt nv12 -f avi -vcodec rawvideo outfile.avi
>
> To get the the Y and U bytes, you can take the AVI_Reader from the ImageJ source
> and modify it to get an external plugin (replace 'package ij.plugin;' by 'import
> ij.plugin.*;'. Then modify writeRGBfromYUV in a suitable way, e.g.:
>  int r=u, g=y, b=v;
> the resulting image will have the raw u in the red channel, y in the green
> channel and v in the blue channel.
>
> What does ImageJ say in debug mode when you open the file created by capturing
> with VirtualDub? (Edit>Options>Misc, 'debug' on)
> Avoiding any conversion would be the cleanest way to access the original data.
>
> ---
> By the way, the 12bit/pixel video files do not drop bits. Color information is
> stored only for blocks of 2x2 pixels. This gives you 4 bytes grayscale and 2
> bytes color for each block of 4x4 pixels, i.e. 6 bytes for 4 pixels.
>
> Michael
> ________________________________________________________________
> On Jun 10, 2013, at 15:44, Seth Pappas wrote:
>
>> Greetings,
>> I am currently using the Quicktime plugin to view live video from a USB
> camera.
>> The data coming out of the camera is in YUY2 format....sort of (two bytes per
>> pixel...but its a 12 bit camera output so we dropped the least 4 bits into the
> U
>> byte). Using the Quicktime Capture scheme to view video, the code translates
>> YUY2 into RGB.... and it is difficult to recover the U term.
>> Is there a way to view video directly as YUY2? I tried the VirtualDub approach
>
>> and IJ did not like it....was not able to open the AVI file.
>> Even if it did work, you have to view/capture/save the video in VirtualDub
> first
>> and then open IJ. I want to do it all in IJ.
>>
>> Any insight would be much appreciated.
>>
>> Thanks,
>>
>> Seth Pappas
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html