AVI Video and Compression

Source: Internet
Author: User

# Include <windows. h>
# Include <VFW. h>
# Pragma comment (Lib, "vfw32.lib ")

Int main (INT argc, char * argv [])
{
Int m_imagewidth, m_imageheight;
Int frames = 1;
M_imagewidth = 100;
M_imageheight = 100;
Char buffer [100*100*4];
Memset (buffer, 1, sizeof (buffer ));

Avifileinit (); // Initialization

Pavifile;
Char filename [] = "A. Avi ";
Pavistream pvideostream;

If (avifileopen (& pavifile, filename, of_create | of_write, null ))
{
MessageBox (null, "avifileopen error", "error", mb_ OK );
Return 0;
}
 
Avistreaminfo avistreaminfow;
Memset (& avistreaminfow, 0, sizeof (avistreaminfow ));
Avistreaminfow. fcctype = streamtypevideo;
Avistreaminfow. dwrate = 1;
Avistreaminfow. dwscale = 1;
Avistreaminfow. dwsuggestedbuffersize = m_imageheight * m_imagewidth * 32;
Avistreaminfow. rcframe. Bottom = m_imageheight;
Avistreaminfow. rcframe. Right = m_imagewidth;
Strcpy (avistreaminfow. szname, filename );
 
Avifilecreatestream (pavifile, & pvideostream, & avistreaminfow );

 

Avicompressoptions options;
Avicompressoptions * aoptions [1] = {& options };
Memset (& options, 0, sizeof (options ));

// Avisaveoptions (null, 0, 1, & pvideostream, aoptions );
DWORD Params = 75;
// Char a [4];
// Memcpy (A, & options. fcchandler, 4 );
Options. fcctype = ictype_video;
Options. fcchandler = mmiofourcc ('I', 'V', '4', '1'); // mmiofourcc ('I', 'V', '4 ', '1 ');
Options. dwquality = 2000;
Options. dwflags = 8;
Options. lpparms = 0;
Options. cbparms = 0;

Pavistream pcompressedstream;
Avimakecompressedstream (& pcompressedstream, pvideostream, aoptions [0], null );

Bitmapinfoheader BMP infoheader;
Memset (& BMP infoheader, 0, sizeof (BMP infoheader ));
BMP infoheader. bisize = sizeof (BMP infoheader );
BMP infoheader. biheight = m_imageheight;
BMP infoheader. biwidth = m_imagewidth;
BMP infoheader. bibitcount = 32;
BMP infoheader. bicompression = bi_rgb;
BMP infoheader. biplanes = 1;

If (0! = Avistreamsetformat (pcompressedstream, 0, & BMP infoheader, sizeof (BMP infoheader )))
{
MessageBox (null, "setformat", "A; lsdkf", mb_ OK );
Return 0;
}
 
// Avistreamsetformat (pvideostream, 0, & BMP infoheader, sizeof (BMP infoheader ));
For (INT I = 0; I <1000; I ++)
{
// Avistreamwrite (pvideostream, frames * 5, 1, buffer, sizeof (buffer), aviif_keyframe, null, null );
Avistreamwrite (pcompressedstream, frames, 1, buffer, sizeof (buffer), aviif_keyframe, null, null );
Memset (buffer, I * 20 + 50, sizeof (buffer ));
Frames ++;
}
// Pcompressedstream-> release ();
If (pvideostream)
{
Pvideostream-> release ();
Pvideostream = NULL;
}
If (pavifile)
{
Avifileclose (pavifile );
Pavifile-> release ();
Pavifile = NULL;
}

Avifileexit (); // release the database
Return 0;
}

Options. fcchandler settings are closely related to the size of the video window. If the ratio is out of proportion, illegal access occurs when the format is set, or the size of the video file saved is 0, after debugging for a day, I found the problem. The fcchandler value can be set according to the fcchandler value obtained in avisaveoptions, and then converted into a 4-character array, which is easy to understand. Haha!

I still don't understand how icxx series functions compress videos

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.