public static void Stop(Process ps)
 {
     try
     {
         if (ps != null && ps.ProcessName.Contains(FFMPEG_PROCESS_NAME))
         {
             int counter = 0;
             while ((!ps.HasExited) && (counter < MAX_RETRY_QUIT_COMMAND))
             {
                 IntPtr hwnd = ps.MainWindowHandle;
                 CommonLibs.CallPostMessage(hwnd, WM_KEYDOWN, KEY_CHARACTER_CODE_Q, 0); //send "Q"
                 System.Threading.Thread.Sleep(RETRY_SEND_QUIT_COMMAND_WAIT_TIME);
                 counter++;
             }
             if (!ps.HasExited && counter >= MAX_RETRY_QUIT_COMMAND)
             {
                 ps.Kill();
             }
         }
     }catch
     {
         // If there is an exception, Kill all ffmpeg process
         Process[] processes = Process.GetProcessesByName(FFMPEG_PROCESS_NAME);
         foreach (Process p in processes)
         {
             p.Kill();
         }
     }
 }
 public static void Pause(Process ps)
 {
     if (ps != null && ps.ProcessName.Contains(FFMPEG_PROCESS_NAME))
     {
         IntPtr hwnd = ps.MainWindowHandle;
         CommonLibs.CallPostMessage(hwnd, WM_KEYDOWN, KEY_CHARACTER_CODE_PAUSE, 0);  // send "pause"
     }
 }