2017-03-17 95 views
0

我正在使用C#(UWP,Windows 10 IoT Core)將視頻流(流入網絡攝像頭)並將其流式傳輸到桌面。儘管我發現一些使用UWP在Java(用於Rasp)和客戶端執行服務器端實現的項目中,我找不到任何有關C#中服務器端編程的項目。使用Raspberry Pi和C的實時視頻流#

另外,是否真的有可能使用C#進行實時流式服務器端編程,因爲此鏈接並非如此。 View the Microsoft Link

任何幫助將深表謝意。

Regards, T.S.

+0

你有沒有檢查[這個項目](https://github.com/davetoland/VideoSocketServer)? –

+0

謝謝,這會做 –

回答

0

即使我發現了一些項目在做Java的服務器端實現(銼)和客戶端使用UWP我找不到關於C#服務器端編程的任何項目。

還有另一個項目我已經編碼和測試成功。如果它可以幫助你,你可以有一個參考。

在MyVideoServer應用程序中,重要的是獲取視頻的相機ID和預覽幀。 previewFrame = await MyMediaCapture.GetPreviewFrameAsync(videoFrame);然後通過streamSocketClient將視頻流發送到客戶端。 await streamSocketClient.sendBuffer(buffer);

public MainPage() 
    { 
     this.InitializeComponent(); 
     InitializeCameraAsync(); 
     InitSocket(); 
    } 

    MediaCapture MyMediaCapture; 
    VideoFrame videoFrame; 
    VideoFrame previewFrame; 
    IBuffer buffer; 

    DispatcherTimer timer; 
    StreamSocketListenerServer streamSocketSrv; 
    StreamSocketClient streamSocketClient; 

    private async void InitializeCameraAsync() 
    { 
     var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); 
     DeviceInformation cameraDevice = allVideoDevices.FirstOrDefault(); 
     var mediaInitSettings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; 
     MyMediaCapture = new MediaCapture(); 

     try 
     { 
      await MyMediaCapture.InitializeAsync(mediaInitSettings); 
     } 
     catch (UnauthorizedAccessException) 
     { 

     } 

     PreviewControl.Height = 180; 
     PreviewControl.Width = 240; 
     PreviewControl.Source = MyMediaCapture; 

     await MyMediaCapture.StartPreviewAsync(); 
     videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, 240, 180, 0); 
     buffer = new Windows.Storage.Streams.Buffer((uint)(240 * 180 * 8)); 
    } 

然後密鑰服務器代碼試圖創建一個服務器,並通過在InitSocket功能套接字通信連接的客戶端。 StreamSocketListenerServer應該創建爲一個對象並啓動。同時,服務器IP端口被設置。 streamSocketSrv = new StreamSocketListenerServer(); await streamSocketSrv.start("22333");最後但並非最不重要的一點,Timer_Tick會每隔100ms向客戶端發送視頻流。

private async void InitSocket() 
    { 
     streamSocketSrv = new StreamSocketListenerServer(); 
     await streamSocketSrv.start("22333"); 

     streamSocketClient = new StreamSocketClient(); 

     timer = new DispatcherTimer(); 
     timer.Interval = TimeSpan.FromMilliseconds(100); 
     timer.Tick += Timer_Tick; 
     timer.Start(); 
    } 

下面,你可以在樹莓派部署MyVideoServer應用3. enter image description here 然後,你可以在PC上部署MyVideoClient應用。然後輸入Raspberry Pi 3 IP地址並點擊連接按鈕。視頻流將顯示在應用程序上。 enter image description here

這是sample代碼,您可以參考。

+0

非常感謝,我會嘗試:-) –

+0

我可以添加音頻到這個解決方案嗎?如果我能如何做到這一點? –