4

This is the code in the ffmpeg.cs class where the process is start . My brother tried to run the ffmpeg.exe alone and it's working no problems but once he click the button and the process is start he is getting an exception :

My brother have windows xp 32bit while i'm using windows 8 64bit but the ffmpeg.exe is 32bit version and it's working on my machine.

using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;

namespace ScreenVideoRecorder
{
    class Ffmpeg
    {
        NamedPipeServerStream p;
        String pipename = "mytestpipe";
        byte[] b;
        System.Diagnostics.Process process;
        string ffmpegFileName;
        string workingDirectory;

        public Ffmpeg()
        {
            workingDirectory = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\workingDirectory";
            ffmpegFileName = @"\ffmpeg.exe";
            if (!Directory.Exists(workingDirectory))
            {
                Directory.CreateDirectory(workingDirectory);
            }
            ffmpegFileName = workingDirectory + ffmpegFileName;
        }

        public void Start(string pathFileName, int BitmapRate)
        {
            string outPath = pathFileName;
            p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);
            b = new byte[1920 * 1080 * 3]; // some buffer for the r g and b of pixels of an image of size 720p

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;
            psi.CreateNoWindow = true;
            psi.FileName = ffmpegFileName;
            psi.WorkingDirectory = workingDirectory;
            psi.Arguments = @"-f rawvideo -pix_fmt bgr0 -video_size 1920x1080 -i \\.\pipe\mytestpipe -map 0 -c:v libx264 -r " + BitmapRate + " " + outPath;
            //psi.RedirectStandardOutput = true;
            process = Process.Start(psi);
            process.EnableRaisingEvents = false;
            p.WaitForConnection();
        }

This is the exception message he get on his computer :

Application: ScreenVideoRecorder.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ComponentModel.Win32Exception
Stack:
   at System.Diagnostics.Process.StartWithCreateProcess(System.Diagnostics.ProcessStartInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
   at ScreenVideoRecorder.Ffmpeg.Start(System.String, Int32)
   at ScreenVideoRecorder.Form1.gkh_KeyDown(System.Object, System.Windows.Forms.KeyEventArgs)
   at Utilities.globalKeyboardHook.hookProc(Int32, Int32, keyboardHookStruct ByRef)
   at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG ByRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32)
   at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
   at ScreenVideoRecorder.Program.Main()

What could be the problem ?

pascalhein
  • 5,700
  • 4
  • 31
  • 44
joneK
  • 241
  • 1
  • 4
  • 13
  • Try targeting the .NET executable to 32bit and see what happens. Could be that it tries to run ffmpeg in 64bit mode. – Oded Jun 08 '13 at 15:38
  • see [this question](http://stackoverflow.com/questions/13974653/system-componentmodel-win32exception-when-starting-process-file-not-found-but) for a similar error – pascalhein Jun 08 '13 at 15:39
  • When you ran the program on your brother's machine did you pass in the same command line arguments as the code does? Also, does your brother's monitor support 1920x1080 resolution? – Jason Jun 08 '13 at 15:40
  • Same arguments command line i sent him the same compiled program im using targeting x86 – joneK Jun 08 '13 at 15:45
  • @joneK did you manage to fix it? did you find out the problem? I am facing same problem but with a windows 7 – ovi May 09 '18 at 20:42

0 Answers0