Reputation: 3
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#.
Upvotes: 0
Views: 231
Reputation: 2105
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;
Upvotes: 4