xamarinxamarin.iosavcapturemoviefileoutput

Set the Video Codec to H.264 when using an AVCaptureMovieFileOutput instance? Xamarin


Need help setting the video codec to H.264 when using an AVCaptureMovieFileOutput instance.

Looking at the Apple Docs I see that they support a struct of type AVVideoCodecType, however, I'm not seeing this in the Xamarin.iOS Docs.

Help would be much appreciated as I don't want to have to rewrite the Video Capture logic to use AVAssetWriter.


Solution

  • So, I found the solution and here it is for those who come after me.

    Step 1: Create a AVCaptureMovieFileOutput instance.

    var output = new AVCaptureMovieFileOutput();
    

    Step 2: Create a NSDictionary where you list the keys and values of the Movie's Output settings you want.

    var outputSettings = new NSDictionary(AVVideoCodecType.H264, AVVideo.CodecKey);
    

    Step 3: Set the output Settings

    output.SetOutputSettings(outputSettings, output.ConnectionFromMediaType(AVMediaType.Video))
    

    The trick here is to call ConnectionFromMediaType Method passing in the MediaType on your AVCaptureMovieFileOutput instance which returns an AVCaptureConnection.