Here its stated that I can record video using AudioVideoCaptureDevice
but there is no sample or help provided.
I need to do the following things:
- record the video into a stream DONE
- display a thumbnail of video recorded (can be a frame captured while video recording) DONE
- replay the video recorded DONE
- change resolution and type of camera (front/back) DONE
How to achieve this? Are there any samples? I am unable to find them. Please help me.
DONE
- record the video into a stream
- replay the video recorded
- change resolution and type of camera (front/back)
- display a thumbnail of video recorded (can be a frame captured while video recording)
NEW PROBLEMS
- front camera video is mirror inverted. I am able to change this while recording using transform but the actual video is still mirrored.
UPDATE
- calculate the size of the recording video and display it. Its not working. Stream.Size is giving random values.
Any thoughts on solving these?
For the problem of Displaying a Thumbnail of the video recording...there is an event called PreviewFrameAvailable on the AudioVideoCaptureDevice. I think if you setup this event handler it will tell you when the data is available to get a preview (image/thumbnail) of the video.
There are also 3 methods for grabbing a byte array of a preview image (GetPreviewBufferARGB, GetPreviewBufferY, GetPreviewBufferYCbCr). All three of these methods return a byte[] of the pixel data for the image in the corresponding format (ex: GetPreviewBufferARGB should return the raw bytes of a raw bitmap in ARGB format). After getting the byte array of the preview data you should be able to encode it as a PNG or JPEG or whatever compressed image format you prefer. Best of luck.
The basics of using the Windows Phone 8 camera are covered here...
Advanced photo capture for Windows Phone 8
How to save a picture captured with the new camera’s API in the camera roll in Windows Phone 8
How to set video record resolution in Windows Phone 8
How to set advanced properties for video recording in WP8
Note: there are issues when getting the supported resolutions of the front camera on some Lumia devices
I solved the problem of mirror inverted video recording through Front-Camera
:
the one line that solved my problem is:
//here videoCapture is AudioVideoCaptureDevice object
videoCapture.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, -90);
Full Code:
XAML code
<Canvas x:Name="CanvasLayoutRoot" RenderTransformOrigin="0.5 0.5"
Width="{Binding ActualHeight, ElementName=LayoutRoot}"
Height="{Binding ActualWidth, ElementName=LayoutRoot}"
Margin="-160 0 0 0">
<Canvas.RenderTransform>
<RotateTransform x:Name="rt" />
</Canvas.RenderTransform>
<Canvas.Background>
<VideoBrush x:Name="videoBrush" />
</Canvas.Background>
</Canvas>
BackEnd C# code
// in any specific method or event handler write
// the below code while initializing the Front camera
private AudioVideoCaptureDevice videoCapture = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Front, new Windows.Foundation.Size(640, 480));
videoCapture.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, -90);
rt.Angle = -90;
videoBrush.SetSource(videoCapture);
This piece of code helped me after tens of efforts..!