[HttpGet] public IActionResult GetVideo(string filename) { string path = Path.Combine(_env.WebRootPath, "videos", filename); var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); return new FileStreamResult(stream, "video/mp4"); }
[HttpGet] public IActionResult GetVideo(string filename) { string path = Path.Combine(_env.WebRootPath, "videos", filename);
var ext = Path.GetExtension(filename).ToLowerInvariant();
var mime = ext switch
{
".mp4" => "video/mp4",
".mkv" => "video/x-matroska",
".webm" => "video/webm",
_ => "application/octet-stream"
};
var cmd = $"-i \"{path}\" -movflags frag_keyframe+empty_moov -f mp4 -frag_size 4096 -";
var ffmpeg = new ProcessStartInfo("ffmpeg", cmd)
{
RedirectStandardOutput = true,
UseShellExecute = false,
};
Response.RegisterForDispose(Process.Start(ffmpeg));
Response.Headers.Add("Accept-Ranges", "bytes");
return File(Response.Body, mime);
}