AVAssetWriter How to create mov video with no compression?

ぃ、小莉子 提交于 2019-12-18 04:23:33

问题


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

回答1:


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




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/11296642/avassetwriter-how-to-create-mov-video-with-no-compression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!