private AVVideoSettingsCompressed getVideoWriterSettings(nfloat bitrate, nfloat width, nfloat height) { var outputSettings = new AVVideoSettingsCompressed() { Height = (int)height, Width = (int)width, Codec = AVVideoCodec.H264, CodecSettings = new AVVideoCodecSettings() { AverageBitRate = (int)bitrate, VideoCleanAperture = new AVVideoCleanApertureSettings( new NSDictionary( AVVideo.CleanApertureWidthKey, new NSNumber(width), AVVideo.CleanApertureHeightKey, new NSNumber(height), AVVideo.CleanApertureVerticalOffsetKey, new NSNumber(10), AVVideo.CleanApertureHorizontalOffsetKey, new NSNumber(10) ) ) }, ScalingMode = AVVideoScalingMode.ResizeAspectFill }; return(outputSettings); }
void SetupAssetReaserWriterForVideo(AVAssetTrack videoTrack) { if (videoTrack == null) { return; } // Decompress to ARGB with the asset reader var decompSettings = new AVVideoSettingsUncompressed { PixelFormatType = CVPixelFormatType.CV32BGRA, AllocateWithIOSurface = null }; AVAssetReaderOutput output = new AVAssetReaderTrackOutput(videoTrack, decompSettings); assetReader.AddOutput(output); // Get the format description of the track, to fill in attributes of the video stream that we don't want to change var formatDescription = (CMVideoFormatDescription)videoTrack.FormatDescriptions.FirstOrDefault(); // Grab track dimensions from format description CGSize trackDimensions = formatDescription != null ? formatDescription.GetPresentationDimensions(false, false) : videoTrack.NaturalSize; // Grab clean aperture, pixel aspect ratio from format description AVVideoCodecSettings compressionSettings = null; if (formatDescription != null) { var cleanApertureDescr = (NSDictionary)formatDescription.GetExtension(CVImageBuffer.CleanApertureKey); var pixelAspectRatioDescr = (NSDictionary)formatDescription.GetExtension(CVImageBuffer.PixelAspectRatioKey); compressionSettings = CreateCodecSettingsFor(cleanApertureDescr, pixelAspectRatioDescr); } // Compress to H.264 with the asset writer var videoSettings = new AVVideoSettingsCompressed { Codec = AVVideoCodec.H264, Width = (int)trackDimensions.Width, Height = (int)trackDimensions.Height, CodecSettings = compressionSettings }; AVAssetWriterInput input = new AVAssetWriterInput(videoTrack.MediaType, videoSettings); input.Transform = videoTrack.PreferredTransform; assetWriter.AddInput(input); // Create and save an instance of ReadWriteSampleBufferChannel, // which will coordinate the work of reading and writing sample buffers videoSampleBufferChannel = new VideoChannel(output, input, transformer); }
void SetupAssetReaserWriterForVideo (AVAssetTrack videoTrack) { if (videoTrack == null) return; // Decompress to ARGB with the asset reader var decompSettings = new AVVideoSettingsUncompressed { PixelFormatType = CVPixelFormatType.CV32BGRA, AllocateWithIOSurface = null }; AVAssetReaderOutput output = new AVAssetReaderTrackOutput (videoTrack, decompSettings); assetReader.AddOutput (output); // Get the format description of the track, to fill in attributes of the video stream that we don't want to change var formatDescription = (CMVideoFormatDescription)videoTrack.FormatDescriptions.FirstOrDefault (); // Grab track dimensions from format description CGSize trackDimensions = formatDescription != null ? formatDescription.GetPresentationDimensions (false, false) : videoTrack.NaturalSize; // Grab clean aperture, pixel aspect ratio from format description AVVideoCodecSettings compressionSettings = null; if (formatDescription != null) { var cleanApertureDescr = (NSDictionary)formatDescription.GetExtension (CVImageBuffer.CleanApertureKey); var pixelAspectRatioDescr = (NSDictionary)formatDescription.GetExtension (CVImageBuffer.PixelAspectRatioKey); compressionSettings = CreateCodecSettingsFor (cleanApertureDescr, pixelAspectRatioDescr); } // Compress to H.264 with the asset writer var videoSettings = new AVVideoSettingsCompressed { Codec = AVVideoCodec.H264, Width = (int)trackDimensions.Width, Height = (int)trackDimensions.Height, CodecSettings = compressionSettings }; AVAssetWriterInput input = new AVAssetWriterInput (videoTrack.MediaType, videoSettings); input.Transform = videoTrack.PreferredTransform; assetWriter.AddInput (input); // Create and save an instance of ReadWriteSampleBufferChannel, // which will coordinate the work of reading and writing sample buffers videoSampleBufferChannel = new VideoChannel (output, input, transformer); }