XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

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

Open lorismich opened this issue 4 years ago • 5 comments

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;
			}
			
		}
		
	}
}

CAMERA PAGE XAML

` <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>

</ContentPage>`

Expected Behavior

Video recorded it's like in preview mode

Actual Behavior

Video recorded it's rotated 90 degree

Basic Information

  • Version with issue: 1.2.0

  • Last known good version:

  • IDE:

  • Platform Target Frameworks: 29

    • iOS: not tested
    • Android: 10.0
    • UWP: not tested
  • Nuget Packages:

  • Affected Devices: Oneplus 5, Huawei Matetab 10.0

lorismich avatar Oct 07 '21 19:10 lorismich

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 avatar Oct 29 '21 20:10 GUOLDEV

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

GUOLDEV avatar Oct 29 '21 20:10 GUOLDEV

@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

bbhxwl avatar Nov 29 '21 04:11 bbhxwl

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

jastorgac avatar Jan 28 '22 17:01 jastorgac

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

frarcedev avatar Sep 11 '22 02:09 frarcedev