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:
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
How to Determine If a Business Is Open Given the Hours of Operation (Swift-Ios)
iOS - Send Image to Instagram - Documentinteraction
Moya/Alamofire - Url Encoded Params with Same Keys
Custom Uitoolbar Too Close to the Home Indicator on iPhone X
Swift: Load Custom Uiview from Xib Programmatically
Swift 2 Unused Constant Warning
Issue with Observing Wkwebview Url Changes via JavaScript Events
Why the Autolayout Is Not Updated If I Use Ibdesignable File When I Run the App
iOS Pod Install Gcm and Pnchartswift
Setup a Collectionview with "Tag"-Like Cells
Error When Decoding Certain Base64 Strings, But Not Others
App Groups Forsecurityapplicationgroupidentifier Returns Nil
Fbsdkcorekit.Framework/Fbsdkcorekit: No Matching Architecture in Universal Wrapper
iOS - Uinavigationcontroller, Hide Navigationbar
Skspritenode Does Not Let Touches Pass Through When Isuserinteractionenabled False
Objective-C Call Swift Function
iOS - How to Make the Uiscrolling Indicator Height Same for Any Number of Data