gpt4 book ai didi

c# - 如何在 C# 中的 ffmpeg 中使用管道

转载 作者:太空狗 更新时间:2023-10-30 00:19:30 25 4
gpt4 key购买 nike

我有 100 张 jpeg。

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

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

我正在使用 C# 并且正在使用进程类来启动 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# - 如何在 C# 中的 ffmpeg 中使用管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com