Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ios中合并两个或多个视频_Ios_Video_Merge_Avvideocomposition - Fatal编程技术网

在ios中合并两个或多个视频

在ios中合并两个或多个视频,ios,video,merge,avvideocomposition,Ios,Video,Merge,Avvideocomposition,我同意上面的答案,并且进展顺利。但我面临一个问题,视频的音频正在被删除。甚至我所有的视频都有声音。但合并后,导出的视频将静音。有人能帮忙吗。提前谢谢。我也面临同样的问题,但我得到了解决方案。 Swift 4.2版本 // Merge All videos. func mergeAllVideos(completionHandler: @escaping(Bool)->Void){ mixComposition = AVMutableComposition.init


我同意上面的答案,并且进展顺利。但我面临一个问题,视频的音频正在被删除。甚至我所有的视频都有声音。但合并后,导出的视频将静音。有人能帮忙吗。提前谢谢。

我也面临同样的问题,但我得到了解决方案。 Swift 4.2版本

 // Merge All videos.
    func mergeAllVideos(completionHandler: @escaping(Bool)->Void){
        mixComposition = AVMutableComposition.init()

        // To capture video.
        let compositionVideoTrack = mixComposition?.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)

        // To capture audio.
        let compositionAudioTrack = mixComposition?.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)
        var nextCliptStartTime: CMTime = CMTime.zero

        // Iterate video array.
        for file_url in Constants.videoFileNameArr{
            // Do Merging here.
            let videoAsset = AVURLAsset.init(url: file_url)
            let timeRangeInAsset = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration);
            do{
                // Merge video.
                try compositionVideoTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: videoAsset.duration), of: videoAsset.tracks(withMediaType: .video)[0], at: nextCliptStartTime)

                // Merge Audio
                try compositionAudioTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: videoAsset.duration), of: videoAsset.tracks(withMediaType: .audio)[0], at: nextCliptStartTime)
            }catch{
                print(error)
            }

            // Increment the time to which next clip add.
            nextCliptStartTime = CMTimeAdd(nextCliptStartTime, timeRangeInAsset.duration)
        }

        // Add rotation to make it portrait.
        let rotationTransform = CGAffineTransform(rotationAngle: CGFloat(Double.pi/2))
        compositionVideoTrack!.preferredTransform = rotationTransform

        // Save final file.
        self.saveFinalFile(mixComposition!){
            isDone in
            completionHandler(true)
        }
    }

我也面临同样的问题,但我找到了解决办法。 Swift 4.2版本

 // Merge All videos.
    func mergeAllVideos(completionHandler: @escaping(Bool)->Void){
        mixComposition = AVMutableComposition.init()

        // To capture video.
        let compositionVideoTrack = mixComposition?.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)

        // To capture audio.
        let compositionAudioTrack = mixComposition?.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)
        var nextCliptStartTime: CMTime = CMTime.zero

        // Iterate video array.
        for file_url in Constants.videoFileNameArr{
            // Do Merging here.
            let videoAsset = AVURLAsset.init(url: file_url)
            let timeRangeInAsset = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration);
            do{
                // Merge video.
                try compositionVideoTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: videoAsset.duration), of: videoAsset.tracks(withMediaType: .video)[0], at: nextCliptStartTime)

                // Merge Audio
                try compositionAudioTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: videoAsset.duration), of: videoAsset.tracks(withMediaType: .audio)[0], at: nextCliptStartTime)
            }catch{
                print(error)
            }

            // Increment the time to which next clip add.
            nextCliptStartTime = CMTimeAdd(nextCliptStartTime, timeRangeInAsset.duration)
        }

        // Add rotation to make it portrait.
        let rotationTransform = CGAffineTransform(rotationAngle: CGFloat(Double.pi/2))
        compositionVideoTrack!.preferredTransform = rotationTransform

        // Save final file.
        self.saveFinalFile(mixComposition!){
            isDone in
            completionHandler(true)
        }
    }

你让音频在@Mayank工作了吗?你找到解决方案了吗?是的,我解决了问题。你让音频在@Mayank工作了吗?你找到解决方案了吗?是的,我解决了问题。谢谢,拉维,但我需要目标C中的解决方案,我找到了。谢谢,拉维,但我需要目标C中的解决方案,我找到了。