Xamarin.Forms Q720p Video Recording

Universal Camera 276 Reputation points
2022-06-08T16:39:03.763+00:00

I have a MediaRecorder that captures High Quality Video. I want it to lower quality to VGA, 720p, 480p etc. I used

		mediaRecorder.SetMaxFileSize((long)(10e6));  
		//mediaRecorder.SetMaxDuration(10000);  
		mediaRecorder.SetAudioSource(AudioSource.Mic);  
		mediaRecorder.SetVideoSource(VideoSource.Surface);  
		mediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);  
		mediaRecorder.SetOutputFile(fileName.AbsolutePath);  
		mediaRecorder.SetVideoEncodingBitRate(10000000);  
		mediaRecorder.SetVideoFrameRate(30);  
		mediaRecorder.SetVideoSize(videoSize.Width, videoSize.Height);  
		mediaRecorder.SetVideoEncoder(VideoEncoder.H264);  
		mediaRecorder.SetAudioEncoder(AudioEncoder.Aac);  
		int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation;  
		int orientation = ORIENTATIONS.Get(rotation);  
		mediaRecorder.SetOrientationHint(orientation);  
		mediaRecorder.Info += MediaRecorder_Info;  
		mediaRecorder.RoutingChanged += MediaRecorder_RoutingChanged;  

//these two lines cause Exception...Removing these two lines executes with High Quality video

                    CamcorderProfile cpVGA = CamcorderProfile.Get(CamcorderQuality.Vga);  
		mediaRecorder.SetProfile(cpVGA);  

                    mediaRecorder.Prepare();  

I have also tried CamcorderQuality.Q720p. When I execute the above I get

Java.Lang.RuntimeException: 'Unknown camcorder profile quality'

Any help will be GREAT!!!!

Developer technologies | .NET | Xamarin
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-06-20T07:23:22.75+00:00

    Hello,

    Did you use the sample repo https://github.com/xamarin/monodroid-samples/tree/main/android5.0/Camera2VideoSample?

    If so, I've tested the sample and make it usable.

    You could modify your mediarecoder part as the following code:

       mediaRecorder.SetAudioSource (AudioSource.Mic);  
       mediaRecorder.SetVideoSource (VideoSource.Surface);  
       mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.Q720p));  
       mediaRecorder.SetOutputFile(GetVideoFile(Activity).AbsolutePath);  
       int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation;  
       int orientation = ORIENTATIONS.Get (rotation);  
       mediaRecorder.SetOrientationHint (orientation);  
       mediaRecorder.Prepare ();  
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.