Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recording (or transforming after recording) video at non-standard size in Windows Phone 8

I am trying to capture MP4 video at a specific resolution in Windows Phone 8 (to be specific, 480x480). I know that I can't use sizes other than the presets, and 480x480 is not a preset. How do I transform a captured video (such as 640x480) and crop the top and bottom to make it 480x480? Any free or open source libraries (that run on Windows Phone) are welcome. Please don't answer with answers such as 'use an external server', I need an on-device solution.

like image 325
Can Poyrazoğlu Avatar asked Jun 18 '13 10:06

Can Poyrazoğlu


1 Answers

Use the Windows.Phone.Media.Capture APIs and the AudioVideoCaptureDevice class

Second parameter for AudioVideoCaptureDevice.OpenAsync - see this link - is the resolution. And you can get the resolutions using AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensor)

EDIT: To set custom resolutions try AudioVideoCaptureDevice.SetCaptureResolutionAsync

EDIT 2: You could try something like the following to transform recorded video: (can't find where i got the code from soz to author!)

StorageFolder isoStore = await ApplicationData.Current.LocalFolder.GetFolderAsync("Shared");
        var file = await isoStore.CreateFileAsync("foos1.wmv", CreationCollisionOption.ReplaceExisting);
        using (var s = await file.OpenAsync(FileAccessMode.ReadWrite))
        {
            Windows.Foundation.Size resolution = new Windows.Foundation.Size(640, 480);
            avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).Last());

            VideoBrush videoRecorderBrush = new VideoBrush();
            videoRecorderBrush.SetSource(avDevice);

            viewfinderRectangle.Fill = videoRecorderBrush;

            await avDevice.StartRecordingToStreamAsync(s);

            Thread.Sleep(30000);

            await avDevice.StopRecordingAsync();
        }


        new MediaPlayerLauncher()
        {
            Media = new Uri(file.Path, UriKind.Relative),
        }.Show();
like image 162
Paul Zahra Avatar answered Nov 20 '22 11:11

Paul Zahra