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

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

问题描述

我有100个jpegs。



我使用ffmpeg将其编码到写入硬盘的视频文件。



有没有办法直接管理一个字节/流?



我正在使用C#,我正在使用进程类来启动ffmpeg。 / p>

谢谢

解决方案

 系统; 
使用System.Diagnostics;
使用System.Drawing;
使用System.IO;

命名空间PipeFfmpeg
{
类程序
{
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(); (int i = 0; i< 500; i ++)
{
使用(var ms = new MemoryStream())

使用(var img = Image.FromFile(@lena.png))
{
img.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
ms.WriteTo(proc.StandardInput.BaseStream);
}
}
}
}

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


I have 100 jpegs.

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?

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

Thanks

解决方案

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

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

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