如何在 c# 中的 ffmpeg 中使用管道 [英] How to use pipe in ffmpeg within c#

查看:52
本文介绍了如何在 c# 中的 ffmpeg 中使用管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 100 个 jpeg.

I have 100 jpegs.

我使用 ffmpeg 编码为写入硬盘的视频文件.

I use ffmpeg to encode to a video file which is written to a hard drive.

有没有办法将它直接通过管道传输到字节/流?

Is there a way to pipe it directly to a byte/stream?

我正在使用 C#,我正在使用进程类来启动 ffmpeg.

I am using C# and I am using the process class to initate ffmpeg.

谢谢

推荐答案

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;

namespace PipeFfmpeg
{
    class Program
    {
        public static void Video(int bitrate, int fps, string outputfilename)
        {
            Process proc = new Process();

            proc.StartInfo.FileName = @"ffmpeg.exe";
            proc.StartInfo.Arguments = String.Format("-f image2pipe -i pipe:.bmp -maxrate {0}k -r {1} -an -y {2}",
                bitrate, fps, outputfilename);
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardInput = true;
            proc.StartInfo.RedirectStandardOutput = true;

            proc.Start();

            for (int i = 0; i < 500; i++)
            {
                using (var ms = new MemoryStream())
                {
                    using (var img = Image.FromFile(@"lena.png"))
                    {
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                        ms.WriteTo(proc.StandardInput.BaseStream);
                    }
                }
            }            
        }

        static void Main(string[] args)
        {
            Video(5000, 10, "lena.mp4");
        }
    }
}

这篇关于如何在 c# 中的 ffmpeg 中使用管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆