What is AVI format and extracting AVI file information?

Source: Internet
Author: User

What is AVI format: http://www.shenmeshi.com/Recreation/Recreation_20080422141745.html

 

Http://www.shenmeshi.com/Recreation/Recreation_20080422141745_2.html

 

VC ++ AVI file operation: http://hi.baidu.com/6908270270/blog/item/1b087739a7c0bff53b87cec6.html

 

 

To read and write Avi, Microsoft provides a set of APIs with a total of 50 functions. They mainly use two types of Apis: AVI file operations and data stream streams operations.

1. Open and Close files

Avifileopen, avifileaddref, avifilereladdre

2. Read the file information from the file

Avifileinfo can be used to obtain information about the AVI file. This function returns an avifileinfo structure and avifilereaddata can be used to obtain information not obtained by the avifileinfo function. This information may not be contained in the file header, such as the name of the company or individual that owns the file.

3. Write File Information

You can use the avifilewritedata function to write some additional information about the file.

4. Open and Close a stream

Opening a data stream is the same as opening a file. You can use the avifilegetstream function to open a data stream. This function creates a stream interface and stores a handle in the interface.

If you want to operate a single stream of a file, you can use the avistreamopenfromfile function, which integrates avifileopen and avifilegetstream functions.

If you want to operate multiple data streams in the file, you must first avifileopen and then avifilegetstream.

You can use avistreamaddref to add stream interface references.

Use the avistreamrelease function to disable data streams. This function is used to reduce the reference count of streams. It is deleted when the count is reduced to 0.

5. Read data and information from the stream

The avistreaminfo function can obtain some information about the data. This function returns an avistreaminfo structure that contains the data type compression method, recommended buffersize, playback rate, and description.

If the data stream has additional information, you can use the avistreamreaddata function to obtain it. The application allocates a memory and passes it to this function. Then, this function returns the data stream information through the memory. The additional information may include the data stream compression and decompression methods, you can use the avistreamdatasize macro to return the size of the memory block to be applied.

You can use the avistreamreadformat function to obtain the format information of the data stream. This function returns the format information of the data stream through the specified memory. For example, for video streams, this buffer contains a bimapinfo structure. For audio streams, the memory block contains the waveformatex or pcmaveformat structure. You can obtain the buffer size by passing an empty buffer to avistreamreadformat. You can also use the avistreamformatsize macro.

You can use the avistreamread function to return multimedia data. This function copies data to the memory provided by the application. For video streams, this function returns the image watermark. For audio streams, this function returns the audio sample data. You can pass a null buffer to avistreamread to obtain the required buffer size. You can also use the avistreamsamplesize macro to obtain the buffer size.

Some Avi Data Stream handles may need to be prepared before starting the data stream. At this time, we can call the avistreambeginstreaming function to inform the Avi Data Stream handle to apply for allocating some resources it needs. Call the avistreamendstreamming function to release resources.

6. perform operations on compressed video data

If you want to demonstrate how many times a video image is compressed, you can call the avistreamread function to pass the obtained data to the drawdib function to display the image. These functions can display compressed and uncompressed images.

Avifile also provides the avistreamgetframeopen function to obtain uncompressed video streams. This function creates a memory to obtain uncompressed data. You can also use the avistreamgetframe function to extract a single video clip. This function can extract an image from a certain region and return the data in a bimapinfoheader structure. After calling the avistreamgetframe function, you must call the avistreamgetframeclose function to release the resources applied by the previous function.

7. Create a file based on an existing data stream

To create a file that contains multiple data streams, You can integrate multiple data streams and write them into a new file. These data streams can be stored in memory or in another file.

We can use the avisave function to build a file. This function can create a file and write multiple specified data streams to the file in the specified sequence. You can also use the avisavev function to create a new file, this function has the same function as avisave. The main difference is that avisavev uses an array of data streams, while avisave is a single data stream that is saved multiple times.

You can call the avisaveoptions function to display a dialog box that allows you to select the compression mode.

You can specify a callback function when calling the avisave and avisavev functions to display the progress of generating an AVI file. This allows you to cancel generating an AVI file at any time.

You can call the getsavefilenamepreview function to display the saved dialog box and select the saved file name.

Through the avimakefilefromstreams function, we can create a virtual file handle. Other Avi functions can use this virtual file handle to operate on the data stream in the file. After the operation is complete, remember to call avifilerelease for release.

8. Write a data stream to the file

You can use the avifilecreatestream function to create a data stream in a new file or an existing file. This function defines a new data stream based on the avistreaminfo structure and creates an interface for the new data stream to return the pointer to the interface.

Before writing new data, you must specify the stream format information. By using the avistreamsetformat function, you must use the bimapinfo structure to set a video stream, and use waveformat for audio.

Then we can write our multimedia data into the data stream through the avistreamwrite function. This function copies the memory data provided by the application to the specified stream. The default Avi handler writes data to the end of the stream.

If you have additional information to write to the stream, you can call avifilewritedata or avistreamwritedata. Remember to call avistreamrelease after data writing is completed.

9. The Shard location in the data stream

Start shard:

You can use the avistreamstart function to obtain the sample number contained in the First shard. You can also use the avistreaminfo function to obtain this information. The avistreaminfo structure of this function contains dwstart. You can use the avistreamstarttime macro to obtain the first sample.

You can use the avistreamlength function to obtain the stream length. This function returns the number of samples in the stream. You can also use the avistreaminfo function to obtain the information. You can use the avistreamlengthtime macro to obtain the stream length in milliseconds.

In a video stream, a sample corresponds to a sequence of images. Therefore, sometimes there is no video data in these samples. If you call the avistreamread function for data, null may be returned, you can also use avistreamfindsample to find the specified sample by specifying the find_any flag.

Search for key regions

Use the avistreamfindsample function to find the desired sample. Then, you can use the following macro to determine whether the critical samples are used.

Switch between time and sample.

Avistreamsampletotime: this function can convert smaple to milliseconds. For a video, this value indicates the start time of the player.


 

 

Avifileinfo source code download: http://www.pudn.com/downloads83/sourcecode/multimedia/vfw/detail319634.html

Http://www.pudn.com/downloads111/sourcecode/windows/file/detail463956.html

 

Codeproject: http://www.codeproject.com/KB/audio-video/ExtractAVIFrames.aspx

 

 

 

Video code: http://www.vckbase.com/code/listcode.asp? Mclsid = 7 & sclsid = 709 & page = 2

 

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.