Làm cách nào tôi có thể bắt các thiết bị sử dụng ffmpeg và C#?

lập trình


Tôi muốn bắt các thiết bị bằng ffmpeg.exe. tôi đã sử dụng lớp Process và lệnh ffmpeg liên quan nhưng không thành công

Những gì tôi đã thử:

tôi đã sử dụng đoạn mã sau nhưng đầu ra không có gì!! tôi nghĩ điều đó xảy ra vì quá trình đã thoát ngay khi tiến trình.start() được thực thi. Làm thế nào tôi có thể làm điều đó?

C#
static void Main(string[] args)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = "ffmpeg.exe";
        startInfo.Arguments = "-list_devices true -f dshow -i dummy";
        startInfo.RedirectStandardOutput = false;


        try
        {
            using (Process process = Process.Start(startInfo))
            {
                while (!process.StandardOutput.EndOfStream)
                {
                    string line = process.StandardOutput.ReadLine();
                    Console.WriteLine(line);
                }

                process.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.ReadKey();
    }
}

Giải pháp 1

Bạn muốn “nắm bắt” đầu ra? Điêu nay co thể trả lơi câu hỏi của bạn: c# — Chụp đầu ra của bảng điều khiển từ ứng dụng .NET (C#)[^]

Giải pháp 2

Tôi gặp vấn đề tương tự. Tôi đã chuyển hướng đầu ra tiêu chuẩn, nhưng FFmpeg xuất tin nhắn văn bản thành lỗi tiêu chuẩn.

C#
static void Main(string[] args)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = "ffmpeg.exe";
        startInfo.Arguments = "-hide_banner -list_devices true -f dshow -i dummy";
        startInfo.RedirectStandardError = true;

        try
        {
            using (Process process = Process.Start(startInfo))
            {
                while (!process.StandardError.EndOfStream)
                {
                    string line = process.StandardError.ReadLine();
                    Console.WriteLine(line);
                }

                process.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.ReadKey();
    }
}

Mẹo: sử dụng -hide_banner trong đối số ffmpeg và bước tiếp theo của bạn sẽ dễ dàng hơn 🙂

Tôi hi vọng nó giúp ích cho ai đó.

コメント

タイトルとURLをコピーしました