2020-12-25 23:12

Video corruption after merge


I'm encoutering an issue when I'm trying to merge two .mov video. After merging them, the resulting video appear to be corrupted on other OS (Windows, Ubuntu) or browser (Firefox, Chrome), but working well with QuickTime on MacOS.

Here is the code :

override func viewDidLoad() {
    // Do any additional setup after loading the view.

    guard let firstVideoUrl = Bundle.main.url(forResource: "part1", withExtension: "mov"),
        let secondVideoUrl = Bundle.main.url(forResource: "part2", withExtension: "mov") else {
            assertionFailure("Can't get videos url.")

    VideoGenerator.fileName = "mergedVideo"
    VideoGenerator.mergeMovies(videoURLs: [secondVideoUrl, firstVideoUrl], success: { (videoURL) in
        self.share(url: videoURL)
    }) { (error) in

You can reproduce this issue with this sample project : https://github.com/floriangbh/video-merge-issue-demo The result video of the merge is available on this link : https://firebasestorage.googleapis.com/v0/b/speedtest-dev/o/mergedVideo.m4v?alt=media&token=c917f475-49a8-40e6-a5de-2bfdba8501fe (you can open it with Firefox or Chrome to see the corruption).

Have you any idea how to fix it ?

Thanks, Florian


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39957835 weixin_39957835 3月前

    , The video file format after the merge is m4v which is Apple-specific (develop for Apple's platforms). That is why it can't be played on other OS (Windows, Ubuntu). You could try to convert the m4v file to an mp4 file using AVAsset.

    点赞 评论 复制链接分享
  • weixin_39761880 weixin_39761880 3月前

    I just tried to convert to mp4, but the result is the same...

    Commit : https://github.com/floriangbh/video-merge-issue-demo/commit/b70497db64f88ad1d279b8ccd4de13e9a8b2918e Final video : https://firebasestorage.googleapis.com/v0/b/speedtest-dev/o/rendered-Video.mp4?alt=media&token=e5c7f7b6-48a4-45a8-87d3-b3c0ff6beb5c

    点赞 评论 复制链接分享
  • weixin_39957835 weixin_39957835 3月前

    , If you noticed the produced video from the library is encoded using H.264 format for the video and AAC for the audio. These configurations can't be changed, because the merge is made using native Apple framework. To be able to play such kind of a format on other OS you will need additional codecs. Thus my previous suggestion won't help you :(

    Here is a link describing how to play H.264 on windows - https://www.techwalla.com/articles/how-to-play-h264-in-windows-media-player

    点赞 评论 复制链接分享
  • weixin_39761880 weixin_39761880 3月前

    In fact the video need to be readable from web navigator like Chrome, Firefox or Safari. I can't ask to our user to install a specific codec :)

    点赞 评论 复制链接分享