HXPhotoPicker icon indicating copy to clipboard operation
HXPhotoPicker copied to clipboard

Processing failed on some videos

Open AEM120 opened this issue 11 months ago • 4 comments

Video File: https://we.tl/t-pAhUdQeXmG

Open Safari, paste the link and download the video. Go to Files. Save Video to Photos. Using the Demo try to edit the video by cropping "square for example" only Then hit finish "Processing failed"

simulator_screenshot_31B7FF9B-AE61-4DBB-B61B-F3B11C81D0B4

AEM120 avatar Jul 16 '23 16:07 AEM120

Some videos work fine, the video example that you have does not produce any issues. While the video example that I provided you have some issues when editing.

Example,

  1. select the video, and crop it to square. click finish, you get processing failed.
  2. select the video, and trim from the start. click finish, you get processing failed.

Please watch the following demo:

https://github.com/SilenceLove/HXPhotoPicker/assets/139702862/aee2d12b-c03f-463c-b4de-74e874b46360

AEM120 avatar Jul 16 '23 16:07 AEM120

ok i will try to fix it

SilenceLove avatar Jul 17 '23 03:07 SilenceLove

I been using different instruments to see where is the error. But it seems something to do with the EditorVideoCompositor. I also found out that some videos have full cpu usage when processing the edit Screenshot 2023-07-17 at 6 43 01 AM Screenshot 2023-07-17 at 6 43 21 AM

AEM120 avatar Jul 17 '23 03:07 AEM120

I found the problem, this is just a temporary solution

EditorVideoTool.swift

func insertAudioTrack(
        duration: CMTime,
        timeRang: CMTimeRange,
        audioTracks: [AVAssetTrack]
    ) throws 

Modify as follows

var audioInputParams: [AVMutableAudioMixInputParameters] = []
for audioTrack in audioTracks {
    guard let track = mixComposition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid) else {
        continue
    }
    let audioTimeRange: CMTimeRange = .init(start: .zero, duration: .init(seconds: audioTrack.timeRange.duration.seconds - 0.5, preferredTimescale: audioTrack.timeRange.duration.timescale))
    try track.insertTimeRange(audioTimeRange, of: audioTrack, at: .zero)
    track.preferredTransform = audioTrack.preferredTransform
    let audioInputParam = AVMutableAudioMixInputParameters(track: track)
    audioInputParam.setVolumeRamp(fromStartVolume: factor.volume, toEndVolume: factor.volume, timeRange: audioTimeRange)
    audioInputParam.trackID = track.trackID
    audioInputParams.append(audioInputParam)
}

SilenceLove avatar Jul 18 '23 04:07 SilenceLove