How do make a reduced size video using AVAssetWriter?

后端 未结 2 1459
灰色年华
灰色年华 2021-01-30 15:31

I would make reduced size video, maybe 50 pixel across and 75 pixels for length. Those are the physical dimension.

How do you set that? in the videosettings? I think

2条回答
  •  遇见更好的自我
    2021-01-30 15:54

    You need to set video codec parameters:

    NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [NSNumber numberWithInt:320], AVVideoCleanApertureWidthKey,
                                               [NSNumber numberWithInt:480], AVVideoCleanApertureHeightKey,
                                               [NSNumber numberWithInt:10], AVVideoCleanApertureHorizontalOffsetKey,
                                               [NSNumber numberWithInt:10], AVVideoCleanApertureVerticalOffsetKey,
                                                nil];
    
    
    NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                                 [NSNumber numberWithInt:3], AVVideoPixelAspectRatioHorizontalSpacingKey,
                                                 [NSNumber numberWithInt:3],AVVideoPixelAspectRatioVerticalSpacingKey,
                                                        nil];
    
    
    
    NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [NSNumber numberWithInt:960000], AVVideoAverageBitRateKey,
                                   [NSNumber numberWithInt:1],AVVideoMaxKeyFrameIntervalKey,
                                   videoCleanApertureSettings, AVVideoCleanApertureKey,
                                   //videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
                                   //AVVideoProfileLevelH264Main30, AVVideoProfileLevelKey,
                                   nil];
    
    
    
    
    
    NSString *targetDevice = [[UIDevice currentDevice] model];
    
    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   AVVideoCodecH264, AVVideoCodecKey,
                                   codecSettings,AVVideoCompressionPropertiesKey,
                                   [NSNumber numberWithInt:320], AVVideoWidthKey,
                                   [NSNumber numberWithInt:480], AVVideoHeightKey,
                                   nil];
    

提交回复
热议问题