title: Mplayer Dump Audio from video, working good only on non C hard drive
body: <p>I'm using Mplayer to extrac audio from video via command line. This is the command i use:</p>
  
  <pre><code>mplayer -ao pcm:fast:file=aaa.wav aaa.avi
  </code></pre>
  
  <p>I copied Mplayer.exe and aaa.avi both on windows drive (C:) and on the root directory of an external hard drive (in my case X).</p>
  
  <p>When i execute from C the dumping start at normal speed (i see the video on real time) and aaa.wav is not created by Mplayer.</p>
  
  <p>When i execute form X the dumping start at fast speed (as requested by the -ao pcm:fast audio driver) and the aaa.wav is correctly created.</p>
  
  <p>I have the same issue in my app, here the code i use to do it:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public static string DumpWav_ConsoleOutput = "";
          public static int DumpWav_ProcessID = 0;
          Process DumpWav_Process = null;
  
          private void DumpWav(string SourceFileName, string DestinationFileName, bool NeedToCut, TimeSpan Start, TimeSpan End)
          {
              //cancelliamo le variabili
              DumpWav_ConsoleOutput = "";
              //Handle della finestra di Media Player
              Variables.MediaPlayerHandle = 0;
              Variables.MediaPlayerHandle = (int)MediaPlayer.Handle;
              Thread thread = new Thread(() =&gt; _DumpWav(SourceFileName, DestinationFileName, NeedToCut,Start, End)); //il thread principale di Dump Wav
              thread.Start();
              while (thread.IsAlive) //aspettiamo il suo completamento
              {
                  Application.DoEvents();
              }
              var myForm = new Output();
              myForm.SetOutputText = Variables.ConsoleOutputMP;
              myForm.Show();
              Variables.MediaPlayerExit = true;
              // ok il processo è terminato
          }
  
          private void _DumpWav(string SourceFileName, string DestinationFileName, bool NeedToCut, TimeSpan Start, TimeSpan End)
          {
              string Output;
              Output = RunDumpWav((output) =&gt; { }, SourceFileName, DestinationFileName, NeedToCut, Start, End);
          }
  
  
          // Media Player avviato da questa funzione
          public string RunDumpWav(Action&lt;string&gt; output, string SourceFileName, string DestinationFileName, bool NeedToCut, TimeSpan Start, TimeSpan End)
          {
              if (output == null)
                  throw new ArgumentNullException("output");
              string args;
              ProcessStartInfo ps = new ProcessStartInfo();
              ps.FileName = FindMediaPlayerPath("mplayer.exe");
              ps.UseShellExecute = false;
              ps.RedirectStandardInput = true;
              ps.RedirectStandardError = true;
              ps.RedirectStandardOutput = true;
              ps.CreateNoWindow = true;
              ps.WorkingDirectory = @"x:\";
              args = "-wid ";
              args += Variables.MediaPlayerHandle;
              args += " -ao pcm:fast:file=";
              args += DestinationFileName;
              if (NeedToCut == true)
              {
                  args += " -ss " + Start + " -endpos " + End;
              }
              //args += " -vo null -vc null -quiet ";
              //-wid will tell MPlayer to show output inisde our panel
              args += " " + SourceFileName;
              ps.Arguments = args;
  
              using (DumpWav_Process = Process.Start(ps))
  
  
              using (ManualResetEvent mreOut = new ManualResetEvent(false),
              mreErr = new ManualResetEvent(false))
              {
                  DumpWav_Process.OutputDataReceived += (o, e) =&gt; { if (e.Data == null) mreOut.Set(); else output(e.Data); };
                  DumpWav_Process.BeginOutputReadLine();
  
                  DumpWav_Process.ErrorDataReceived += (o, e) =&gt; { if (e.Data == null) mreErr.Set(); else output(e.Data); }; ;
                  DumpWav_Process.BeginErrorReadLine();
  
                  output = s =&gt; DumpWav_ElaborateOutput(s);
  
                  DumpWav_ProcessID = DumpWav_Process.Id;
                  //processMP.StandardInput.Close();
                  DumpWav_Process.WaitForExit();
                  mreOut.WaitOne();
                  mreErr.WaitOne();
                  //stringa di ritorno (tutto il contenuto della console)
                  return DumpWav_ConsoleOutput;
              }
          }
  
          //controlliamo l'output della console
          private void DumpWav_ElaborateOutput(string output)
          {
              Variables.ConsoleOutputMP = Variables.ConsoleOutputMP + output + Environment.NewLine;
              if (output.IndexOf("A:") != -1)
              {
  //some check here
              }
  
          }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I recently added this: </p>
  
  <pre><code>ps.WorkingDirectory = @"x:\";
  </code></pre>
  
  <p>But the result not change, the video speed is not fast and the wav file is not created by Mplayer.</p>
  
  <p>In my app, like the C test, i receive some errors:</p>
  
  <pre><code>[AO PCM] Failed to open aaa.wav for writing!
  Failed to initialize audio driver 'pcm:fast:file=aaa.wav'
  </code></pre>
  
  <p>One more question, when i use mPlayer to encapsulate videos inside my app the process start about one minute after i launched it... maybe concatenate with dumping issue?</p>
  
  <p>Please, any suggestion?</p>
  
  <p>Edit:
  I discovered just now: If i start the command prompt with admin rights then also in C Drive Mplayer do the job in the right way...
  My app unfortunately don't. I edited the manifest to grant admin rights but it's the same. Somewhere here at stackoverflow i read something about to useshellexecute to true but unfortunately by this way (i need to test anyway) i lose the ability to redirect input/output/error.</p>
  
  <p>I need to find a way to start the process (then the mplayer.exe) from within my app, with admin rights, without use shellexecute...</p>
  
  <p>Edit 2°
  I created a simple button with this code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>            string args;
              //Handle della finestra di Media Player
              Variables.MediaPlayerHandle = 0;
              Variables.MediaPlayerHandle = (int)MediaPlayer.Handle;
              ProcessStartInfo psi = new ProcessStartInfo();
              psi.FileName = FindMediaPlayerPath("mplayer.exe");
              //psi.FileName = @"x:\mplayer.exe";
              psi.UseShellExecute = true;
              psi.CreateNoWindow = true;
              psi.WindowStyle = ProcessWindowStyle.Hidden;
              psi.WorkingDirectory = Environment.CurrentDirectory; ;
              psi.Verb = "runas";
              args = "-wid ";
              args += Variables.MediaPlayerHandle;
              args += " -ao pcm:fast:file=";
              args += @"x:\aaa.wav";
              args += @" x:\aaa.avi";
              psi.Arguments = args;
              Process.Start(psi);</code></pre>
  </div>
  </div>
  </p>
  
  <p>:-( same result, Mplayer is not able to open audio driver and to save file..</p>
  
  <p>Fail, again.. 3° edit:
  I tried using CMD:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>        private void button2_Click(object sender, EventArgs e)
          {
              ProcessStartInfo processInfo;
              Process process;
              Variables.MediaPlayerHandle = 0;
              Variables.MediaPlayerHandle = (int)MediaPlayer.Handle;
              string args = "";
              args = @"x:\mplayer.exe -wid " + Variables.MediaPlayerHandle + @" -ao pcm:fast:file=x:\aaa.wav x:\aaa.avi";
              MessageBox.Show(args);
              processInfo = new ProcessStartInfo("cmd.exe", "/c " + args);
              processInfo.CreateNoWindow = true;
              processInfo.UseShellExecute = true;
              processInfo.Verb = "runas";
              process = Process.Start(processInfo);
              process.WaitForExit();
              MessageBox.Show("terminato");
  
              process.Close();
          }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Now i see the first frame of the video and Mplayer freeze...</p>
  
  <p>I'm losing my hope to use mplayer :-(</p>