I wish I hadn’t been so crunched in the week leading up to the Voices That Matter: iPhone Developer Conference last weekend in Philadelphia, and had gotten a few of the super-advanced AV Foundation features working for demos, but since I went over my time by 10 minutes, I guess the talk was already chock ful o’ content.

Anyways, I promised materials would be on my blog after a code clean-up, and here they are:

Title: Mastering Media with AV Foundation

  • Presentation slides (PDF)
  • VTM_Player.zip – Illustrates basic playback functionality, with local and remote files and streams (included URLs include .m4a, .mov, Shoutcast, and HTTP LIve Streaming)
  • VTM_AVRecPlay.zip – Performs A/V capture from camera/mic and playback of captured movie
  • VTM_AVEditor.zip – Simple cuts-only editor for in/out editing, addition of audio track at export time.

4 Comments

  • 1. kmadhukishore replies at 16th November 2010 um 6:52 am :

    Hello there,
    First of all thanks for the nice tutorials.
    In my app I want mix one audio file with video file, I am able to do that in simulator, but not in my iPhone 3g :(
    Following is the code which I am using:

    NSURL* a_inputFileUrl = nil;
    NSURL* b_inputFileUrl = nil;
    {
    NSString* extStr = [NSString stringWithString:@"mov"];
    NSString* fileName = [[NSBundle mainBundle] pathForResource:@”1″ ofType:extStr];
    a_inputFileUrl = [NSURL fileURLWithPath:fileName];
    }
    {
    NSString* extStr = [NSString stringWithString:@"caf"];
    NSString* fileName = [[NSBundle mainBundle] pathForResource:@”1″ ofType:extStr];
    b_inputFileUrl = [NSURL fileURLWithPath:fileName];
    }
    NSString* outputFilePath = nil;
    {
    NSString* storeUrlStr = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@”temp”];
    NSFileManager* fileManager = [NSFileManager defaultManager];
    [fileManager createDirectoryAtPath:storeUrlStr withIntermediateDirectories:NO attributes:nil error:nil];
    outputFilePath = [storeUrlStr stringByAppendingPathComponent:[NSString stringWithString:@"outputFile.mov"]];
    outputFileUrl = [[NSURL fileURLWithPath:outputFilePath] retain];
    }

    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:b_inputFileUrl options:nil];
    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:a_inputFileUrl options:nil];

    AVMutableComposition* mixComposition = [AVMutableComposition composition];

    AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeTimedMetadata
    preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration)
    ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
    atTime:kCMTimeZero error:nil];

    AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
    preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
    ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
    atTime:kCMTimeZero error:nil];

    _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition
    presetName:AVAssetExportPresetPassthrough];
    NSURL* exportUrl = outputFileUrl;

    if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath])
    {
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil];
    }

    _assetExport.outputFileType = @”com.apple.quicktime-movie”;
    _assetExport.outputURL = exportUrl;
    _assetExport.shouldOptimizeForNetworkUse = YES;

    [_assetExport exportAsynchronouslyWithCompletionHandler:
    ^(void ) {

    }];

  • 2. [Time code];&hellip replies at 12th April 2011 um 3:17 pm :

    [...] this is twice in a row that I’ve done a talk for the Voices That Matter: iPhone Developer Conference and been able [...]

  • 3. [Time code];&hellip replies at 23rd August 2011 um 8:28 am :

    [...] VTM_Player.zip, VTM_AVRecPlay.zip, VTM_AVEditor.zip – see Slides and stuff from Voices That Matter talk [...]

  • 4. google.com/accounts/o8… replies at 8th September 2011 um 11:31 am :

    Hi ,
    Thanks for the best tutorial i have found !
    I have a question Can we only record video with black or white color / blend color ?

Leave a comment

You must be logged in to post a comment.