AVAssetWriter How to create mov video with no compression?

wawanopoulos picture wawanopoulos · Jul 2, 2012 · Viewed 8.5k times · Source

I'am creating a video from an array of images. The purpose of my work is to create a .mov video with no compression. I have see in developer library that it exist a key "AVVideoCompressionPropertiesKey" but I don't know how to specify no compression with this key.

Could you help me please?

Here is my sample code :

NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [NSNumber numberWithInt:320], AVVideoCleanApertureWidthKey,
                                            [NSNumber numberWithInt:480], AVVideoCleanApertureHeightKey,
                                            [NSNumber numberWithInt:10], AVVideoCleanApertureHorizontalOffsetKey,
                                            [NSNumber numberWithInt:10], AVVideoCleanApertureVerticalOffsetKey,
                                            nil];

NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithInt:960000], AVVideoAverageBitRateKey,
                               [NSNumber numberWithInt:1],AVVideoMaxKeyFrameIntervalKey,
                               videoCleanApertureSettings, AVVideoCleanApertureKey,
                               nil];


NSDictionary *videoOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey,codecSettings,AVVideoCompressionPropertiesKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey,
                                     [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil];

self.videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoOutputSettings];

Answer

Steve McFarlin picture Steve McFarlin · Jul 4, 2012

Try using AVVideoCodecJPEG with the AVVideoQualityKey value set to a NSNumber of 1.0. Another method is to specify H264, set the bit rate to something very very high, and specify a key frame interval of 1 (i.e. all key frames).