在 UWP 中转码视频 [英] Transcoding video in UWP
问题描述
我需要将视频流从 MJPEG 转码为 MP4、AVI 或 MKV 格式.是否可以使用 ffmpeg 或 vlc?我正在开发 UWP Win10 应用程序,并且没有很多包.
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.
我的代码
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();
推荐答案
首先,uwp 应用有自己的命名空间 Windows.Media.Transcoding
用于视频转码.有关如何转码媒体文件,请参考 这篇文章.而官方示例 提供了转码媒体文件的示例到 MP4
、WMI
和 AVI
可以参考.
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.
其次,对于 FFmpeg,它是一个免费的开源多媒体框架,其中包括一组可供最终用户用于转码、流式传输和播放的工具,以及一组供开发人员在应用程序中使用的库.所以你可以用它来进行转码.幸运的是,目前有一个用于 uwp 的 FFmpeg 库,名为FFmpegInterop".您可以尝试通过 Nuget 包 FFmpegInterop.UWP 1.0.3 使用它,更多详情请参考 在 Windows 应用程序中使用 FFmpeg.
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.
对于 VLC,还有一个用于 uwp 的包,它是 VLC.MediaElement.你可以通过参考这个NuGet包来访问这个包.
For VLC, there is also a package for uwp, it is VLC.MediaElement. You could access this package by reference this NuGet package.
这篇关于在 UWP 中转码视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!