0

I am trying to create a preview of my rtmp stream. But RTMP playback occupies the bandwidth as source, I want to do mjpeg streaming using ffmpeg and c#. Is it possible to do?

I am trying to create a webpage where users can monitor the stream. For this I dont need to use RTMP url to watch as it needs more and more bandwidth.

So, my idea is to capture images and show them in sequence rate controlled at 1 frame per second. In this way users can monitor.

I have tried various methods like using mjpeg

ffmpeg.exe -i renditiontest.mp4 -c:v mjpeg -q:v 31 -an sample.avi

Now, output file is getting generated. But, it is occupying harddisk.

So, next way is to create images overwriting previous images

ffmpeg.exe -y -i renditiontest.mp4 -f image2 -updatefirst 1 sample2.jpg

Now, I tried creating a stream which will continously read the image and write it as response in C#.

using (WebClient webClient = new WebClient())
                {
                    string url = "http://localhost/probe_VOD/mjpg/sample2.jpg";
                    var memoryStream = new MemoryStream(webClient.DownloadData(url));

                    response.Headers.AcceptRanges.Add("bytes");
                    response.StatusCode = HttpStatusCode.OK;
                    response.Content = new StreamContent(memoryStream);
                    //response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("render");
                    //response.Content.Headers.ContentDisposition.FileName = "sample.jpg";
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/x-mixed-replace; boundary=myboundary");
                    response.Content.Headers.ContentLength = memoryStream.Length;
                }
                return response; 

Please let me know how do I acheive this.

RecklessSergio
  • 806
  • 3
  • 10
  • 34
  • Yes it is. Pretty much everything is possible if you try hard enough. Would you care to show us what you _have_ tried so far? – ProgrammingLlama Dec 19 '17 at 07:55
  • What do you mean with "preview"? Stream or stream not, there is no "preview". How do you want to use ffmpeg? As Streaming Server and C# as client? This question is really much to vague. – Fildor Dec 19 '17 at 07:55
  • @Fildor, Sorry for the delay. I have edited my question. Hope it is clear – RecklessSergio Dec 20 '17 at 11:10
  • I'd try going for RT**S**P / [RTP](https://www.codeproject.com/Articles/85763/C-NET-RTP-MJPEG-Player) . I don't know if there are ready-to-go libs for that but it's also not very complicated to implement that parts you need. Also see https://stackoverflow.com/a/31705978/982149 – Fildor Dec 20 '17 at 12:03

0 Answers0