1
votes

I am using the AVIFile Reference API(https://msdn.microsoft.com/en-us/library/windows/desktop/dd756808(v=vs.85).aspx) to, create an AVI video output file. While, adding the frames to the video file, I would like to check the size of the file, that was created till now and if it exceeds more than certain size limit (say 1GB), I would like to stop adding the frames to the file and close the AVI File and exit.

I am using the below code:

      LONG lnSize=0;
      PAVISTREAM ppavi=NULL;
      AVIFileGetStream(pfile,&ppavi,mmioFOURCC('M', 'S', 'V', 'C'),1);
      AVIStreamDataSize(ppavi,mmioFOURCC('M', 'S', 'V', 'C'),&lnSize);

The AVIFileGetStream is returning null value into ppavi pointer. Hence, it is crashing at the call to AVIStreamDataSize.

Is, my approach to retrieve the size of the AVI file correct while the AVI file is in the process of creation? If so, what I should correct in the code to get the correct size of the AVI file? Otherwise, please let me know what is the correct way to retrieve the same?

Thanks in Advance.

1

1 Answers

1
votes

Your file size checking is approximate anyway: when you finish the file, some [indexing] data is attached for the file to be at all playable and you don't know the size in advance.

You might possibly be able to open a second handle to the file sharing access with the API and seeking to the end of the file in order to query current size. However I would say that the easiest and yet powerful and accurate enough solution is simply to count the payload you are writing - cbData argument in respective AVIFileWriteData calls. This data attributes to the most of the effectively written data (99%?) and so the estimation is accurate enough.