Is it possible to use a quality between AVAssetExportPresetMediumQuality and AVAssetExportPresetHighestQuality with AVAssetExportSession?
Asked Answered
P

2

7

I am using AVAssetExportSession to export a video out of my iOS app, like this:

AVAssetExportSession *exportSession=[AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetMediumQuality];

I want to upload the exported video, therefore size does matter. The problem is: The medium quality is a real bad quality and the AVAssetExportPresetHighestQuality is fine, but about 5 times larger than the medium one.

So, is there a way to create a video with a quality in between, lets say with 2 times the size?

Is this possible with AVAssetExportSession?

If not, is it possible with AVAssetWriter?

Thanks in advance,

best regards,

Walchy

Pollster answered 21/3, 2011 at 2:56 Comment(1)
How did you end up solving this?Woo
P
6

The answer is:

No. Not possible with AVAssetExportSession.

But yes. It is possible with AVAssetReader/AVAssetWriter.

Pollster answered 28/8, 2011 at 19:8 Comment(0)
U
2

While an explicit setting does not exist, it is possible to get a quality between medium and high with AVAssetExportSession.

You can choose AVAssetExportPresetHighestQuality and then manually limit the file size. You can estimate the file size and then set a limit to some % of that. For example:

exportSession.estimateOutputFileLength { length, error in
            exportSession.outputURL = outputURL
            exportSession.outputFileType = .mp4

            if error != nil {
                exportSession.fileLengthLimit = Int64(Double(length) * 0.1)
            } else {
                exportSession.fileLengthLimit = Int64(10 * 1024 * 1024)
            }

            exportSession.exportAsynchronously {
                handler(exportSession)
            }
        }

Through testing, limiting it to 20%-30% of the estimated size will lead to much better than medium quality, at a much reduced file size. You might want to add additional checks like if the file size is less than X mb, don't reduce further, etc.

Unifilar answered 19/2, 2024 at 18:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.