Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the AVAssetExportPreset Quality #112

Closed
kfung0426 opened this issue Apr 23, 2018 · 8 comments
Closed

Change the AVAssetExportPreset Quality #112

kfung0426 opened this issue Apr 23, 2018 · 8 comments

Comments

@kfung0426
Copy link

Hi
Please let us change the AVAssetExportPresetHighestQuality to AVAssetExportPresetPassthrough in tempCopyMediaFile() by declaring in TLPhotosPickerConfigure?
My app only need to get the original video without convert.

@tilltue
Copy link
Owner

tilltue commented Apr 24, 2018

@kfung0426
Use this code.
TLAssetsCollection.swift 214 line copy & paste :)
and add options.deliverMode
options.deliveryMode = .highQualityFormat//<<----

public func exportVideoFile(progressBlock:((Float) -> Void)? = nil, completionBlock:@escaping ((URL,String) -> Void)) {
        guard let phAsset = self.phAsset, phAsset.mediaType == .video else { return }
        var type = PHAssetResourceType.video
        guard let resource = (PHAssetResource.assetResources(for: phAsset).filter{ $0.type == type }).first else { return }
        let fileName = resource.originalFilename
        var writeURL: URL? = nil
        if #available(iOS 10.0, *) {
            writeURL = FileManager.default.temporaryDirectory.appendingPathComponent("\(fileName)")
        } else {
            writeURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("\(fileName)")
        }
        guard let localURL = writeURL,let mimetype = MIMEType(writeURL) else { return }
        let options = PHVideoRequestOptions()
        options.isNetworkAccessAllowed = true
        options.deliveryMode = .highQualityFormat//<<---- 
        PHImageManager.default().requestAVAsset(forVideo: phAsset, options: options) { (avasset, avaudioMix, infoDict) in
            guard let avasset = avasset else { return }
            let exportSession = AVAssetExportSession.init(asset: avasset, presetName: AVAssetExportPresetHighestQuality)
            exportSession?.outputURL = localURL
            exportSession?.outputFileType = AVFileType.mov
            exportSession?.exportAsynchronously(completionHandler: {
                completionBlock(localURL,mimetype)
            })
            func checkExportSession() {
                DispatchQueue.global().async { [weak exportSession] in
                    guard let exportSession = exportSession else { return }
                    switch exportSession.status {
                    case .waiting,.exporting:
                        DispatchQueue.main.async {
                            progressBlock?(exportSession.progress)
                        }
                        Thread.sleep(forTimeInterval: 1)
                        checkExportSession()
                    default:
                        break
                    }
                }
            }
            checkExportSession()
        }
    }

@kfung0426
Copy link
Author

Hi tilltue, thanks for your reply.
I know I can change the file there.
The matter appears when I "pod update" your library, my revised code will be replaced.
I forgot to change it back and submitted to App Store...I need to make another update now.

So I ask for a declare place apart from the core code.

@tilltue
Copy link
Owner

tilltue commented Apr 24, 2018

@kfung0426
Oh i see.
I mean, you can extension method in your project.
But now, I added parameter PHVideoRequestOptions at exportVideoFile method.

@kfung0426
Copy link
Author

thanks for your update

@kfung0426
Copy link
Author

oops, could you please also add for the tempCopyMediaFile()?

@kfung0426 kfung0426 reopened this Apr 25, 2018
@kfung0426
Copy link
Author

kfung0426 commented Apr 25, 2018

Hi tilltue,
thanks for your update. I'm sorry that I haven't told you clearly and make you misunderstood.

Actually, I am asking for the change "AVAssetExportPresetHighestQuality" to "AVAssetExportPresetPassthrough" in the line:180

return PHImageManager.default().requestExportSession(forVideo: phAsset, options: requestOptions, exportPreset: AVAssetExportPresetHighestQuality) { (session, infoDict) in

to

return PHImageManager.default().requestExportSession(forVideo: phAsset, options: requestOptions, exportPreset: AVAssetExportPresetPassthrough) { (session, infoDict) in

could you please make AVAssetExportPresetPassthrough can pass to tempCopyMediaFile() ?

@tilltue
Copy link
Owner

tilltue commented Apr 26, 2018

I've added for that. :)

@kfung0426
Copy link
Author

awesome, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants