0

我需要将视频流从 MJPEG 转码为 MP4、AVI 或 MKV 格式。可以用ffmpeg或vlc吗?我正在开发 UWP Win10 应用程序,并且没有很多包。

编辑:我的代码

        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();  
4

1 回答 1

3

首先,uwp 应用程序有自己的名称空间Windows.Media.Transcoding用于转码视频。有关如何转码媒体文件,请参考这篇文章官方示例提供了将媒体文件转码为的示例MP4,您可以参考。WMIAVI

其次,对于 FFmpeg 来说,它是一个免费的开源多媒体框架,其中包括一组可供最终用户用于转码、流式传输和播放的工具,以及一组供开发人员在应用程序中使用的库。所以你可以用它来转码。幸运的是,目前有一个用于 uwp 的 FFmpeg 库,名为“FFmpegInterop”。您可以尝试通过 Nuget 包FFmpegInterop.UWP 1.0.3使用它,更多详细信息请参考在 Windows 应用程序中使用 FFmpeg

对于 VLC,还有一个用于 uwp 的包,它是VLC.MediaElement。您可以通过引用此 NuGet 包来访问此包

于 2017-03-09T07:02:35.713 回答