{
  "id": 1302,
  "title": "Anyone figure out a way to read the avi file in C#",
  "url": "/competitions/GestureChallenge/discussion/1302",
  "author_name": "",
  "post_date": "2012-01-24T05:52:53.417Z",
  "votes": null,
  "comment_count": 12,
  "views": 19726,
  "content": "<p>Since Microsoft SDK is in C#, I was trying to code in C# but ran into issues of finding a library to read the avi file in C#.</p>\r\n<p>OS: Windows 7</p>\r\n<p>Arch: x64</p>\r\n<p>Visual Studio 2010</p>\r\n<p>I tried the following:Emgu and <a href=\"http://code.google.com/p/aforge/\">http://code.google.com/p/aforge/</a>&nbsp;but it failed to read avi file, so looks like I am going to have to write my own wrapper for opencv from C&#43;&#43; to C#. Anyone have any other suggestions\r\n for libraries?</p>\r\n<p>Thanks!</p>\r\n<p>Aniket</p>",
  "messages": [
    {
      "id": "8247",
      "postDate": "01/24/2012 05:52:53",
      "content": "<p>Since Microsoft SDK is in C#, I was trying to code in C# but ran into issues of finding a library to read the avi file in C#.</p>\r\n<p>OS: Windows 7</p>\r\n<p>Arch: x64</p>\r\n<p>Visual Studio 2010</p>\r\n<p>I tried the following:Emgu and <a href=\"http://code.google.com/p/aforge/\">http://code.google.com/p/aforge/</a>&nbsp;but it failed to read avi file, so looks like I am going to have to write my own wrapper for opencv from C&#43;&#43; to C#. Anyone have any other suggestions\r\n for libraries?</p>\r\n<p>Thanks!</p>\r\n<p>Aniket</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8255",
      "postDate": "01/25/2012 07:26:18",
      "content": "<p>This is awful... Microsoft isn't even fixing its signing issues for dlls.... Therefore I recommend not trying to work with Aforge.Net.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8256",
      "postDate": "01/25/2012 10:43:06",
      "content": "<p>What seems to be the problem with AForge? It's not my favorite library but it was quite stable when I used it. Did you try the DirectShow video reader they provide?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8259",
      "postDate": "01/25/2012 17:02:24",
      "content": "<p>For reading avi files, they recommend you use: VideoFileReader class. It is a version problem. Basically the following: https://connect.microsoft.com/VisualStudio/feedback/details/464524/mt-error-810100b.\r\n</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8266",
      "postDate": "01/26/2012 03:30:03",
      "content": "<p>[quote=Aniket;8247]</p>\r\n<p>Since Microsoft SDK is in C#, I was trying to code in C#...</p>\r\n<p>[/quote]</p>\r\n<p>I may be wrong, but I'm pretty sure there is no easy way to use the Kinect SDK on these pre-recorded videos. Everything I've read has led me to believe the SDK can only be used with a live Kinect and not pre-recorded kinect video.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8268",
      "postDate": "01/26/2012 07:19:57",
      "content": "<p>I wasn't trying to use the Kinect SDK to read in the videos... I am trying to read the video with another library, AForge.NET, that way I don't have to rewrite all of my matlab code.\r\n</p>\r\n<p>Think I have figured it out.... Was using the wrong class. If anyone is stuck use the AVIFileVideoSource or AVIReader which is found in Aforge.Video.VFW dll. Think this should work but haven't completely figure it out yet. My problem seems to be that it\r\n is nor recognizing the creation of the object.</p>\r\n<p>Ex: <br>\r\nAVIReader reader = new AVIReader( );<br>\r\nreader.Open( &quot;test.avi&quot; );</p>\r\n<p>It doesn't recognize the object(&quot;reader&quot;) on the second line in my code. </p>\r\n<p>Any suggestions? </p>\r\n<p>Thanks! </p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8270",
      "postDate": "01/26/2012 16:33:17",
      "content": "<p>It's probably the best if you post the full code (just for reading the video). Also try the samples here: http://www.aforgenet.com/framework/samples/video.html</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8279",
      "postDate": "01/27/2012 06:14:33",
      "content": "<p>Sorry but I think I know what the problem is.... Forgot the main method. Feel really stupid.... Really sorry for all the questions!</p>\r\n<p>&nbsp;</p>\r\n<p>Forgot to mention that you also need the correct codec.&nbsp;</p>\r\n<p>Aniket</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8348",
      "postDate": "01/30/2012 14:52:39",
      "content": "<p>I am able to read an avi file frame by frame using the following code. However, it isn't exiting the form. Believe this a threading problem. Any suggestions? Or should I try AVIReader class? However the AVIReader skips the first frame(think this would be\r\n important...)</p>\r\n<p>I have tried the videoSource.Stop(), videoSource.SignaltoStop(), videoSource.WaitForStop() but none of them seems to work. I have also tried Application.Exit() and this.close().\r\n<br>\r\nThanks!</p>\r\n<p>Code:<br>\r\nusing System;<br>\r\nusing System.Collections.Generic;<br>\r\nusing System.ComponentModel;<br>\r\nusing System.Data;<br>\r\nusing System.Drawing;<br>\r\nusing System.Linq;<br>\r\nusing System.Text;<br>\r\nusing System.Windows.Forms;<br>\r\nusing AForge.Video;<br>\r\nusing AForge.Video.DirectShow;<br>\r\nusing System.Threading;</p>\r\n<p>namespace GestureRecognition<br>\r\n{<br>\r\npublic partial class Form1 : Form<br>\r\n{<br>\r\n//store video source<br>\r\nFileVideoSource videoSource;<br>\r\n//delegate void videoSource_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);</p>\r\n<pre><code>    public Form1()\n    {\n        InitializeComponent();\n    }\n\n    private void Form1_Load(object sender, EventArgs e)\n    {\n        fileName = @&quot;C:\\Users\\aniket\\Documents\\CHALEARN Gesture Challenge\\Challenge\\Data\\valid01\\M_1.avi&quot;;\n        videoSource = new FileVideoSource(fileName);\n\n        videoSource.NewFrame &#43;= new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);\n        videoSource.Start();\n    }\n\n    // New frame event handler, which is invoked on each new available video frame\n    public void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)\n    {\n        // get new frame\n        Bitmap bitmap = eventArgs.Frame;\n        // process the frame\n        pictureBox1.Image = bitmap;\n\n        Thread.Sleep(200);\n    }\n\n    public string fileName { get; set; }\n}\n</code></pre>\r\n<p>}</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8373",
      "postDate": "01/31/2012 15:30:03",
      "content": "<p>You should do something like videoSource.PlayingFinished &#43;= (o,e)=&gt;Close(); before starting the video if you want the form to close after the video is finished.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8384",
      "postDate": "02/01/2012 04:46:22",
      "content": "<p>Thanks! redstr. I will try that.<br>\r\nAniket</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "24505",
      "postDate": "05/20/2013 02:25:49",
      "content": "<p>maybe you can use <a href=\"http://www.rasteredge.com/how-to/csharp-imaging/imaging-processing/\">\r\nc# image reading library</a> to help&nbsp; you with whatever you are doing. it can be fun and interesting.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "121062",
      "postDate": "05/23/2016 11:22:05",
      "content": "<blockquote>\n  <p>Full disclosure: I work for GleamTech</p>\n</blockquote>\n\n<p>Sorry if this is too late but it may benefit future surfers.</p>\n\n<p>There is a way for this purpose if you want to do it with any video file format on the planet (no need for codecs). The following sample will loop all frames, however you can seek or skip frames when necessary:</p>\n\n\n\n<pre><code>using (var videoFrameReader = new VideoFrameReader(@&quot;C:\\Video.mp4&quot;))\n{\n    var frameIndex = 0;\n\n    while (videoFrameReader.Read())\n    {\n        Console.WriteLine(&quot;Coded Frame Number: &quot; + videoFrameReader.CurrentFrameNumber);\n        Console.WriteLine(&quot;Frame Index: &quot; + frameIndex++);\n\n        //This gets the current frame as a Bitmap instance\n        //Of course only if the above Read() call is successful.\n        var frame = videoFrameReader.GetFrame();\n\n        //Do something with frame\n    }\n}\n</code></pre>\n\n<p><strong>VideoFrameReader</strong> class is found <a href=\"http://www.gleamtech.com/videoultimate\">VideoUltimate</a> library from GleamTech. It reads a video frame by frame, also allows seeking and provides info on the video.</p>",
      "rawMarkdown": "> Full disclosure: I work for GleamTech\r\n\r\nSorry if this is too late but it may benefit future surfers.\r\n\r\nThere is a way for this purpose if you want to do it with any video file format on the planet (no need for codecs). The following sample will loop all frames, however you can seek or skip frames when necessary:\r\n\r\n<!-- language: c# -->\r\n\r\n\tusing (var videoFrameReader = new VideoFrameReader(@\"C:\\Video.mp4\"))\r\n\t{\r\n\t\tvar frameIndex = 0;\r\n\r\n\t\twhile (videoFrameReader.Read())\r\n\t\t{\r\n\t\t\tConsole.WriteLine(\"Coded Frame Number: \" + videoFrameReader.CurrentFrameNumber);\r\n\t\t\tConsole.WriteLine(\"Frame Index: \" + frameIndex++);\r\n            \r\n            //This gets the current frame as a Bitmap instance\r\n            //Of course only if the above Read() call is successful.\r\n            var frame = videoFrameReader.GetFrame();\r\n\r\n            //Do something with frame\r\n\t\t}\r\n\t}\r\n\r\n**VideoFrameReader** class is found [VideoUltimate][1] library from GleamTech. It reads a video frame by frame, also allows seeking and provides info on the video.\r\n\r\n  [1]: http://www.gleamtech.com/videoultimate",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 8255,
      "author_name": "",
      "author_url": "",
      "post_date": "01/25/2012 07:26:18",
      "content": "<p>This is awful... Microsoft isn't even fixing its signing issues for dlls.... Therefore I recommend not trying to work with Aforge.Net.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8256,
      "author_name": "redstr",
      "author_url": "",
      "post_date": "01/25/2012 10:43:06",
      "content": "<p>What seems to be the problem with AForge? It's not my favorite library but it was quite stable when I used it. Did you try the DirectShow video reader they provide?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8259,
      "author_name": "",
      "author_url": "",
      "post_date": "01/25/2012 17:02:24",
      "content": "<p>For reading avi files, they recommend you use: VideoFileReader class. It is a version problem. Basically the following: https://connect.microsoft.com/VisualStudio/feedback/details/464524/mt-error-810100b.\r\n</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8266,
      "author_name": "mmolek",
      "author_url": "",
      "post_date": "01/26/2012 03:30:03",
      "content": "<p>[quote=Aniket;8247]</p>\r\n<p>Since Microsoft SDK is in C#, I was trying to code in C#...</p>\r\n<p>[/quote]</p>\r\n<p>I may be wrong, but I'm pretty sure there is no easy way to use the Kinect SDK on these pre-recorded videos. Everything I've read has led me to believe the SDK can only be used with a live Kinect and not pre-recorded kinect video.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8268,
      "author_name": "",
      "author_url": "",
      "post_date": "01/26/2012 07:19:57",
      "content": "<p>I wasn't trying to use the Kinect SDK to read in the videos... I am trying to read the video with another library, AForge.NET, that way I don't have to rewrite all of my matlab code.\r\n</p>\r\n<p>Think I have figured it out.... Was using the wrong class. If anyone is stuck use the AVIFileVideoSource or AVIReader which is found in Aforge.Video.VFW dll. Think this should work but haven't completely figure it out yet. My problem seems to be that it\r\n is nor recognizing the creation of the object.</p>\r\n<p>Ex: <br>\r\nAVIReader reader = new AVIReader( );<br>\r\nreader.Open( &quot;test.avi&quot; );</p>\r\n<p>It doesn't recognize the object(&quot;reader&quot;) on the second line in my code. </p>\r\n<p>Any suggestions? </p>\r\n<p>Thanks! </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8270,
      "author_name": "redstr",
      "author_url": "",
      "post_date": "01/26/2012 16:33:17",
      "content": "<p>It's probably the best if you post the full code (just for reading the video). Also try the samples here: http://www.aforgenet.com/framework/samples/video.html</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8279,
      "author_name": "",
      "author_url": "",
      "post_date": "01/27/2012 06:14:33",
      "content": "<p>Sorry but I think I know what the problem is.... Forgot the main method. Feel really stupid.... Really sorry for all the questions!</p>\r\n<p>&nbsp;</p>\r\n<p>Forgot to mention that you also need the correct codec.&nbsp;</p>\r\n<p>Aniket</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8348,
      "author_name": "",
      "author_url": "",
      "post_date": "01/30/2012 14:52:39",
      "content": "<p>I am able to read an avi file frame by frame using the following code. However, it isn't exiting the form. Believe this a threading problem. Any suggestions? Or should I try AVIReader class? However the AVIReader skips the first frame(think this would be\r\n important...)</p>\r\n<p>I have tried the videoSource.Stop(), videoSource.SignaltoStop(), videoSource.WaitForStop() but none of them seems to work. I have also tried Application.Exit() and this.close().\r\n<br>\r\nThanks!</p>\r\n<p>Code:<br>\r\nusing System;<br>\r\nusing System.Collections.Generic;<br>\r\nusing System.ComponentModel;<br>\r\nusing System.Data;<br>\r\nusing System.Drawing;<br>\r\nusing System.Linq;<br>\r\nusing System.Text;<br>\r\nusing System.Windows.Forms;<br>\r\nusing AForge.Video;<br>\r\nusing AForge.Video.DirectShow;<br>\r\nusing System.Threading;</p>\r\n<p>namespace GestureRecognition<br>\r\n{<br>\r\npublic partial class Form1 : Form<br>\r\n{<br>\r\n//store video source<br>\r\nFileVideoSource videoSource;<br>\r\n//delegate void videoSource_NewFrameDelegate(object sender, NewFrameEventArgs eventArgs);</p>\r\n<pre><code>    public Form1()\n    {\n        InitializeComponent();\n    }\n\n    private void Form1_Load(object sender, EventArgs e)\n    {\n        fileName = @&quot;C:\\Users\\aniket\\Documents\\CHALEARN Gesture Challenge\\Challenge\\Data\\valid01\\M_1.avi&quot;;\n        videoSource = new FileVideoSource(fileName);\n\n        videoSource.NewFrame &#43;= new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);\n        videoSource.Start();\n    }\n\n    // New frame event handler, which is invoked on each new available video frame\n    public void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)\n    {\n        // get new frame\n        Bitmap bitmap = eventArgs.Frame;\n        // process the frame\n        pictureBox1.Image = bitmap;\n\n        Thread.Sleep(200);\n    }\n\n    public string fileName { get; set; }\n}\n</code></pre>\r\n<p>}</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8373,
      "author_name": "redstr",
      "author_url": "",
      "post_date": "01/31/2012 15:30:03",
      "content": "<p>You should do something like videoSource.PlayingFinished &#43;= (o,e)=&gt;Close(); before starting the video if you want the form to close after the video is finished.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8384,
      "author_name": "",
      "author_url": "",
      "post_date": "02/01/2012 04:46:22",
      "content": "<p>Thanks! redstr. I will try that.<br>\r\nAniket</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 24505,
      "author_name": "adimage",
      "author_url": "",
      "post_date": "05/20/2013 02:25:49",
      "content": "<p>maybe you can use <a href=\"http://www.rasteredge.com/how-to/csharp-imaging/imaging-processing/\">\r\nc# image reading library</a> to help&nbsp; you with whatever you are doing. it can be fun and interesting.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 121062,
      "author_name": "gleamtech",
      "author_url": "",
      "post_date": "05/23/2016 11:22:05",
      "content": "<blockquote>\n  <p>Full disclosure: I work for GleamTech</p>\n</blockquote>\n\n<p>Sorry if this is too late but it may benefit future surfers.</p>\n\n<p>There is a way for this purpose if you want to do it with any video file format on the planet (no need for codecs). The following sample will loop all frames, however you can seek or skip frames when necessary:</p>\n\n\n\n<pre><code>using (var videoFrameReader = new VideoFrameReader(@&quot;C:\\Video.mp4&quot;))\n{\n    var frameIndex = 0;\n\n    while (videoFrameReader.Read())\n    {\n        Console.WriteLine(&quot;Coded Frame Number: &quot; + videoFrameReader.CurrentFrameNumber);\n        Console.WriteLine(&quot;Frame Index: &quot; + frameIndex++);\n\n        //This gets the current frame as a Bitmap instance\n        //Of course only if the above Read() call is successful.\n        var frame = videoFrameReader.GetFrame();\n\n        //Do something with frame\n    }\n}\n</code></pre>\n\n<p><strong>VideoFrameReader</strong> class is found <a href=\"http://www.gleamtech.com/videoultimate\">VideoUltimate</a> library from GleamTech. It reads a video frame by frame, also allows seeking and provides info on the video.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "8247": "",
    "8255": "",
    "8256": "",
    "8259": "",
    "8266": "",
    "8268": "",
    "8270": "",
    "8279": "",
    "8348": "",
    "8373": "",
    "8384": "",
    "24505": "",
    "121062": "> Full disclosure: I work for GleamTech\r\n\r\nSorry if this is too late but it may benefit future surfers.\r\n\r\nThere is a way for this purpose if you want to do it with any video file format on the planet (no need for codecs). The following sample will loop all frames, however you can seek or skip frames when necessary:\r\n\r\n<!-- language: c# -->\r\n\r\n\tusing (var videoFrameReader = new VideoFrameReader(@\"C:\\Video.mp4\"))\r\n\t{\r\n\t\tvar frameIndex = 0;\r\n\r\n\t\twhile (videoFrameReader.Read())\r\n\t\t{\r\n\t\t\tConsole.WriteLine(\"Coded Frame Number: \" + videoFrameReader.CurrentFrameNumber);\r\n\t\t\tConsole.WriteLine(\"Frame Index: \" + frameIndex++);\r\n            \r\n            //This gets the current frame as a Bitmap instance\r\n            //Of course only if the above Read() call is successful.\r\n            var frame = videoFrameReader.GetFrame();\r\n\r\n            //Do something with frame\r\n\t\t}\r\n\t}\r\n\r\n**VideoFrameReader** class is found [VideoUltimate][1] library from GleamTech. It reads a video frame by frame, also allows seeking and provides info on the video.\r\n\r\n  [1]: http://www.gleamtech.com/videoultimate"
  },
  "source": "meta"
}