AVI recovery

Somewhere to share your expertise in using SharpCap
Post Reply
albusmw
Posts: 3
Joined: Mon Feb 22, 2021 7:54 am

AVI recovery

Post 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.
User avatar
admin
Site Admin
Posts: 6669
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: AVI recovery

Post 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
albusmw
Posts: 3
Joined: Mon Feb 22, 2021 7:54 am

Re: AVI recovery

Post 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.
Post Reply