Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:35:59+00:00 2026-06-14T22:35:59+00:00

I am merging multiple videos and multiple songs and I am bot getting what

  • 0

I am merging multiple videos and multiple songs and I am bot getting what is wrong in the code because the same code was running absolutely fine yesterday but today I’m getting the following response
AVAssetExportSessionStatus = 4,error = Error Domain=AVFoundationErrorDomain Code=-11841 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11841.)"
I did some research and found that exporting is getting failed due to invalid video composition.Please find out what is wrong with the video composition.

- (void)mergeAllselectedVideos
{
    NSArray *pathArray = [DocumentDirectory getUrlFromDocumentDirectoryOfList:self.selectedClipsArray];
    AVMutableComposition *mixComposition = [[AVMutableComposition alloc]init];
    NSMutableArray *layerinstructions = [[NSMutableArray alloc]init];
    CMTime time = kCMTimeZero;
    CMTime previousSongDuration = kCMTimeZero;
    for (int i = 0 ; i < pathArray.count; i++)
    {
        //VIDEO TRACK//
        time = CMTimeAdd(time, previousSongDuration);
        NSURL *url = [NSURL URLWithString:[pathArray objectAtIndex:i]];
        AVAsset *avAsset = [AVAsset assetWithURL:url];
        AVMutableCompositionTrack *track = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
        [track insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration) ofTrack:[[avAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:time error:nil];
    previousSongDuration = avAsset.duration;
    }
    CMTime audioTime = kCMTimeZero;
    for (int i = 0; i < self.selectedSongsArray.count; i++)
    {
        MPMediaItem * songItem = [self.selectedSongsArray objectAtIndex:i];
        NSURL *songURL = [songItem valueForProperty: MPMediaItemPropertyAssetURL];
        AVAsset *audioAsset = [AVAsset assetWithURL:songURL];
        AVMutableCompositionTrack *AudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
        CMTimeRange timeRange = CMTimeRangeMake(audioTime, audioAsset.duration);
        if(CMTimeGetSeconds(CMTimeAdd(audioTime, audioAsset.duration)) > CMTimeGetSeconds(time))
        {
            timeRange = CMTimeRangeMake(audioTime, CMTimeSubtract(time,audioTime));
        }
        [AudioTrack insertTimeRange:timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
        audioTime = CMTimeAdd(audioTime, audioAsset.duration);
    }

    AVMutableVideoCompositionInstruction * MainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
    MainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, time);
    MainInstruction.layerInstructions = layerinstructions;

    AVMutableVideoComposition *MainCompositionInst = [AVMutableVideoComposition videoComposition];
    MainCompositionInst.instructions = [NSArray arrayWithObject:MainInstruction];
    MainCompositionInst.frameDuration = CMTimeMake(1, 30);
    MainCompositionInst.renderSize = CGSizeMake(320.0, 480.0);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    movieName = [CoreDataFunctions getNameForMovieForDate:[CalendarFunctions getCurrentDateString]];
    self.moviePlayButton.titleLabel.text = movieName;
    NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:movieName];

    NSURL *url = [NSURL fileURLWithPath:myPathDocs];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
    exporter.outputURL=url;
    exporter.outputFileType = AVFileTypeQuickTimeMovie;
    exporter.videoComposition = MainCompositionInst;
    exporter.shouldOptimizeForNetworkUse = YES;
    [exporter exportAsynchronouslyWithCompletionHandler:^{dispatch_async(dispatch_get_main_queue(), ^{[self exportDidFinish:exporter];});}];
}
- (void)exportDidFinish:(AVAssetExportSession*)session
{
    //Printing error
    NSLog(@"AVAssetExportSessionStatus = %i,error = %@",session.status,session.error);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:36:00+00:00Added an answer on June 14, 2026 at 10:36 pm

    I found your question while having the same problem. My theory on this issue is that all the properties for the video composition are not set at export time, so it’s crapping out. Here’s the stanza that I am now using which is now resulting in an error-free export:

    AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
    videoComposition.frameDuration = CMTimeMake(1,30);
    videoComposition.renderScale = 1.0;
    videoComposition.renderSize = CGSizeMake(352.0, 288.0);
    instruction.layerInstructions = [NSArray arrayWithObject: layerInstruction];
    instruction.timeRange = CMTimeRangeMake(kCMTimeZero, videoAsset.duration);
    videoComposition.instructions = [NSArray arrayWithObject: instruction];
    

    In my case, I was missing the timeRange property on the instruction. Check your own properties to ensure they’re getting the correct values. Good luck! This stuff is hard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on merging videos, but is not merging my videos. Here is
I'm merging multiple small images into a rectangular mosaic. When dealing with a small
I am to process single PDFs that have each been created by 'merging' multiple
I'm merging two UIImages into one context. It works, but it performs pretty slow
Possible Duplicate: Python: simple list merging based on intersections I have a multiple list:
I need an easy way to iterate over multiple collections without actually merging them,
I have a SimpleXML Object made from merging multiple XMLs from PubMed (snippet below)
I've read that merging several multiple javascript files into a single file improves performance,
This is a follow-up question to Merging multiple encoded polylines into one encoded polyline
Is there a method of logically merging multiple dictionaries if they have common strings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.