Page 1 of 1

AVI recovery

Posted: Sat Apr 24, 2021 10:03 am
by albusmw
Hi,

I have an AVI file from another astronomer that crashed during the final save.
As I am a skilled programmer (haha ...), I could recover the basic frame offsets from a shorter file with a RIFF explorer and thus extract the frames (the header is complety 000000), but each 170 frames (with this camera and this resolution) there seem to be a jump in the index.

Is there any rule available from the SharpCap code how the chunk offsets are calculated in an AVI files?
Trial-and-error will give me a solution, but a formular would be better ...

Best regards

Martin.

Re: AVI recovery

Posted: Sat Apr 24, 2021 3:06 pm
by admin
Hi Martin,

SharpCap just gets Windows DirectShow to write AVI files for it, so any interesting features in the AVI data are down to Windows and unknown to me sadly.

However, I've played this game before and have some code I can share that looks for frame starts (assuming non zero data in the frame itself). Unfortunately the actual writing of the fixed AVI is using SharpCap internal code which I can't share, but I can share the code that reads the corrupt file and finds the frames.

Code: Select all

 class Program
    {
        static void Main(string[] args)
        {
            var src = File.OpenRead(args[0]);
            long frameStart = FindNextNonZero(src, 0) + 8;

            var width = 800;
            var height = 608;
            var colorPlanes = 3;

            var frameSize = width*height*colorPlanes;
            byte[] data = new byte[frameSize];

            int i = 0;

            while (frameStart + frameSize < src.Length)
            {
                src.Seek(frameStart, SeekOrigin.Begin);
                src.Read(data, 0, data.Length);

		// Write data to output AVI or image file

                frameStart += frameSize + 8;
                frameStart = FindNextNonZero(src,frameStart) + 8;
                Console.Write($@"Frame {++i}");
                Console.CursorLeft = 0;

            }

        }

        private static long FindNextNonZero(FileStream src, long i)
        {
            src.Seek(i, SeekOrigin.Begin);
            while (src.ReadByte() == 0)
            {
                i++;

            }

            return i;
        }
    }

Hope this helps,

Robin

Re: AVI recovery

Posted: Mon Apr 26, 2021 1:28 pm
by albusmw
Hi Robin,

thanks for your reply. I am doing something similar, so in the 1st run I extract all the images which you then go through and note the shifts that occure on some frames.
You can then feed a text file that describes this shifts and my AVIFixer software will process them and re-align the images.

Finally all frame fall out, and ffmpeg can be used to re-glue them to an AVI.

I will attach a link when I finished the final software.

Best regards

Martin.