I'm using .NNET Core 2.0 to develop my Web API in C# and I want to forward an MJEPG stream of images with HTTP GET request. I have created the multipart content but when I check the response I can only see the first image and no playing of video is happening.
I have tried to even use an mjpeg external file that I know it works but it does the same thing, it displays the first image frame only.
This is the Controller Get Request:
// GET: api/<controller> [HttpGet] public IActionResult Get() { var path = Path.Combine( Directory.GetCurrentDirectory(),"LVUpload", "test.mjpeg"); var stream = new FileStream(path, FileMode.Open); MultipartResult multipartResult = new MultipartResult { ContentType = "image/jpeg", Stream = stream }; return multipartResult; }
And the multipart implementation:
public class MultipartContent { public string ContentType { get; set; } public Stream Stream { get; set; } } public class MultipartResult : MultipartContent, IActionResult { private readonly System.Net.Http.MultipartContent content; public MultipartResult(string subtype = "x-mixed-replace", string boundary = "canonliveview") { if (boundary == null) { this.content = new System.Net.Http.MultipartContent(subtype); } else { this.content = new System.Net.Http.MultipartContent(subtype, boundary); } } public async Task ExecuteResultAsync(ActionContext context) { if (Stream != null) { var content = new StreamContent(Stream); if (ContentType != null) { content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentType); } this.content.Add(content); } context.HttpContext.Response.ContentLength = content.Headers.ContentLength; context.HttpContext.Response.ContentType = content.Headers.ContentType.ToString(); await content.CopyToAsync(context.HttpContext.Response.Body); }
Can someone help on how can I do this with .Net Core 2.0? I know it's possible with full .Net framework but I have to use latest .Net Core.
I'm not sure if there is a way maybe to encode the stream images to another video type, like x264.