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 7078141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:30:36+00:00 2026-05-28T06:30:36+00:00

here i create the video is succeded and i combine the video and audio

  • 0

here i create the video is succeded and i combine the video and audio is merged in to the MOV Format and By Using the AVAssetExportSession the file is Exported, But When the file is played in media player is not played it just displays the blank screen

here i attached the merging code for video and audio

-(void)combine:(NSString *)audiopathvalue videoURL:(NSString *)videopathValue;
{

   // 1. Create a AVMutableComposition

    CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent(); //Debug purpose - used to calculate the total time taken
    NSError *error = nil;
    AVMutableComposition *saveComposition = [AVMutableComposition composition];


  //  2. Get the video and audio file path  
    NSString *tempPath = NSTemporaryDirectory();
    NSString *videoPath = videopathValue ;//<Video file path>;
    NSString *audioPath = audiopathvalue ;//<Audio file path>;;


    //3. Create the video asset 
    NSURL * url1 = [[NSURL alloc] initFileURLWithPath:videoPath];
    AVURLAsset *video = [AVURLAsset URLAssetWithURL:url1 options:nil];
    [url1 release];

   // 4. Get the AVMutableCompositionTrack for video and add the video track to it.
//        The method insertTimeRange: ofTrack: atTime: decides the what portion of the video to be added and also where the video track should appear in the final video created.
        AVMutableCompositionTrack *compositionVideoTrack = [saveComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    AVAssetTrack *clipVideoTrack = [ objectAtIndex:0];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, ) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil];
    NSLog(@"%f %@",CMTimeGetSeconds(),error);



    //5. Create the Audio asset 

    NSLog(@"audioPath:%@",audioPath);
    NSURL * url2 = [[NSURL alloc] initFileURLWithPath:audioPath];
    AVURLAsset *audio = [AVURLAsset URLAssetWithURL:url2 options:nil];
    [url2 release];

    //6. Get the AVMutableCompositionTrack for audio and add the audio track to it.
        AVMutableCompositionTrack *compositionAudioTrack = [saveComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
    AVAssetTrack *clipAudioTrack = [ objectAtIndex:0];
    [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, ) ofTrack:clipAudioTrack atTime:kCMTimeZero error:nil];
    NSLog(@"%f %@",CMTimeGetSeconds(),error);

    //7. Get file path for of the final video.
        NSString *path = [tempPath stringByAppendingPathComponent:@"mergedvideo.MOV"];
    if([[NSFileManager defaultManager] fileExistsAtPath:path])
    {
        [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
    }

    NSURL *url = [[NSURL alloc] initFileURLWithPath: path];


    //8. Create the AVAssetExportSession and set the preset to it.
    //The completion handler will be called upon the completion of the export.
    AVAssetExportSession *exporter = [[[AVAssetExportSession alloc] initWithAsset:saveComposition presetName:AVAssetExportPresetHighestQuality] autorelease];
    exporter.outputURL=url;
    exporter.outputFileType = @"com.apple.quicktime-movie";
    NSLog(@"file type %@",exporter.outputFileType);
    exporter.shouldOptimizeForNetworkUse = YES;






    [exporter exportAsynchronouslyWithCompletionHandler:^{

        switch ([exporter status]) {

            case AVAssetExportSessionStatusFailed:

                NSLog(@"Export failed: %@", [[exporter error] localizedDescription]);
                NSLog(@"ExportSessionError: %@", exporter.error);

                break;

            case AVAssetExportSessionStatusCancelled:

                NSLog(@"Export canceled");

                break;

            case AVAssetExportSessionStatusCompleted:
            {
                NSLog(@"Export Completed");
                ImageToAirPlayAppDelegate *theApp_iphone=(ImageToAirPlayAppDelegate *)[[UIApplication sharedApplication] delegate];
                [theApp_iphone call];
                break;
            }

            default:
                break;
        }

        //[exporter release];

    }];

in the video path it contains the series of images
and in the audio path only one audio

  • 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-05-28T06:30:37+00:00Added an answer on May 28, 2026 at 6:30 am

    The function (not in your code):

    - (void) captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
    

    Try doing the processing there.

    Gives you the outputFileURL that is the one you have to use in your mix. There is no reason to use an NSString in the function combine.

    I also recommend you to use AVFileTypeQuickTimeMovie instead “com.apple.quicktime-movie”. It is the same but easier to handle in case you want to experiment with other format.

    To know the available formats just use

    NSLog(@"%@", [exporter supportedFileTypes]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new here. I have been trying to create a video capture app using
I'm trying to create video from images using OpenGL ES and ffmpeg, but on
There are instructions here to create a C# assembly using the SimMetrics library. The
I found an example here to create a select list with optgroups using KnockoutJS.
I am using the jquery plugin boilerplate ( available here ) to create an
I am creating a web application using zend, here I create an interface from
I am using git configuration mentioned here If I create a new tab and
I'm trying to write to an AVI file using AVIStreamWrite but the resulting avi
am import some dll for create the live video. here myprob is i have
I want to create a simple video player using mediaPlayer.. So I did the

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.