65.9K
CodeProject is changing. Read more.
Home

Copy a period of AVI chunks

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.89/5 (5 votes)

May 23, 2006

1 min read

viewsIcon

42861

downloadIcon

757

How to copy a period of AVI video by copying the chunk data.

Introduction

Generally, we have two mothods to copy a period of AVI video.

  • Use AVIStreamGetFrame and AVIStreamWriteData. The disadvantage of this method is it will cost a long time and generate a very big output file (uncompressed), especially when copying a long period.
  • Use EditStreamCopy and EditStreamPaste. This can give the user a chance to select an encoder, and use this encoder to compress the output file. Still, the output file is always more than 10 times the same period of the input file, and also this will cost a very long time.

How to Copy AVI Chunks

Basicly, the format of AVI files should like this:

RIFF                   RIFF HEADER
|-AVI                  AVI CHUNK  
  |-hdrl               MAIN AVI HEADER
  | |- ......          OTHER HEADER INFORMATION
  |-movi               MOVIE DATA
  | |-chunk1           chunk data
  | |- ......          chunk data
  | |-chunkn           chunk data
  |-idx1               AVI INDEX
    |-[index data]     DATA

So, we can copy the chunks of certain periods to the output file by the following steps:

  • Copy header.
  • Copy chunks.
  • Reconstruct index data.
  • Correct some data of the header, such as the file length and the data length.

Advantages and Disadvantages

This methed can run very fast, and the size of the output files corresponds to the input file. Still the disadvantages are obvious too. This class depends on the codec and may not work for some kinds of AVI files.

How to Use

The only code required to use this class is:
CCopyAVIChunk copier;
copier.CopyFile("C:\\tests\\test1.avi", "C:\\tests\\test2.avi", 123, 765);

Comments

I use this class for certain projects, so I only care if it can work with "those" kind of AVI files. Still I have no chance to test for general AVI files. If you are interested in this class and finds it can't work, please feel free to contact me at yinglong_w@hotmail.com.

Version History

  • Version 1.0 - posted May 23, 2006 to CodeProject.