Изменение размера кадра видео с помощью AVFoundation

Я пытаюсь изменить размер видеокадра на квадрат, т.е. 100 x 100. Вот код:

- (void) changeSize :(NSURL *) url
{

//Create audio/video Settings
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt: 100], AVVideoWidthKey, 
                               [NSNumber numberWithInt:100], AVVideoHeightKey, 
                               nil];

NSDictionary * audioSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
                               [NSNumber numberWithFloat: 44100.0], AVSampleRateKey, 
                               [NSNumber numberWithInt: 2], AVNumberOfChannelsKey, 
                               [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey, 
                               [NSData data], AVChannelLayoutKey, nil];



//Read Asset 
AVURLAsset *myAsset = [AVURLAsset URLAssetWithURL:url options:nil];

NSArray *videoTracks = [myAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *audioTrack = [[myAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0];


AVAssetReader *assetReader = [[AVAssetReader alloc]initWithAsset:myAsset error:nil];

AVAssetReaderOutput *videoOutput = [AVAssetReaderVideoCompositionOutput assetReaderVideoCompositionOutputWithVideoTracks:videoTracks videoSettings:nil];

AVAssetReaderOutput *audioOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:audioTrack outputSettings:nil];

[assetReader addOutput:videoOutput];
[assetReader addOutput:audioOutput];


//Create writer and set its properties
AVAssetWriterInput* writerInputVideo = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
                                                                           outputSettings:videoSettings] retain];

AVAssetWriterInput* writerInputAudio = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
                                                                           outputSettings:nil] retain];


NSError *error = nil;
AVAssetWriter *writer = [[AVAssetWriter alloc]initWithURL:[NSURL fileURLWithPath:fullPath] fileType:AVFileTypeQuickTimeMovie error:&error];

[writer addInput:writerInputVideo];
[writer addInput:writerInputAudio];


//start reading/writting
[writer startWriting];
[assetReader startReading];

}

Теперь проблема в том, что когда он достигает [assetReader startReading], он выдает и исключение: «Необходимо установить AVAssetReaderVideoCompositionOutput.videoComposition».

Кто-нибудь, пожалуйста, помогите мне?

TIA

5
задан shujaat 17 August 2011 в 19:07
поделиться