Output Video Size Huge Using Hevc Encoder on iOS

Output Video Size Huge Using HEVC Encoder on iOS

Have you tried to specify the bitrate, etc.?
As below:

NSUInteger bitrate = 50 * 1024 * 1024;  // 50 Mbps
NSUInteger keyFrameInterval = 30;
NSString *videoProfile = AVVideoProfileLevelH264HighAutoLevel;
NSString *codec = AVVideoCodecH264;
if (@available(iOS 11, *)) {
videoProfile = (NSString *)kVTProfileLevel_HEVC_Main_AutoLevel;
codec = AVVideoCodecTypeHEVC;
}

NSDictionary *codecSettings = @{AVVideoAverageBitRateKey: @(bitrate),
AVVideoMaxKeyFrameIntervalKey: @(keyFrameInterval),
AVVideoProfileLevelKey: videoProfile};
NSDictionary *videoSettings = @{AVVideoCodecKey: codec,
AVVideoCompressionPropertiesKey: codecSettings,
AVVideoWidthKey: @((NSInteger)resolution.width),
AVVideoHeightKey: @((NSInteger)resolution.height)};

AVAssetWriterInput *videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
...

As far as I understand, with the same bitrate, the file size should be the same for H264 and HEVC, but the quality of the HEVC should be better.

Is Apple Video Encoder (hevc) Lossless?

HEVC itself is a lossless codec link. So yes, Apple's VideoToolBox supported HEVC compression is also lossless.

By lossless, it means that whatever data it can capture (8 bit/ 10 bit), if it compresses them using HEVC, it can decompress back to what it originally captured.

Now regarding compression settings to achieve lossless, first I need to know are you going to use Apple's VideoToolbox library to configure the compressor ? Or something else ?

Reducing the size of a video exported with AVAssetExportSession - iOS Swift

To reduce file size try these properties for setting up HEVC codec (use cocoa pod NextLevelSessionExporter):

let compressionDict: [String: Any] = [
AVVideoAverageBitRateKey: NSNumber(integerLiteral: 2500000), //lower it if you wish
AVVideoProfileLevelKey: AVVideoProfileLevelH264BaselineAutoLevel as String,
]
exporter.videoOutputConfiguration = [
AVVideoCodecKey : AVVideoCodecType.hevc,
AVVideoWidthKey : NSNumber(integerLiteral: 1280),
AVVideoHeightKey: NSNumber(integerLiteral: 720),
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoCompressionPropertiesKey: compressionDict
]

You need to upgrade to macOS High Sierra and iOS 11 in order to use HEVC video codec. But if you can't use HEVC for some reason, use regular H.264 with lower bitrate.

AVVideoCodecKey : AVVideoCodecType.h264:

Sample Image

Also, look at this SO post about video bitrate in iOS.

How to encode video 3840x2160 with 32x32 and 16x16 CU with depth 2 and 1 in HEVC Encoder HM 13

This is most probably due to the fact that you have compiled the binary for a 32-bit system?

Please rebuild it for a 64-bit system and the problem will go away.



Related Topics



Leave a reply



Submit