简体   繁体   中英

How to carry out live camera stream for metro apps c#

I have spent over a month now looking for a solution on how to transmit live camera stream from a metro app to a publishing server which I implemented in form of a web socket ashx handler. Apparently, all resources I have found online states that I cannot get access to the live camera frames with c#, it was said that this could only be achieved with native C++.

I wrote a hack to override the WriteAsync method IRandmomAccessStream class in the Windows.Storage.Streams namespace. I believe this method gets called each time a new sequence of bytes is to be written from the recording camera to the stream buffer. I overrode this write method to send those sequence of bytes to the manually created web socket server which worked fine but the video was always corrupted at the receiving end.

I believe this is due to some missing metadata/fragmented frames as the stream is in h.264. I want to ask if anyone has an idea of a library that can transcode the camera feed in real-time for live streaming in pure c#.

you can use the MediaCapture API https://msdn.microsoft.com/en-us/library/windows/apps/mt280228.aspx

var properties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
var frame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)properties.Width, (int)properties.Height);
var previewFrame = await _mediaCapture.GetPreviewFrameAsync(frame);
var previewBitmap = frame.SoftwareBitmap;
frame.Dispose();
frame = null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM