Exporting time lapse with AVAssetExportSession results in black video

前端 未结 1 369
遥遥无期
遥遥无期 2021-01-02 18:14

I need to be able to merge videos taken with the time lapse function in the Camera app on iOS and export as a single video.

However, even if I try to export a singl

相关标签:
1条回答
  • 2021-01-02 18:38

    The problem code is:

    videoLayerInstruction.setTransform(videoAssetTrack!.preferredTransform, at: kCMTimeZero)
    

    This transformation is eligible to "up" (default) orientation only and it makes a video completely black for the other orientations. You should make a correct transformation for each orientation e.g.:

    var transform = videoAssetTrack.preferredTransform
    // Right
    if transform.a == 0 && transform.b == 1.0 && transform.c == -1.0 && transform.d == 0 {
        isPortrait = true
        let rotate = CGAffineTransform.identity.translatedBy(x: videoAssetTrack.naturalSize.height - videoAssetTrack.preferredTransform.tx, y: -videoAssetTrack.preferredTransform.ty)
        transform = videoAssetTrack.preferredTransform.concatenating(rotate)
    }
    // Left
    else if transform.a == 0 && transform.b == -1.0 && transform.c == 1.0 && transform.d == 0 {
        isPortrait = true
        let rotate = CGAffineTransform.identity.translatedBy(x:  -videoAssetTrack.preferredTransform.tx, y: videoAssetTrack.naturalSize.width - videoAssetTrack.preferredTransform.ty)
        transform = videoAssetTrack.preferredTransform.concatenating(rotate)
    }
    // Up
    else if transform.a == 1.0 && transform.b == 0 && transform.c == 0 && transform.d == 1.0 {
        transform = videoAssetTrack.preferredTransform
    }
    // Down
    else if transform.a == -1.0 && transform.b == 0 && transform.c == 0 && transform.d == -1.0 {
        let rotate = CGAffineTransform.identity.translatedBy(x: videoAssetTrack.naturalSize.width - videoAssetTrack.preferredTransform.tx, y: videoAssetTrack.naturalSize.height - videoAssetTrack.preferredTransform.ty)
        transform = videoAssetTrack.preferredTransform.concatenating(rotate)
    }
    
    videoLayerInstruction.setTransform(transform, at: .zero)
    
    0 讨论(0)
提交回复
热议问题