5

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

4

4 に答える 4

6
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");
        }
    }
}
于 2016-04-21T15:59:36.763 に答える
2

ffmpeg プロセスを実行する代わりに、コードから ffmpeg ライブラリに直接アクセスする必要があります。たとえば、AForge.Netをチェックしてください。とりわけ、ffmpeg 管理ラッパーがあります。AForge.Video.FFMPEG.VideoFileWriter指定されたエンコーダーを使用してビデオ ファイル ストリームにイメージを書き込むクラスに興味があります。詳細については、オンライン ドキュメントを参照してください。

于 2013-10-29T12:50:56.790 に答える