testfairy-blog / VideoCompressionTutorial

iOS - Fine tuned video compression in Swift 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Video size larger then original size.

sinhaGIT opened this issue · comments

I am having an issue with this.

when I am selecting video from gallery it was showing compressing. after selecting video I started compression using your code after successful compression what I got in closure is
my original file size print 3.90 MB. and compressed file size in 7.00 MB. please guide me how to solve this issue.

Then I checked the Info of Media in device is

size: 9.4 MB
640x1136
video codec type: h.264
frame rate: 29.9 fps
duration 01.28 minutes

Compression amount depends on the bitrate. You can instantiate and provide a CompressionConfig object like below to modify the output video according to your needs. Google "video bitrate calculator" if you want to calculate what your desired bitrate value is. Beware that low bitrates on high-res videos cause unwanted compression artifacts in the image.

let config = CompressionConfig(
        videoBitrate: 1024 * 750,
        videomaxKeyFrameInterval: 30,
        avVideoProfileLevel: AVVideoProfileLevelH264High41,
        audioSampleRate: 22050,
        audioBitrate: 80000
    )

compressh264VideoInBackground(
    //...
    compressionConfig: config,
    //...
)