egarcia8484
May 29th, 2006, 12:07 PM
Hi folks,
I have an avi file (e.g. myTake.avi). The images are compressed with the MJPG codec. Now suppose I wan't to create another avi file that contains a "portion" of the original... I can think of a number of ways of achiving it, however, I don't want to "recompress" or "decompress" the images. What I wan't is just to "copy" and "paste" a number of contiguous frames.
Here goes my solution... I would like another one, since this code "recompress" the images (e.g. decompress and then compress with a given codec).....
Thanks in advance :wave:
int _stdcall ExtractSectionFromAvi(char * strAviFileSource, char * strAviFileDest, long start, long length)
{
int res;
PAVIFILE pAviFileSource = NULL;
PAVIFILE pAviFileDest = NULL;
PAVISTREAM pAviStream = NULL;
PAVISTREAM pEditableStream = NULL;
AVICOMPRESSOPTIONS aco;
AVISTREAMINFO si;
LONG _lStart, _lLength;
AVIFileInit();
res = AVIFileOpen(&pAviFileSource, strAviFileSource, OF_READ, NULL);
if (res != AVIERR_OK)
goto CleanUp;
res = AVIFileGetStream(pAviFileSource, &pAviStream, streamtypeVIDEO /*video stream*/, 0 /*first stream*/);
if (res != AVIERR_OK)
goto CleanUp;
res = AVIStreamInfo(pAviStream, &si, sizeof(AVISTREAMINFO));
if (res != AVIERR_OK)
goto CleanUp;
res = CreateEditableStream(&pEditableStream, NULL);
if (res != AVIERR_OK)
goto CleanUp;
_lStart = 0;
res = EditStreamPaste(pEditableStream, &_lStart, &_lLength, pAviStream, start, length);
if (res != AVIERR_OK)
goto CleanUp;
ZeroMemory(&aco, sizeof(AVICOMPRESSOPTIONS));
aco.fccType = si.fccType;
aco.fccHandler = si.fccHandler;
aco.dwKeyFrameEvery = 1;
aco.dwQuality = si.dwQuality;
res = AVISave(strAviFileDest, NULL, NULL, 1, pEditableStream, &aco);
if (res != AVIERR_OK)
goto CleanUp;
CleanUp:
/*
Releases and such
*/
return 0;
}
I have an avi file (e.g. myTake.avi). The images are compressed with the MJPG codec. Now suppose I wan't to create another avi file that contains a "portion" of the original... I can think of a number of ways of achiving it, however, I don't want to "recompress" or "decompress" the images. What I wan't is just to "copy" and "paste" a number of contiguous frames.
Here goes my solution... I would like another one, since this code "recompress" the images (e.g. decompress and then compress with a given codec).....
Thanks in advance :wave:
int _stdcall ExtractSectionFromAvi(char * strAviFileSource, char * strAviFileDest, long start, long length)
{
int res;
PAVIFILE pAviFileSource = NULL;
PAVIFILE pAviFileDest = NULL;
PAVISTREAM pAviStream = NULL;
PAVISTREAM pEditableStream = NULL;
AVICOMPRESSOPTIONS aco;
AVISTREAMINFO si;
LONG _lStart, _lLength;
AVIFileInit();
res = AVIFileOpen(&pAviFileSource, strAviFileSource, OF_READ, NULL);
if (res != AVIERR_OK)
goto CleanUp;
res = AVIFileGetStream(pAviFileSource, &pAviStream, streamtypeVIDEO /*video stream*/, 0 /*first stream*/);
if (res != AVIERR_OK)
goto CleanUp;
res = AVIStreamInfo(pAviStream, &si, sizeof(AVISTREAMINFO));
if (res != AVIERR_OK)
goto CleanUp;
res = CreateEditableStream(&pEditableStream, NULL);
if (res != AVIERR_OK)
goto CleanUp;
_lStart = 0;
res = EditStreamPaste(pEditableStream, &_lStart, &_lLength, pAviStream, start, length);
if (res != AVIERR_OK)
goto CleanUp;
ZeroMemory(&aco, sizeof(AVICOMPRESSOPTIONS));
aco.fccType = si.fccType;
aco.fccHandler = si.fccHandler;
aco.dwKeyFrameEvery = 1;
aco.dwQuality = si.dwQuality;
res = AVISave(strAviFileDest, NULL, NULL, 1, pEditableStream, &aco);
if (res != AVIERR_OK)
goto CleanUp;
CleanUp:
/*
Releases and such
*/
return 0;
}