Re: Converting YUY2 format video to AVI



On Feb 21, 3:50 pm, Paul <nos...@xxxxxxxxxx> wrote:
bharath_r wrote:
Hi,

I have a video capture card that captures videos in H.264 format. I am
using the api that comes with the card to decode the videos frame by
fram into YUV2 format and then using the video for windows library
functions to compress it into avi format. The compression works fine,
except that the resulting video has very poor color reproduction. Its
like watching a negative print. Can anyone help me in solving this?

Thanks
Bharath

So you know, somewhere along the way, that one of your assumptions
about the color model or pixel mode, is wrong. Somehow, you need a
way to verify the content of the movie, through each stage of your
process.

Could you start, by converting VGZ to uncompressed format. So at least
the data would be easier to examine ? Then go from uncompressed to AVI
and check the color output again.

And for the movie, stick a static image in front of the camera, with
standard colors of some sort on the target. Sort of like this
(just the concept, not the whole chart). You need some way to verify
the transformation of the data, stage by stage.

http://en.wikipedia.org/wiki/SMPTE_color_bars

    Paul

Hi Paul,

One thing I am certain about is that the decoding works fine. Since i
am displaying each decoded frame i can tell you that the resulting
YUY2 frame has no color reproduction problem. The problem is while
compressing to avi. But i am not able to find what setting is causing
the problem. I am very new to this and i'm not able to figure out what
is wrong. Here is the code what i am doing

#define YUY2 mmioFOURCC('Y','U','Y','2')
#define XVID mmioFOURCC('X','V','I','D')

hicc = ICOpen(ICTYPE_VIDEO, XVID, ICMODE_COMPRESS);

// Get width and height of YUV source image
Width = 320;
Height = 240;

// Set the capture's YUV format
pYUVFmt = (LPBITMAPINFOHEADER)malloc(sizeof(BITMAPINFOHEADER));
memset(pYUVFmt, 0, sizeof(BITMAPINFOHEADER));
pYUVFmt->biSize = sizeof( BITMAPINFOHEADER);
pYUVFmt->biWidth = Width;
pYUVFmt->biHeight = Height;
pYUVFmt->biPlanes = 1;
pYUVFmt->biBitCount = 24;
pYUVFmt->biCompression = YUY2;

lFmtLength = ICCompressGetFormat(hicc, pYUVFmt, NULL);
pXVIDFmt = (LPBITMAPINFOHEADER)malloc(abs(lFmtLength));
ICCompressGetFormat(hicc, pYUVFmt, pXVIDFmt);

// Init AVIFile functions
AVIFileInit();

// Delete the previously captured file
OpenFile("c:\\capture.avi", &of, OF_DELETE);

// Create and open the the capture file
AVIFileOpen(&pfile, "c:\\capture.avi", OF_CREATE | OF_WRITE |
OF_SHARE_DENY_NONE, NULL);

// Set the AVI stream information
sivideo.fccType = streamtypeVIDEO;
sivideo.fccHandler = XVID;
sivideo.dwFlags = 0;
sivideo.dwCaps = 0;
sivideo.wPriority = 0;
sivideo.wLanguage = 0;
if ((iStandard == PAL_STANDARD) ||
(iStandard == SECAM_STANDARD))
{
// PAL/SECAM 25 fps
sivideo.dwScale = 1;
sivideo.dwRate = 25;
}
else
{
// NTSC 29.97 fps
sivideo.dwScale = 1001;
sivideo.dwRate = 30000;
}
sivideo.dwStart = 0;
sivideo.dwLength = 0;
sivideo.dwInitialFrames = 0;
sivideo.dwSuggestedBufferSize = 0;
sivideo.dwQuality = (DWORD)-1;
sivideo.dwSampleSize = 0;
sivideo.rcFrame.left = 0;
sivideo.rcFrame.top = 0;
sivideo.rcFrame.right = 0;
sivideo.rcFrame.bottom = 0;
sivideo.dwEditCount = 0;
sivideo.dwFormatChangeCount = 0;
sivideo.szName[0] = 0;

// Create the AVI stream
AVIFileCreateStream(pfile, &pavivideo, &sivideo);

// Set the XVID format in the AVI stream
AVIStreamSetFormat(pavivideo, 0, pXVIDFmt, lFmtLength);

// Get the current frame index in the AVI stream (0)
lIndex = AVIStreamLength(pavivideo);

// Allocate the XVID compressed data buffer
pXVIDBuffer = malloc(Width * Height * 2);


dwNextIndexCount = 0;
dwPrevIndexCount = 0;

prevYUVBuff = NULL;
prevYUVFmt = NULL;

DWORD res = ICCompressBegin(hicc,pXVIDFmt,pYUVFmt);
if(res != ICERR_OK)
{
return;
}

ICCompress(hicc,
ICCOMPRESS_KEYFRAME,
pXVIDFmt,
pXVIDBuffer,
pYUVFmt,
buff,
&dwCkID,
&dwFlags,
lIndex,
0,
7500, // Quality * 100
prevYUVFmt,
prevYUVBuff);

// Save this compressed frame in the AVI stream
AVIStreamWrite(pavivideo,
lIndex++,
1,
pXVIDBuffer,
pXVIDFmt->biSizeImage,
AVIIF_KEYFRAME,
NULL,
NULL);

.



Relevant Pages

  • Re: Converting YUY2 format video to AVI
    ... using the api that comes with the card to decode the videos frame by ... functions to compress it into avi format. ... // Set the AVI stream information ... sivideo.fccHandler = XVID; ...
    (rec.video.desktop)
  • Re: Is it possible to downsample a MPEG frame?
    ... >to compress a single streams into different format and I also don't ... >want to decompress and compress the frame again. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: The Whole thinG with the shuTTle
    ... the basis of what a "space Frame" is in the ideas of what strength is ... spaceD & sizes adjustments in the ideas of what overall inters-DesiGn is in ... format "Rise of the Machines," is - in fact an obligatory Defining sYstem ... implications are in this afters format of existence as it unfolds in ...
    (sci.space.shuttle)
  • Re: DSLR question: Full-frame or cropped body?
    ... The next question is what do you like to shoot? ... A full frame format would be significantly better *if* these are ... MP) camera, that is 10x13. ...
    (alt.photography)
  • Re: "Help" is anything but
    ... newsgroup carried th ereferred article? ... inserting it in a text box or frame. ... Format the text container by using the options on the Drawing ... outlines - TC (Table of Contents Entry), TOC, ...
    (microsoft.public.word.newusers)