The class AVAsset is fundamental to the design of the AVFoundation framework. AVAsset represents a collection of media data (sound and video tracks). AVAsset is not tied to any data formats. AVAsset is a superclass of classes that can be used for playback of media or for editing or creating new media.

It looks like you use AVAssetWriter to write a movie to disk.

AVFoundation separates the asset from the presentation of the asset. Different parts of the same asset can be displayed at the same time. The presentation of an asset is managed by a player item object and each track is managed by a player item track object. A player item is played by a player object and the output of the player object is sent to a core animation layer.

You can use an export session to re-encode an existing asset into one of a limited number of commonly used presets. For more control you can use an asset reader and writer object in tandem. This gives the ability to select tracks to include, specify an output format etc.

You can use AVAssetImageGenerator to capture video still thumbnails.

AVFoundation uses compositions to create and edit media. You can use a mutable composition to add and remove tracks and adjust layer and temporal orderings. When finished you export a composition using an export session.

I need to get a basic understanding of Core Animation. See the Core Animation programming guide.

Apple sample code to obtain an Asset that represents the first video in the saved photos album (iOS). I’ve rewritten to more easily see the operation of the blocks.

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    // Block implementation.
    ALAssetsLibraryGroupsEnumerationResultsBlock libraryEnumeratorBlock = ^(ALAssetsGroup *group, BOOL *stop)
    {
        // Within the group enumeration block, filter to enumerate just videos.
        [group setAssetsFilter:[ALAssetsFilter allVideos]];

        // Inner block implementation.
        ALAssetsGroupEnumerationResultsBlock groupEnumeratorBlock = ^(ALAsset *alAsset, NSUInteger index, BOOL *stop)
        {
            // The end of the enumeration is signaled by asset == nil.
            if (alAsset)
            {
                ALAssetRepresentation *representation = [alAsset defaultRepresentation];
                NSURL *url = [representation url];
                AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
                // Do something interesting with the AV asset.
            }            
        };

        // For this example, we're only interested in the first item.
        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
                                options:0
                             usingBlock:groupEnumeratorBlock];
    };

    // Failure block implementation.
    ALAssetsLibraryAccessFailureBlock libraryAcessFailureBlock = ^(NSError *error)
    {
        NSLog(@"No groups");
    };

    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                           usingBlock:libraryEnumeratorBlock
                         failureBlock:libraryAcessFailureBlock];

Getting Still Images From a Video

To get still images such as thumbnails from an asset for playback, you use an AVAssetImageGenerator object. You initialize an image generator with your asset. Initialization may succeed, though, even if the asset possesses no visual tracks at the time of initialization, so if necessary you should test whether the asset has any tracks with the visual characteristic using tracksWithMediaCharacteristic:

AVAsset anAsset = <#Get an asset#>;
if ([[anAsset tracksWithMediaType:AVMediaTypeVideo] count] > 0)
{
  AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:anAsset];
  // Implementation continues...
}

You can specify the maximum dimensions for the generated images by setting maximumSize and if you want to obtain an unscaled image then set maximumSize to CGSizeZero. Don’t need to worry about aperture mode.

List of AVAsset presets:

AVAssetExportPresetAppleM4V1080pHD,
AVAssetExportPreset960x540,
AVAssetExportPresetAppleM4VWiFi,
AVAssetExportPresetAppleM4VCellular,
AVAssetExportPresetAppleM4V720pHD,
AVAssetExportPreset1920x1080,
AVAssetExportPreset640x480,
AVAssetExportPresetAppleM4V480pSD,
AVAssetExportPresetAppleM4VAppleTV,
AVAssetExportPresetAppleM4ViPod,
AVAssetExportPresetAppleM4A,
AVAssetExportPresetAppleProRes422LPCM,
AVAssetExportPreset1280x720

 

ends