title: Use FFMPEG process to get all frame from rtsp
body: <p>process to run a command that reads a RTSP stream with FFMPEG, and I need to catch each frame to display it in a picturebox; I'm receiving the data in void OnOutputDataReceived(object sender, DataReceivedEventArgs e), but once I transform e.data to byte[] and I generate the bitmap the app crashes.</p>
  
  <p>my code:</p>
  
  <pre><code>private void Form1_Load_1(object sender, EventArgs e)
      {
          Process proc = new Process();
          proc.StartInfo.FileName = "ffmpeg";
          proc.StartInfo.Arguments = "-i rtsp://user:foscam@50.197.211.181:9826/videoMain -an -vcodec mjpeg -s 640x480 -threads 1 -aspect 16:9 -q:v 2 -updatefirst 1 -b:v 64k -f -";
          proc.StartInfo.RedirectStandardError = true;
          proc.StartInfo.UseShellExecute = false;
          proc.StartInfo.RedirectStandardOutput = true;
          proc.OutputDataReceived += OnOutputDataReceived;
          if (!proc.Start())
          {
              Console.WriteLine("Error starting");
              return;
          }
          proc.BeginOutputReadLine();
          StreamReader reader = proc.StandardError;
          string line;
          while ((line = reader.ReadLine()) != null)
          {
              Console.WriteLine(line);
          }
          proc.Close();
      }
  
      void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
      {
          byte[] bytes = new byte[e.Data.Length * sizeof(char)];
          System.Buffer.BlockCopy(e.Data.ToCharArray(), 0, bytes, 0, bytes.Length);
          Bitmap bmp;
          using (var ms = new MemoryStream(bytes))
          {
      // CRASH SITE
  
              bmp = new Bitmap(ms);
          }
          pictureBox1.Image = bmp;
      }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/d7Fuz.jpg" rel="nofollow">Bytes</a></p>
  
  <p><a href="http://i.stack.imgur.com/dnYQs.jpg" rel="nofollow">Crash</a></p>