C# ffmpeg 把 byte[]推送到rtmp服务器

using System;
using System.Diagnostics;
 
class Program
{
    static void Main(string[] args)
    {
        // 定义要发送的字节数组
        byte[] data = new byte[1024];
        
        // 构建 FFmpeg 命令参数
        string commandArgs = "-i - -f flv rtmp://your_rtmp_server/live/stream";
        
        // 创建 ProcessStartInfo 对象来运行 FFmpeg
        var processInfo = new ProcessStartInfo("ffmpeg", commandArgs);
        processInfo.RedirectStandardInput = true;
        processInfo.UseShellExecute = false;
        
        try
        {
            using (var process = Process.Start(processInfo))
            {
                if (process != null && !process.HasExited)
                {
                    // 向 FFmpeg 输入流写入字节数组
                    process.StandardInput.BaseStream.Write(data, 0, data.Length);
                    
                    // 关闭标准输入流
                    process.StandardInput.Close();
                    
                    // 等待 FFmpeg 结束
                    process.WaitForExit();
                }
            }
            
            Console.WriteLine("RTMP 推送完成!");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"错误信息:{ex.Message}");
        }
    }
}



© 2016-2024 阿尔佛 aerfo.com | 豫ICP备17044542号 | 豫公网安备 41010602000172