Log in

View Full Version : AVIStreamWrite() writes all keyframes - avisynth related?


temporance
25th February 2004, 21:16
Mysterious problem this. I'm playing with a very simple commandline C++ application to transcode video from one AVI to another. When transcoding from one AVI to another AVI it works perfectly. However, when transcoding from an avisynth source to AVI, all the frames in the destination AVI are set as keyframes (only the first frame is actually encoded by ICCompress() with AVIIF_KEYFRAME set). I can't think why this should happen.

Can any of the developers think why this would only happen with an avisynth source? Is the Windoze avifile library buggy?

TIA :)


Rather than paste the whole source here, these are the API calls I'm using:

AVIFileInit

Opening source AVI:
AVIFileOpen
AVIFileGetStream
AVIStreamReadFormat
AVIStreamLength
AVIStreamInfo
AVIStreamGetFrameOpen

Opening Dest AVI:
AVIFileOpen
ICCompressGetFormat
AVIStreamSetFormat
ICCompressBegin

Frame loop:
AVIStreamRead
ICDecompress
ICCompress
AVIStreamWrite

Closing Dest:
ICCompressEnd
ICClose
AVIStreamRelease
AVIFileRelease

Closing Source:
AVIStreamGetFrameClose
ICDecompressEnd
AVIStreamRelease
AVIFileExit

Bidoche
25th February 2004, 22:14
Avisynth handles data uncompressed internally, so all frames are keyframes, it's normal.

esby
26th February 2004, 01:56
As bidoche said,
Avisynth decompresses frames and handle them to the application via avifile...
Even if we modify avisynth to not decode it,
that will mean that no filters are allowed,
except a few ones like trim and splice...

I'll be curious to look on your comand line tool :)

esby

temporance
26th February 2004, 10:05
I found the problem: if the sample size is specified when calling AVIStreamSetFormat(), then the AVI writer assumes that all frames are keyframes, even if they are not flagged as such. Arghh!

My app is pretty simple, if I get it to work well I'll publish it somewhere. On the other hand it's so simple that surely someone must have done it before???

usage: transcode.exe FourCC infile.avi outfile.avi

e.g. transcode xvid source.avs dest.avi

Si
26th February 2004, 18:21
What do you mean by "transcoding" ?

The current popular use of such a term is in MPEG-2 transcoding where I believe the MPEG-2 picture data is reduced in size in order to get DVD-9's onto a DVD-5.

Are you attempting something like this with MPEG-4 or are you just writing a video decompressor/compressor?

As Bidoche says Avisynth decompresses every frame, so if keyframe == a decompressed frame then all frames are keyframes.

regards
Simon

mf
26th February 2004, 19:10
Transcoding = writing from one format to another. You can transcode an MP4 to AVI without recoding the compressed data, but you can also transcode XviD to DivX going from AVI to AVI (in this case recoding the compressed data). It's a pretty general term.