2017-03-07 164 views
0

我需要將視頻流從MJPEG轉碼爲MP4,AVI或MKV格式。是否可以使用ffmpeg或vlc?我正在開發UWP Win10應用程序,並沒有太多的軟件包。在UWP中轉碼視頻

編輯:我的代碼

 VLCPreview.Source = "http://Admin:[email protected]: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(); 
+0

您確定可以使用ffmpeg,但您也應該嘗試更好地編寫您的問題。 –

回答

1

首先,UWP應用對視頻轉碼自己的命名空間Windows.Media.Transcoding。有關如何轉碼媒體文件,請參閱this articleofficial sample提供了將媒體文件轉碼爲MP4WMIAVI的示例,您可以參考該文件。其次,對於FFmpeg,它是一個免費的開放源代碼多媒體框架,其中包括一組工具,可供最終用戶使用,用於轉碼,,流媒體和播放,以及一組庫開發人員用於應用程序。所以你可以使用它進行轉碼。幸運的是,目前有一個名爲「FFmpegInterop」的uwp FFmpeg庫。您可以嘗試使用Nuget包FFmpegInterop.UWP 1.0.3,更多詳細信息請參考Using FFmpeg in Windows Applications

對於VLC,還有一個uwp包,它是VLC.MediaElement。您可以通過參考this NuGet package訪問該軟件包。

+0

感謝您的快速回復!我用Windows.Media.Transcoding,但是當它創建MediaEncodingProfile,它崩潰拋出了以下異常:「請求的Windows運行時類型‘Windows.Media.MediaProperties.MediaEncodingProfile’未註冊」 System.TypeloadException {:「Windows.Media。 MediaProperties.MediaEncodingProfile「}。任何想法?,我搜索,我沒有任何東西。 – cahernanz

+0

@cahernanz請提供您的代碼片段。並請確保您已導入相關名稱空間。此外,接受答案並打開一個新線程會更好,因爲這是一個新問題。 –

+0

此外,我編輯的代碼,它創建的權重「x」MB的未壓縮文件,但我不能播放它。我需要通過ffmpeg.exe來正確播放它。任何想法解決它?提前致謝。 – cahernanz