C# 是否记录用户上传的视频流?
目标:我正在创建一个视频共享网站。我想编码一个用户上传的视频流到mp4。(我假设这反过来也会验证用户上传的是视频文件而不是exe。) 当前代码:C# 是否记录用户上传的视频流?,c#,asp.net-mvc,ffmpeg,C#,Asp.net Mvc,Ffmpeg,目标:我正在创建一个视频共享网站。我想编码一个用户上传的视频流到mp4。(我假设这反过来也会验证用户上传的是视频文件而不是exe。) 当前代码: [HttpPost] public async Task<ActionResult> Upload(HttpPostedFileBase video) { using (var ffmpeg = new Process()) { ffmpeg.StartInfo
[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
}
[HttpPost]
公共异步任务上载(HttpPostedFileBase视频)
{
使用(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=新字节[video.InputStream.Length];
等待video.InputStream.ReadAsync(缓冲区,0,缓冲区,长度);
等待ffmpeg.StandardInput.BaseStream.WriteAsync(buffer,0,buffer.Length);
var stdoutLength=Convert.ToInt32(ffmpeg.StandardOutput.BaseStream.Length);
var encodedVideo=新字节[stdoutLength];
等待ffmpeg.standardpoutput.BaseStream.ReadAsync(encodedVideo,0,stdoutLength);
}
//将编码视频上载到Azure block blob存储
//返回
}
错误:当前我在尝试写入StandardInput时收到“管道已结束”。然而,我确信这段代码还有更多的问题
提前谢谢你