PDA

View Full Version : AVISynth reporting incorrect frame width/height


ryaowe
2nd January 2008, 19:14
I'm using AVISynth to resize short avi clips using the BilinearResize filter. My code is written in C++ and uses the Windows AVIStream API to read the avi clips through the avisynth scripts. The problem is that (seemingly at random), the BITMAPINFOHEADER returned by AVIStreamReadFormat has an invalid width and height.

Here is a snippet of my code (error checking removed for brevity, but I have double checked that no error codes are being returned):

AVIFileGetStream(pAVI, &pStream, streamtypeVIDEO, 0);
size_t formatSize = 0;
AVIStreamReadFormat(pStream, 0, NULL, &formatSize);
BITMAPINFOHEADEr *pBMI = (BITMAPINFOHEADER *)new char[formatSize];
AVIStreamReadFormat(pStream, 0, pBMI, &formatSize);
printf("%dx%d\n", pBMI->biWidth, pBMI->biHeight);

The avi files being read are raw YUY2 (16bpp) video at 24fps and 640x272

The AVISynth script is as follows:
AVISource("0000000005.avi")
BilinearResize(480, 360)

most of the time, everything works great and the width and height are reported as 480x360. But every once in a while, it will report them as 724x80.

I have a series of these small avi files that I have to process. I have three processes (not threads) going at the same time to work on them. All three processes are using avisynth (on separate avi files) at the same time.

When the problem happens, I can stop my program and look at the source avi file, and it all looks good. I can even reuse the avisynth script and it will work just fine. I can rerun my program and it will successfully process the problematic avi file the second time through. But if I have my program retry without exiting, it gets the same error each time for the same avi file.

I've used a bounds checker to make sure I'm not overflowing a buffer somewhere and stepping on avisynth - haven't been able to find anything like that so far.

The avi files are created by decoding an arbitrary piece of source content from whatever codec it's using into raw YUY2. Differing pieces of source content have the same problem, regardless of size or codec.

Also, I can remove the BilinearResize filter, so the avisynth script only consists of AVISource(...), and the problem still happens.

I know the problem could exist in my code, and I'm still looking there too, but I'm really hoping someone else has seen this and can help me out. My code is pretty simple, and I've added debug code to check the width and height as soon as AVIStreamReadFormat returns, so it doesn't seem like anything should have a chance to step on the buffer before then, since each process is only a single thread. The BITMAPINFOHEADER structure that is allocated before the second call to AVIStreamReadFormat is not NULL, so the allocation should be good.

IanB
2nd January 2008, 21:05
724x80 is the size of an error text output. Look at the output frame for one of the failing scripts.

ryaowe
4th January 2008, 22:30
The error is:
AVISource autodetect: couldn't open file '0000000005.avi'
Error code: 32

Windows error 32 is: ERROR_SHARING_VIOLATION The process cannot access the file because it is being used by another process

I'm not sure how to fix it yet, but at least I know what the problem is now. Thanks IanB!

IanB
5th January 2008, 02:33
Check your virus scanner! You may have to exempt the directories you are working in.

sh0dan
6th January 2008, 02:19
[Moved to development section]
It could also be locked by explorer.exe, attempting to create a preview.

tebasuna51
6th January 2008, 10:50
It could also be locked by explorer.exe, attempting to create a preview.

Yep, I always disable the preview feature of Windows Explorer (don't work fine with Xvid avi's) with:
regsvr32 /u shmedia.dll