3

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?

Milan Aggarwal
  • 5,104
  • 3
  • 25
  • 54

3 Answers3

3

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.

Strifex
  • 832
  • 1
  • 7
  • 16
  • Sorry No, I've only worked briefly with the rear camera so far. Best of Luck to you! – Strifex Jul 31 '13 at 15:21
  • btw do you know how to display the recorded video size? randomaccessstream.size is throwing random values for Nokia devices, works well in htc. – Milan Aggarwal Aug 01 '13 at 10:07
1

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

Community
  • 1
  • 1
Neil Turner
  • 2,712
  • 2
  • 18
  • 37
  • They dont use AudioVideoCaptureDevice and there is no sample for front camera. – Milan Aggarwal Jul 29 '13 at 05:16
  • I've updated the links - and you're right, there isn't much on the front camera specifically but once the `CameraSensorLocation.Front` is specified, the regular camera API applies. Also, one question at a time :) – Neil Turner Jul 29 '13 at 18:31
  • Thanks for the response. But now only one problem remains. Front camera recording is mirror inverted. Trying to crack that. – Milan Aggarwal Jul 30 '13 at 10:55
  • @MilanAggarwal did you find any solution for "Front camera records mirror inverted video"..? I'm facing the same issue and unable to find solution. – Keval Langalia May 01 '15 at 08:53
  • Actually I didnt, for now I am just rotating the frame, so that the recording person doesn't see the inversion. While playback using the inbuilt media player, inversion is observed. – Milan Aggarwal May 01 '15 at 08:57
  • ohkay.. but actually i'm not going to play the video in the app instead need to send it to server..! :/ can you answer this: http://stackoverflow.com/questions/29984325/rotate-video-stream-wp8 anyway, thanks for quick response. – Keval Langalia May 01 '15 at 09:18
  • @MilanAggarwal I found the solution for mirror inverted video recording by `front-camera`. check my answer in this post. kudos.. – Keval Langalia May 02 '15 at 07:31
0

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..!

Keval Langalia
  • 1,762
  • 1
  • 16
  • 29