PDA

View Full Version : How does vfw store codec settings


R3g
22nd November 2002, 22:36
Well I just put my nose in all these vfw things, and I wonder how codec settings work.
I explain : when you call ICCompressorChoose and the user sets up his codec, you get a COMPVAR structure, which, I think, can't handle codec-specific settings.
So I suppose that vfw, or maybe the codec itself, stores these settings somewhere, and then retrieve it when it's time to encode ?

Does anybody have precision about how it works ?

mandm
23rd November 2002, 00:05
Thank to Int21h...

and if you search the ICGetStateSize in the MSDN help you'll find other samples


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));
}

mandm
23rd November 2002, 00:06
Thank to Int21h...

and if you search the ICGetStateSize in the MSDN help you'll find other samples


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));
}


M&M

[Toff]
23rd November 2002, 01:04
Originally posted by R3g
So I suppose that vfw, or maybe the codec itself, stores these settings somewhere, and then retrieve it when it's time to encode ?
Does anybody have precision about how it works ?

If you look into the COMPVARS struct you see the 2 interesting fields :
LPVOID lpState;
LONG cbState;

lpState is a pointer to the codec parameters struct.
Each codec has is own struct.

//---------------

In the codec there is :

typedef struct {
int : bitrate;
...
} mycodec_params_type;

mycodec_params_type codec_params;

// ----------------

In the application you could see :

compvar.lpState = &codec_params;
compvar.cbState = sizeof(mycodec_params);

So if you have the source of the codec, like for xvid you can easily retrieve parameters. (look at the CONFIG struct in config.h of the vfw xvid module)
But if the codec change, your application will be broken ...

R3g
23rd November 2002, 15:28
Ok, thanks, I misunderstood a couple of things before, it is much simplier than I thought.

mandm
25th November 2002, 12:14
Online there is the code (1.1 beta) that saves and reloads the plugin settings.

Only it looks like it does not work so well.


If you are able to work with save/load of dual pass plugins can you help me ?


M&M