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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:46:35+00:00 2026-06-02T01:46:35+00:00

I am trying to export an image over video, but when the export fininshes

  • 0

I am trying to export an image over video, but when the export fininshes I get a video of black screen with the image.
Here’s the code that sets up the compositions:

UIImage *myImage = [UIImage imageNamed:@"block.png"];
CALayer *aLayer = [CALayer layer];
aLayer.frame = CGRectMake(100, 100, 40, 40);
aLayer.contents = (id)myImage.CGImage ;
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video-1" ofType:"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
cmp = [[AVMutableComposition alloc] init] ;  
AVMutableCompositionTrack *trackA = [cmp addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
NSError *error = nil ;
AVAssetTrack *sourceVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[trackA insertTimeRange:CMTimeRangeMake(kCMTimeZero, [asset duration]) ofTrack:sourceVideoTrack atTime:kCMTimeZero error:&error] ;
animComp = [[AVMutableVideoComposition videoComposition] retain] ;
animComp.renderSize = CGSizeMake(640, 480);
animComp.frameDuration = CMTimeMake(1,30);
animComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithAdditionalLayer:aLayer asTrackID:2];
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);
AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:trackA];
[layerInstruction setTrackID:2];
[layerInstruction setOpacity:1.0 atTime:kCMTimeZero ];
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction] ;
animComp.instructions = [NSArray arrayWithObject:instruction];

To export the movie I use the following code:

-(IBAction) exportMovie:(id)sender{
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *tempPath = [docPaths objectAtIndex:0];
NSLog(@"Temp Path: %@",tempPath);

NSString *fileName = [NSString stringWithFormat:@"%@/output-anot.MOV",tempPath];
NSFileManager *fileManager = [NSFileManager defaultManager] ;
if([fileManager fileExistsAtPath:fileName ]){
    NSError *ferror = nil ;
    BOOL success = [fileManager removeItemAtPath:fileName error:&ferror];
}

NSURL *exportURL = [NSURL fileURLWithPath:fileName];

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:cmp presetName:AVAssetExportPresetHighestQuality]  ;
exporter.outputURL = exportURL ;
exporter.videoComposition = animComp ;
exporter.outputFileType= AVFileTypeQuickTimeMovie ;
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
    switch (exporter.status) {
        case AVAssetExportSessionStatusFailed:{
            NSLog(@"Fail");
            break;
        }
        case AVAssetExportSessionStatusCompleted:{
            NSLog(@"Success");
            break;
        }

        default:
            break;
    } 
}];

}

Am I missing sthg here or done something wrong.

  • 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-02T01:46:37+00:00Added an answer on June 2, 2026 at 1:46 am

    yes I see the issue, thanks for the code BTW! I have been trying to do this, and I just copy paste (I’m a noob) but I found your issue while editing the code for my issue, this line

    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video-1.mp4" ofType:nil];
    

    that is wrong, funny kind of, anyways change it to this

    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video-1" ofType:@"mp4"];
    

    and that should be the only issue. the reason its black is because it doesn’t have the right movie.

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

Sidebar

Related Questions

Im trying to export a .dmp of an oracle database but am getting the
I'm trying to export a profile from WAS 6.1 so that I can give
I'm trying to export an Excel database into .txt (Tab Delimited), but some of
I'm trying to export the data that is shown in plot(yi) using wavwrite. When
I'm currently trying to export gridview to pdf file. My code is: public void
I was trying to export https://github.com/LiosK/UUID.js into a module, but I'm having a rough
I'm trying to export data from a web app into excel, but there is
I'm trying to write some simple code to resize an image, and I am
I'm trying to use a 64-bit application that uses SDL (and SDL Image in
I'm trying to export from SQL Server to Oracle a table that consists of

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.