1

我的 windows phone 应用程序需要从前置摄像头录制视频并通过 web 服务将其发送到服务器。

在这里,当我尝试从 录制视频时front-camera,我得到了mirror inverted video。表示前置摄像头录制 180 度旋转视频。

我认为可能唯一的解决方案是将录制的视频流向后旋转 180 度。

问题:

  • 还有其他解决方案可以通过前置摄像头录制正确的视频wp8吗?
  • 如果没有,如何将视频流旋转 180 度?任何c#API来做它..?

编辑:

这是我正在使用的代码:

XAML 代码VideoBrush

    <Canvas x:Name="CanvasLayoutRoot" RenderTransformOrigin="0.5 0.5"
            Width="{Binding ActualHeight, ElementName=LayoutRoot}"
            Height="{Binding ActualWidth, ElementName=LayoutRoot}"
            Margin="-160 0 0 0">
        <!--Background="Transparent"-->

        <Canvas.Background>
            <VideoBrush x:Name="videoBrush" />
        </Canvas.Background>
        <Canvas.RenderTransform>
            <RotateTransform x:Name="rt" />
        </Canvas.RenderTransform>

    </Canvas>

初始化相机

    public async void InitializeVideoRecorder()
    {
        try
        {
            if (videoCapture == null)
            {
                // below line of code will detect if "Front Camera" is available or not
                // if availble, then open it or it will open "Back Camera"

                videoCapture = await AudioVideoCaptureDevice.OpenAsync(
                    AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Front) ? CameraSensorLocation.Front : CameraSensorLocation.Back,
                    new Windows.Foundation.Size(640, 480));

                videoCapture.RecordingFailed += videoCapture_RecordingFailed;

                videoCapture.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, videoCapture.SensorRotationInDegrees);

                // Initialize the camera if it exists on the phone.
                if (videoCapture != null)
                {
                    videoBrush.SetSource(videoCapture);
                    if (!AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Front))
                    {
                        rt.Angle = videoCapture.SensorRotationInDegrees;
                    }
                    else
                    {
                        rt.Angle = -(videoCapture.SensorRotationInDegrees);
                    }
                }
                else
                {
                    MessageBox.Show("Unable to load Camera. Please try again later.", App.appName, MessageBoxButton.OK);
                    NavigationService.GoBack();
                }
            }
        }
        catch (Exception ex)
        {
            (new WebServices()).catchExceptions(ex);
            NavigationService.GoBack();
        }
    }

启动视频捕捉

    private async Task StartVideoRecording()
    {
        try
        {
            // Gets the application data folder
            StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
            StorageFolder transfersFolder = await (await applicationFolder.GetFolderAsync("Shared")).GetFolderAsync("Transfers");

            // Create the file specified in the application data folder
            videoFileName = selectedQue.response.template_id + "_" + selectedQue.response.id + "_" + selectedQue.response.invite_id +".mp4";
            StorageFile storageFile = await transfersFolder.CreateFileAsync(videoFileName, CreationCollisionOption.ReplaceExisting);

            // Open a file stream, ready to write video data
            randomAccessStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite);

            // Video recording to the specified stream
            await videoCapture.StartRecordingToStreamAsync(randomAccessStream);
            isRecordingStarted = true;

            //timer = "0:00";
            tbTimer.Text = "0:00";
            dt.Start();
        }
        catch (Exception ex)
        {
            (new WebServices()).catchExceptions(ex);
        }
    }
4

2 回答 2

0

经过24小时的努力,我终于通过以下解决方案解决了我的问题。

下面是通过旋转视频引起问题的代码行。

videoCapture.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, videoCapture.SensorRotationInDegrees);

这里 videoCapture 是 AudioVideoCaptureDevice 的对象

在使用前置摄像头时,我们需要反转cameraSensor.

videoCapture.SetProperty所以我在这行代码中使用了上面相同的代码(有问题),并做了一个微小的修改。正确的代码行如下。

videoCapture.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, -(videoCapture.SensorRotationInDegrees));

videoCapture.SensorRotationInDegrees我只是通过在它之前添加一个减号 (-) 来反转它。

希望这对大家有帮助..

于 2015-05-02T07:48:53.073 回答
0

这在过去对我有用,它只是一个条形码扫描仪应用程序,我编写了代码以满足功能要求。我把变换放在<VideoBrush>.

<Grid x:Name="ContentPanel" Margin="12,0,12,0">
    <Canvas x:Name="cam_canvas" Width="480" Height="480">                
        <Canvas.Background>
            <VideoBrush x:Name="cam_video_brush" Stretch="None">
                <VideoBrush.RelativeTransform>
                    <CompositeTransform Rotation="90" CenterX="0.5" CenterY="0.5" />
                </VideoBrush.RelativeTransform>
            </VideoBrush>
        </Canvas.Background>
    </Canvas>
</Grid>
于 2015-05-02T01:00:50.880 回答