0

I have written a bit of code that's supposed to create an avi file out of a List.

// instantiate AVI writer, use WMV3 codec
        internal static AVIWriter writer = new AVIWriter( "wmv3" );
        private static List<Bitmap> imgList = new List<Bitmap>();

        internal static void SaveFile()
        {
            var list = imgList;
            imgList = default(List<Bitmap>);

            // create new AVI file and open it
            writer.Open(@"d:\test.avi", 640, 480);
            foreach (Bitmap b in list)
            {
                writer.AddFrame(b);
            }
            writer.Close();
        }

Unfortubately, I am getting a nullreference exception at "foreach (Bitmap b in list)" But when I debug and place a breakpoint at writer.Close();, this error only triggers after I actually pass that breakpoint.

So I'm pretty confused, does anyone know what's going on here?

1 Answers1

0

No exactly sure why your program would encounter the same exception at 2 different points. My best guess is it has something to do with native interop not syncing with managed code.

Have you tried referencing the AForge source code instead of a binary? This will let you pin-point the exact location the error occurs.

For now I suggest you check your list of bitmaps for any nulls or update to the latest AForge(maybe it's a framework bug). I also recommend you try a couple of different codecs(don't ask why).

Curtis Jones
  • 131
  • 4
  • Hm, and when I try to use the FFMPEG library instead, it somehow manages to throw an exception even BEFORE any code relating to ffmpeg is accessed (the code to place frames in imgList, which is entirely unrelated) – user2303251 Apr 21 '13 at 15:42
  • May i suggest that you ditch AForge. In my experience it's just too unstable(in this respect) to handle stuff like this. Try using the video writer class in EmguCV instead. Even better, dump all your video frames to a temp directory and invoke FFMpeg DIRECTLY(through command line arguments) to combine them all(just google the arguments). – Curtis Jones Apr 23 '13 at 19:49