Duet - Merge 2 Videos Side by Side

后端 未结 2 489
耶瑟儿~
耶瑟儿~ 2020-12-10 23:00

NOTE:- Merge Videos Side By Side WITHOUT Losing Video Quality

I think that is a Very Very Important Question, After a lot of search

相关标签:
2条回答
  • 2020-12-10 23:43

    To achieve this, I would create a new AVMutableComposition object containing 2 tracks, and set transform on each to place them side by side:

    let composition = AVMutableComposition(urlAssetInitializationOptions: <your options>)
    let videoTrackA = composition.addMutableTrack(withMediaType:.video, preferredTrackID:kCMPersistentTrackID_Invalid);
    let videoTrackB = composition.addMutableTrack(withMediaType:.video, preferredTrackID:kCMPersistentTrackID_Invalid);
    
    videoTrackA.preferredTransform = CGAffineTransform(translationX: <yourX_for_A>, y:0.0)
    videoTrackB.preferredTransform = CGAffineTransform(translationX: <yourX_for_B>, y:0.0)
    

    Then. save it using:

    let exporter = AVAssetExportSession(asset:<yourAsset>, presetName:<yourPresetName>)
    exporter.exportAsynchronously(completionHandler: <yourCompletionHandler>)
    

    (Swift code not tested).

    0 讨论(0)
  • 2020-12-10 23:43

    in fact, AVAssetExportSession is for simple needs, and it is too simple for your situation.

    You must use AVAssetWriter.

    You add AVAssetWriterInput to your AVAssetWriter.

    You can configure trasnform of the AVAssetWriterInput using its transform property.

    Then, you feed your AVAssetWriterInput with CMSampleBuffer (each images buffer) using append calls.

    See full Apple documentation for detailed example: https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html#//apple_ref/doc/uid/TP40010188-CH9-SW2

    0 讨论(0)
提交回复
热议问题