Re: Converting YUY2 format video to AVI
- From: bharath_r <bharath.0523@xxxxxxxxx>
- Date: Thu, 21 Feb 2008 21:25:17 -0800 (PST)
On Feb 21, 7:37 pm, Paul <nos...@xxxxxxxxxx> wrote:
bharath_r wrote:
On Feb 21, 3:50 pm, Paul <nos...@xxxxxxxxxx> wrote:
bharath_r wrote:
Hi,So you know, somewhere along the way, that one of your assumptions
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
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);
In this example here, in the capture's YUV format, biBitCount is 16 for YUY2.
http://www.morgan-multimedia.com/download/codec.c
Two bytes to represent a pixel.http://wiki.multimedia.cx/index.php?title=YCbCr_4:2:2
Referenced from here.http://wiki.multimedia.cx/index.php?title=HFYU
And in this snippet.http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2847677&SiteID=1
Just a guess, because I'm not a software guy :-)
Paul- Hide quoted text -
- Show quoted text -
Thanks for all the help Paul
Yes, this thread is related to my streaming thread. The reason for
XviD is that i tried looking around how to convert YUY2 to wmv or asf
directly. But i din't find any api that can do that. So the alternate
was to convert the H.264 to avi using VFW library api and then using
Windows media encoder sdk to convert avi to wmv. I know its a little
crazy but we need a streamable format video. The card that i am using
is a IBP 1704 card manufactured by IBASE, Taiwan. The card captures
videos and stores them in their proprietary format (.vgz not .avi). Do
you know of a utility that can convert YUY2 to wmv? I looked at the
WME sdk but i din't find anything that will take one frame at a time
and compress it into wmv.
Regards
Bharath
.
- Follow-Ups:
- Re: Converting YUY2 format video to AVI
- From: Ken Maltby
- Re: Converting YUY2 format video to AVI
- References:
- Converting YUY2 format video to AVI
- From: bharath_r
- Re: Converting YUY2 format video to AVI
- From: Paul
- Re: Converting YUY2 format video to AVI
- From: bharath_r
- Re: Converting YUY2 format video to AVI
- From: Paul
- Converting YUY2 format video to AVI
- Prev by Date: Re: Media Player Classic freezes with XviD mpeg-4 (DX50) avi files
- Next by Date: Re: Vegas: delete audio and video together
- Previous by thread: Re: Converting YUY2 format video to AVI
- Next by thread: Re: Converting YUY2 format video to AVI
- Index(es):
Relevant Pages
|