4

这是启动进程的 ffmpeg.cs 类中的代码。我的兄弟试图单独运行 ffmpeg.exe 并且没有问题,但是一旦他单击按钮并且进程开始,他就会遇到异常:

我的兄弟有 windows xp 32 位,而我使用的是 windows 8 64 位,但 ffmpeg.exe 是 32 位版本,它在我的机器上工作。

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();
        }

这是他在计算机上收到的异常消息:

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()

可能是什么问题呢 ?

4

0 回答 0