longitachi / ZLPhotoBrowser

Wechat-like image picker. Support select photos, videos, gif and livePhoto. Support edit image and crop video. 微信样式的图片选择器,支持预览/相册内拍照及录视频、拖拽/滑动选择,编辑图片/视频,支持多语言国际化等功能;
MIT License
4.72k stars 953 forks source link

Max deviation is 0 in ZLEditVideoViewController? #765

Closed isayeter closed 1 year ago

isayeter commented 1 year ago

Issue Description

I have created a function to use your video editor:

func showVideoEditor(model: ZLPhotoModel) {
    ZLPhotoManager.fetchOriginalImage(for: model.asset) { [weak self] image, isDegraded in
        if isDegraded {
            if let requestAvAssetID = self?.requestAvAssetID {
                PHImageManager.default().cancelImageRequest(requestAvAssetID)
            }

            self?.requestAvAssetID = ZLPhotoManager.fetchAVAsset(forVideo: model.asset) { [weak self] avAsset, _ in
                if let avAsset = avAsset {
                    let vc = ZLEditVideoViewController(avAsset: avAsset)
                    vc.modalPresentationStyle = .fullScreen

                    vc.editFinishBlock = { [weak self] url in
                        if let u = url {
                            self?.videoPicked(filePath: u, thumbnail: image)
                        }
                        else {
                            print("!url")
                        }
                    }

                    safeVC.present(vc, animated: false, completion: nil)
                }
                else {
                    print("timeout")
                }
            }
        }
    }
}

When I call this function, after I click "Done" button in the video editor VC (without trimming any)

Screen Shot 2022-09-25 at 15 40 46

your SDK falls into this line this line and callbacks editFinishBlock block with nil url.

Those are the console prints when investigation:

(lldb) po self.avAsset.duration.seconds
5.959

(lldb) po interval
0.6

(lldb) po clipRect().width
330.0

(lldb) po ZLEditVideoViewController.frameImageSize.width
33.0

(lldb) po (CGFloat(interval) * clipRect().width / ZLEditVideoViewController.frameImageSize.width)
6.0

(lldb) po (abs(CGFloat(interval) * clipRect().width / ZLEditVideoViewController.frameImageSize.width - round(CGFloat(avAsset.duration.seconds))))
0.0

I couldn't understand the necessity of that line, can you please explain what is the reason?

Info

ZLPhotoBrowser version: 4.3.6 Device: iOS Simulator Device version: iOS 14.5 Xcode version: Xcode 14.0

Configuration code of ZLPhotoConfiguration

        ZLPhotoConfiguration.default().cameraConfiguration.flashMode = .auto
        ZLPhotoConfiguration.default().cameraConfiguration.focusMode = .continuousAutoFocus
        ZLPhotoConfiguration.default().cameraConfiguration.videoExportType = .mp4

        ZLPhotoConfiguration.default().allowSelectImage = true
        ZLPhotoConfiguration.default().allowSelectVideo = true
        ZLPhotoConfiguration.default().allowSelectGif = false
        ZLPhotoConfiguration.default().allowTakePhoto = false
        ZLPhotoConfiguration.default().allowRecordVideo = false
        ZLPhotoConfiguration.default().allowEditImage = true
        ZLPhotoConfiguration.default().allowEditVideo = true
        ZLPhotoConfiguration.default().editAfterSelectThumbnailImage = true
        ZLPhotoConfiguration.default().saveNewImageAfterEdit = true
        ZLPhotoConfiguration.default().allowSelectOriginal = true
        ZLPhotoConfiguration.default().allowPreviewPhotos = true
        ZLPhotoConfiguration.default().showPreviewButtonInAlbum = false
        ZLPhotoConfiguration.default().maxSelectCount = 1
        ZLPhotoConfiguration.default().maxVideoSelectCount = 1

        ZLPhotoConfiguration.default().minRecordDuration = 3.0
        ZLPhotoConfiguration.default().minSelectVideoDuration = 3.0
        ZLPhotoConfiguration.default().maxRecordDuration = 60.0
        ZLPhotoConfiguration.default().maxEditVideoTime = 60.0
        ZLPhotoConfiguration.default().maxSelectVideoDuration = 60.0
isayeter commented 1 year ago

As I understand, editFinishBlock only fires when trimming video, if you don't touch the trimming, then SDK just returns the supplied Asset directly, however in this case videoExportType = .mp4 will be also meaningless because if I choose a MOV file and not trim the video, SDK does not return a mp4 video. How to solve the problem?

isayeter commented 1 year ago

Ok I have changed the editFinishBlock so that if returns nil, I'm creating mp4 converted video with another code.

vc.editFinishBlock = { [weak self] url in
    //video trimmed
    if let u = url {
        self?.videoPicked(filePath: u, thumbnail: image)
    }
    //clicked directly done button without trimming
    else {
        self?.getUrlFromPHAsset(asset: model.asset, callBack: { url in
            if url != nil {
                VideoCompressHelper.shared.compressVideo(url!) { url2 in
                    DispatchQueue.main.async {
                        if let finalCompressed = url2 {
                            ZLPhotoManager.saveVideoToAlbum(url: finalCompressed) { [weak self] _, asset in }
                            self?.videoPicked(filePath: finalCompressed, thumbnail: image)
                        }
                    }
                }
            }
        })
    }
}