## AVI recovery

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

### AVI recovery

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.
Posts: 6321
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

### Re: AVI recovery

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)
{
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);

// 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);
{
i++;

}

return i;
}
}


Hope this helps,

Robin
albusmw
Posts: 3
Joined: Mon Feb 22, 2021 7:54 am

### Re: AVI recovery

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.