0

I need to transcode video streaming from MJPEG to MP4, AVI or MKV format. Is it possible to do with ffmpeg or vlc? I am developing UWP Win10 app and there aren't many packages for this.

Edit: my code

        VLCPreview.Source = "http://Admin:123456@192.168.0.21:6021/cgi-bin/cmd/encoder?GET_STREAM";

   /cmd/encoder?GET_STREAM

        try
        {


                            HttpClientHandler aHandler = new HttpClientHandler();
                            aHandler.Credentials = new NetworkCredential("Admin", "123456");
                            aHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;

                            HttpClient aClient = new HttpClient(aHandler);
                            aClient.DefaultRequestHeaders.ExpectContinue = false;
                                                                                    //url get stream o web.Source
                            HttpResponseMessage response = await aClient.GetAsync("http://192.168.0.21:6021/cgi-bin/cmd/encoder?GET_STREAM", HttpCompletionOption.ResponseHeadersRead);//urlLinkToOnlineStream

                            Stream stream = await response.Content.ReadAsStreamAsync();
                             IInputStream inputStream = stream.AsInputStream();
                             ulong totalBytesRead = 0;
                             while (true)
                             {
                                 // Read from the web.
                                 IBuffer buffer = new Windows.Storage.Streams.Buffer(4096);
                                 buffer = await inputStream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);
                                 if (buffer.Length == 0)
                                 {
                                     break;
                                 }
                                 totalBytesRead += buffer.Length;
                                 await fileStream.WriteAsync(buffer);
                                Debug.WriteLine("TotalBytesRead: {0:f}", totalBytesRead);

                                if (StopRec == true) { break;}
            }

            transcode(destinationFile, sampleFileVidTranscoded);

                              inputStream.Dispose();

                            fileStream.Dispose();  
cahernanz
  • 11
  • 4

1 Answers1

3

Firstly, uwp app has its own namespace Windows.Media.Transcoding for transcoding video. For how to transcode media files please reference this article. And the official sample provide examples for transcoding media files to MP4,WMI and AVI that you can reference.

Secondly, For FFmpeg, it is a free, open-source multimedia framework that includes a set of tools which can be used by end users for transcoding, streaming, and playing, as well as a set of libraries for developers to use in applications. So you could use it for transcoding. Fortunately, currently there is a FFmpeg library for uwp called "FFmpegInterop". You can try to use it by the Nuget package FFmpegInterop.UWP 1.0.3, and more details please reference Using FFmpeg in Windows Applications.

For VLC, there is also a package for uwp, it is VLC.MediaElement. You could access this package by reference this NuGet package.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • Thanks for your quick reply!. I used Windows.Media.Transcoding, but when it creates MediaEncodingProfile , it crashes throwing the following exception: System.TypeloadException {"Requested Windows Runtime type 'Windows.Media.MediaProperties.MediaEncodingProfile' is not registered.":"Windows.Media.MediaProperties.MediaEncodingProfile"}. Any ideas?, I searched and I didn´t fount anything. – cahernanz Mar 10 '17 at 12:13
  • @cahernanz please provide your code snippet. And please ensure you have import the relative name space. Additionally, accepted an answer and open a new thread will be much better since this is a new issue. – Sunteen Wu Mar 13 '17 at 01:27
  • Furthermore, the code i edited, it creates the uncompressed file that weights "x" MBs, but i can´t play It. I need to "pass" though ffmpeg.exe to play it correctly. Any ideas for solving it?. Thanks in advance. – cahernanz Mar 14 '17 at 15:20
  • So, if my video is in mjpeg format, there is many problems to play it. I cant play with vlc. I think i can´t convert from mjpeg to another formats using mediaTranscoding, insn´t it? – cahernanz Mar 14 '17 at 23:38