AVAssetWriter How to create mov video with no comp

2019-01-24 18:22发布

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

3条回答
Anthone
2楼-- · 2019-01-24 19:16

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).

查看更多
甜甜的少女心
3楼-- · 2019-01-24 19:23

that key is not for disabling compression, is to specify specific compression values for certain codecs, like jpg or h264 .I.e.

    [videoSettings addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
                                                 AVVideoCodecH264, AVVideoCodecKey,
                                                 nil]];

        NSMutableDictionary* videoCompressionSettings = [NSMutableDictionary dictionary];

        if ([[Preferences instance] recordingH264Keyframes] > 0) {
            [videoCompressionSettings addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
                                                     [NSNumber numberWithInt:[[Preferences instance] recordingH264Keyframes]], AVVideoMaxKeyFrameIntervalKey,
                                                     nil]];
        }

        if ([[Preferences instance] recordingH264Bitrate] > 0) {
            [videoCompressionSettings addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
                                                     [NSNumber numberWithInt:[[Preferences instance] recordingH264Bitrate]*1000], AVVideoAverageBitRateKey,
                                                     nil]];
        }

        if ([videoCompressionSettings count]) {
            [videoSettings addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:videoCompressionSettings,AVVideoCompressionPropertiesKey,nil]];
        }
查看更多
劫难
4楼-- · 2019-01-24 19:23

The ProRes4444 video codec is the closest thing Apple supplies to an uncompressed codec. This codec is not available on iOS for writing video content only OS X.

It is not possible on iOS to export video content uncompressed.

查看更多
登录 后发表回答