HHK1 / PryntTrimmerView

A set of tools to trim, crop and select frames inside a video
MIT License
829 stars 199 forks source link

Trim video issue. #40

Open DGP13 opened 5 years ago

DGP13 commented 5 years ago

I'm trim video using this PryntTrimmerView lib. I have set min 15 second & max 60 second but save video total duration is 52 second.

HHK1 commented 5 years ago

Can you provide an example (video asset included) to reproduce please ? What was the duration of the original asset ?

DGP13 commented 5 years ago

This is export trim video code....

do { let asset = AVURLAsset(url: asset_url) let trimmedAsset = try asset .assetByTrimming(startTime: trimmerView.startTime ?? kCMTimeZero, endTime: trimmerView.endTime ?? url_AVURLAsset.duration)

        let destinationURL = URL(fileURLWithPath: NSTemporaryDirectory())
            .appendingUniquePathComponent(pathExtension: "mov")

        print(destinationURL)

        try trimmedAsset.export(to: destinationURL) { [weak self] in
            //guard let strongSelf = self else { return }

            print("save \(destinationURL)")
            DispatchQueue.global(qos: .background).async {

                let data = NSData(contentsOf: destinationURL)
                print("File size before compression: \(Double((data?.length)! / 1048576)) mb")
                self?.compressVideoOutput(videoURL: destinationURL)

            }

        }
    } catch let error {
        print("💩 \(error)")
    }

I'm set max 1 minit video allow otherwise is automatically trim.