目标:我正在创建一个视频共享网站。我想将用户上传的视频流编码为mp4。 (我假设这反过来也会验证用户上传了一个视频文件,而不是exe。)
当前代码:
[HttpPost]
public async Task<ActionResult> Upload(HttpPostedFileBase video)
{
using (var ffmpeg = new Process())
{
ffmpeg.StartInfo.FileName = "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = "-i - {0} -f mp4 - ";
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.RedirectStandardInput = true;
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();
video.InputStream.Position = 0;
var buffer = new byte[video.InputStream.Length];
await video.InputStream.ReadAsync(buffer, 0, buffer.Length);
await ffmpeg.StandardInput.BaseStream.WriteAsync(buffer, 0, buffer.Length);
var stdoutLength = Convert.ToInt32(ffmpeg.StandardOutput.BaseStream.Length);
var encodedVideo = new byte[stdoutLength];
await ffmpeg.StandardOutput.BaseStream.ReadAsync(encodedVideo, 0, stdoutLength);
}
// Upload encoded video to Azure block blob storage
// Return
}
错误:当我尝试写入StandardInput时,我正在收到“管道已经结束”。但是我确信这段代码还有更多问题。
先谢谢你。