无法将流写入文件

时间:2018-10-21 08:45:45

标签: c# file-io

我正在尝试将进程的输出流写入文件。文件已创建,但是那里没有内容(0 kb)。

var ffmpeg = System.Web.HttpContext.Current.Server.MapPath("~/FFMpeg/ffmpeg.exe");
var outputDir = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/converted.mp4");
var inputArgs = "-i http://file-examples.com/wp-content/uploads/2018/04/file_example_AVI_1280_1_5MG.avi";
var outputArgs = "-c:v libx264 -preset ultrafast -crf 26 -ac 2 -c:a aac -strict -2 -b:a 128k -f mp4 -";

var process = new Process
{
        StartInfo =
        {
            FileName = ffmpeg,
            Arguments = $"{inputArgs} {outputArgs}",
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true
        }
 };

 process.Start();
 System.IO.Stream outputStream = process.StandardOutput.BaseStream;
 process.WaitForExit();
 if (process.HasExited)
 {
         using (var fileStream = System.IO.File.Create(outputDir))
         {
               outputStream.CopyTo(fileStream);
         }
 }

0 个答案:

没有答案