mandm
23rd November 2002, 00:09
I'm trying to write a dual pass for M&M.
To load and save the paraemters I use (thank int21h):
void SaveCodecParams(const char* filename, COMPVARS* cvar)
{
LONG lStateSize = 0;
void* memState = NULL;
FILE* fileState = fopen(filename,"wb");
lStateSize = ICGetStateSize(cvar->hic);
memState = malloc(lStateSize);
if (ICGetState(cvar->hic, memState, lStateSize) < 0)
{
_RPTF0(_CRT_WARN,"\tSaveCodecParams\tError ICGetState\n");
return;
}
fwrite(&cvar->fccHandler, sizeof(cvar->fccHandler), 1, fileState);
fwrite(&cvar->lKey, sizeof(cvar->lKey), 1, fileState);
fwrite(&cvar->lQ, sizeof(cvar->lQ), 1, fileState);
fwrite(&cvar->lDataRate, sizeof(cvar->lDataRate), 1, fileState);
fwrite(&lStateSize, sizeof(lStateSize), 1, fileState);
fwrite(memState, lStateSize, 1, fileState);
free(memState);
fclose(fileState);
}
void LoadCodecParams(void)
{
int NbPassFile = 0;
FILE* fileState;
if ((fileState = fopen("M&M Avi 1.par", "r")) != NULL)
ReadCodecParam(fileState, pcompvars); // Read 1st pass codec state
else
ZeroMemory(pcompvars,sizeof(COMPVARS));
if ((fileState = fopen("M&M Avi 2.par", "r")) != NULL)
ReadCodecParam(fileState, pcompvars2); // Read 2st pass codec state
else
ZeroMemory(pcompvars2,sizeof(COMPVARS));
}
The files are created correctly and correctly read.
First point is:
why, after that I have saved and reloaded the data when I perform the:
ZeroMemory(&birgb, sizeof(BITMAPINFOHEADER));
birgb.biSize = sizeof(BITMAPINFOHEADER);
birgb.biWidth = Clip_Width;
birgb.biHeight = Clip_Height;
birgb.biPlanes = 1;
birgb.biBitCount = 24;
birgb.biCompression = BI_RGB;
birgb.biSizeImage = Clip_Width * Clip_Height * 3;
lpbirgb = &birgb;
memcpy_amd(pcvar,pcvar_s,sizeof(COMPVARS));
pcvar->cbSize = sizeof(COMPVARS);
if (ICCompressorChoose(hWnd, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW,
lpbirgb, NULL, pcvar, sZ2))
where pcvar is pcompvars for first pass and pcompvars2 for second pass the properties in the avi codec details is not correct ?
Second
We handle multiple files sequences.
the sequence is
open file 1
first pass
reset parameters
second pass
open file 2
etc...
now for the first file everithing is ok... first pass then second pass (only if I set the parameters not if I reload them from file)
but file 2 will do 2 times "second pass" this even if I switch correctly the parameters.
opts.cbFormat = sizeof(birgb);
opts.fccType = streamtypeVIDEO;
opts.fccHandler = ((do2pass && !is2pass) || (!do2pass)) ? compvars.fccHandler : compvars2.fccHandler;
opts.dwKeyFrameEvery = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lKey : compvars2.lKey;
opts.dwQuality = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lQ : compvars2.lQ;
opts.dwBytesPerSecond = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lDataRate<<10 : compvars2.lDataRate<<10;
opts.dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES | AVICOMPRESSF_DATARATE;
opts.dwInterleaveEvery = 0;
opts.lpFormat = lpbirgb;
opts.cbParms = ((do2pass && !is2pass) || (!do2pass)) ? compvars.cbState : compvars2.cbState ;
opts.lpParms = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lpState : compvars2.lpState ;
...
if (AVIFileOpen(&pfile, VideoOut, OF_WRITE | OF_CREATE, NULL) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
if (AVIFileCreateStream(pfile, &ps, &strinfo) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
if (AVIMakeCompressedStream(&psCompressed, ps, lpopts, NULL) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
Any help ?
Any idea ?
To load and save the paraemters I use (thank int21h):
void SaveCodecParams(const char* filename, COMPVARS* cvar)
{
LONG lStateSize = 0;
void* memState = NULL;
FILE* fileState = fopen(filename,"wb");
lStateSize = ICGetStateSize(cvar->hic);
memState = malloc(lStateSize);
if (ICGetState(cvar->hic, memState, lStateSize) < 0)
{
_RPTF0(_CRT_WARN,"\tSaveCodecParams\tError ICGetState\n");
return;
}
fwrite(&cvar->fccHandler, sizeof(cvar->fccHandler), 1, fileState);
fwrite(&cvar->lKey, sizeof(cvar->lKey), 1, fileState);
fwrite(&cvar->lQ, sizeof(cvar->lQ), 1, fileState);
fwrite(&cvar->lDataRate, sizeof(cvar->lDataRate), 1, fileState);
fwrite(&lStateSize, sizeof(lStateSize), 1, fileState);
fwrite(memState, lStateSize, 1, fileState);
free(memState);
fclose(fileState);
}
void LoadCodecParams(void)
{
int NbPassFile = 0;
FILE* fileState;
if ((fileState = fopen("M&M Avi 1.par", "r")) != NULL)
ReadCodecParam(fileState, pcompvars); // Read 1st pass codec state
else
ZeroMemory(pcompvars,sizeof(COMPVARS));
if ((fileState = fopen("M&M Avi 2.par", "r")) != NULL)
ReadCodecParam(fileState, pcompvars2); // Read 2st pass codec state
else
ZeroMemory(pcompvars2,sizeof(COMPVARS));
}
The files are created correctly and correctly read.
First point is:
why, after that I have saved and reloaded the data when I perform the:
ZeroMemory(&birgb, sizeof(BITMAPINFOHEADER));
birgb.biSize = sizeof(BITMAPINFOHEADER);
birgb.biWidth = Clip_Width;
birgb.biHeight = Clip_Height;
birgb.biPlanes = 1;
birgb.biBitCount = 24;
birgb.biCompression = BI_RGB;
birgb.biSizeImage = Clip_Width * Clip_Height * 3;
lpbirgb = &birgb;
memcpy_amd(pcvar,pcvar_s,sizeof(COMPVARS));
pcvar->cbSize = sizeof(COMPVARS);
if (ICCompressorChoose(hWnd, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW,
lpbirgb, NULL, pcvar, sZ2))
where pcvar is pcompvars for first pass and pcompvars2 for second pass the properties in the avi codec details is not correct ?
Second
We handle multiple files sequences.
the sequence is
open file 1
first pass
reset parameters
second pass
open file 2
etc...
now for the first file everithing is ok... first pass then second pass (only if I set the parameters not if I reload them from file)
but file 2 will do 2 times "second pass" this even if I switch correctly the parameters.
opts.cbFormat = sizeof(birgb);
opts.fccType = streamtypeVIDEO;
opts.fccHandler = ((do2pass && !is2pass) || (!do2pass)) ? compvars.fccHandler : compvars2.fccHandler;
opts.dwKeyFrameEvery = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lKey : compvars2.lKey;
opts.dwQuality = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lQ : compvars2.lQ;
opts.dwBytesPerSecond = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lDataRate<<10 : compvars2.lDataRate<<10;
opts.dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES | AVICOMPRESSF_DATARATE;
opts.dwInterleaveEvery = 0;
opts.lpFormat = lpbirgb;
opts.cbParms = ((do2pass && !is2pass) || (!do2pass)) ? compvars.cbState : compvars2.cbState ;
opts.lpParms = ((do2pass && !is2pass) || (!do2pass)) ? compvars.lpState : compvars2.lpState ;
...
if (AVIFileOpen(&pfile, VideoOut, OF_WRITE | OF_CREATE, NULL) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
if (AVIFileCreateStream(pfile, &ps, &strinfo) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
if (AVIMakeCompressedStream(&psCompressed, ps, lpopts, NULL) != AVIERR_OK)
{
AVIKill();
ThreadKill(1);
}
Any help ?
Any idea ?