xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.59k stars 474 forks source link

[Bug] Video recorded in portraid mode it's 90 degrees rotated #1651

Open lorismich opened 2 years ago

lorismich commented 2 years ago

Description

When recording a video or photo in portrait mode, the image is reversed at 90 degrees. Image recording is done as a landscape mode.

Steps to Reproduce

  1. CameraPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Essentials;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Xamarin.Forms.PlatformConfiguration;
using MYAPP.Services;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.CommunityToolkit.Core;

namespace MYAPP.Views
{
    public partial class CameraPage : ContentPage
    {

        public CameraPage()
        {
            InitializeComponent();

            Title = "Camera";
            cameraView.CaptureMode = CameraCaptureMode.Video;
            cameraView.VideoStabilization = true;

        }

        void DoCameraThings_Clicked(object sender, EventArgs e)
        {

            cameraView.Shutter();
            doCameraThings.Text = cameraView.CaptureMode == CameraCaptureMode.Video
                ? "Stop Recording"
                : "Snap Picture";

        }

        void CameraView_OnAvailable(object sender, bool e)
        {
            doCameraThings.IsEnabled = e;
        }

        void CameraView_MediaCaptured(object sender, MediaCapturedEventArgs e)
        {

            switch (cameraView.CaptureMode)
            {
                default:
                case CameraCaptureMode.Default:
                case CameraCaptureMode.Photo:

                    break;
                case CameraCaptureMode.Video:
                    FileMediaSource file = e.Video.File;

                    DependencyService.Get<IStorage>().exportFileMediaSource(file, "asd.mp4");

                    double rotate = e.Rotation;
                    doCameraThings.Text = "Registra";

                    DependencyService.Get<IToast>().ShortAlert("Video salvato");

                    break;
            }

        }

    }
}

2. CAMERA PAGE XAML

`<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MYAPP.Views.CameraPage" xmlns:vm="clr-MYAPP.ViewModels" xmlns:xct="http://xamarin.com/schemas/2020/toolkit" xmlns:local="clr-namespace:MYAPP.Views;assembly=CustomView" Title="{Binding Title}">

<AbsoluteLayout>
    <StackLayout Orientation="Vertical" Spacing="0" AbsoluteLayout.LayoutFlags="All"
                     AbsoluteLayout.LayoutBounds="0,0,1,1">

        <local:CameraPreview Camera="Rear"
                         HorizontalOptions="FillAndExpand"
                         VerticalOptions="FillAndExpand" />

        <xct:CameraView
            Grid.Column="0"
            x:Name="cameraView"
            CaptureMode="Photo"
            FlashMode="Off"                  
            MediaCaptured="CameraView_MediaCaptured"
            OnAvailable="CameraView_OnAvailable"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand" />

    </StackLayout>

    <Button
        HorizontalOptions="CenterAndExpand"
        VerticalOptions="End"
        WidthRequest="500"    
        HeightRequest="70"
        CornerRadius="15"
        AbsoluteLayout.LayoutFlags="PositionProportional"
        AbsoluteLayout.LayoutBounds="0.5,1,AutoSize,AutoSize"
        Margin="0, 0, 0, 30"
        x:Name="doCameraThings"
        Clicked="DoCameraThings_Clicked"
        IsEnabled="False"
        Text="Registra" />

</AbsoluteLayout>

`

Expected Behavior

Video recorded it's like in preview mode

Actual Behavior

Video recorded it's rotated 90 degree

Basic Information

GUOLDEV commented 2 years ago

Hi @lorismich I think #1524 fixes the issue that you are experiencing. It would be great if you could test and let me know if works or not for your use case 👍

GUOLDEV commented 2 years ago

@pictos @jfversluis I think it is the same error fixed on #1524, but just in case could you please add CameraView label?

bbhxwl commented 2 years ago

@pictos @jfversluis I think it is the same error fixed on #1524, but just in case could you please add CameraView label?

For Android, I haven't solved it

jastorgac commented 2 years ago

I just updated to 2.0.0 and this bugs still seems to be around on Android.

frarcedev commented 2 years ago

In my case I got a personal solution for this issue in the CameraFragment.android.cs in Views/CameraView/Android. The method GetCaptureOrientation set a frontOffset when you are using a front camera to record videos, but in my opinion usually the front camera is in the top center of the device dont need apply 90 degree. image

I changed 90 degree to 0 when it's using a front camera. That worked for me. image