5

AVAsset にロードできるビデオ ファイルがあります。このビデオの再生速度を変更し、速度を 2 倍にして、ビデオの長さが 10 秒の場合、速度を上げて 5 秒で終了するようにします。

これが私が試しているコードです。どこが間違っているのか教えてもらえますか?

フレーム期間は、目標を達成するために必要なプロパティです。

AVAsset *anAsset = self.moviePlayer.currentItem.asset;


NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPreset640x480]) {
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
                                           initWithAsset:anAsset presetName:AVAssetExportPreset640x480];
    // Implementation continues.

    NSString *tmpStr = [[aclip selectedTakeUrl] stringByReplacingOccurrencesOfString:@".m4v" withString:@""];

    NSString *filePath = [NSString stringWithFormat:@"%@_applied.m4v", tmpStr];


    exportSession.outputURL = [NSURL fileURLWithPath:filePath];

    AVMutableVideoComposition *vidcomp = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:anAsset];

    vidcomp.frameDuration = CMTimeMake(1, 24);
    //self.moviePlayer.currentItem.videoComposition = vidcomp;

    exportSession.videoComposition = vidcomp;
    //exportSession.videoComposition.frameDuration = CMTimeMake(1, 50);

    // what is the song URL before loading startRecordingViewController?
    NSLog(@"From Save settgins Choose Song -Song URL : %@", exportSession.outputURL);

    //   NSLog(@"start time%f, end time %f", CMTimeGetSeconds(self.startTime),CMTimeGetSeconds(self.endTime));

    exportSession.outputFileType = AVFileTypeMPEG4;

    //CMTimeRange range = CMTimeRangeMake(CMTimeMake(0.0, 1), CMTimeMake(diffTime/currentround,1));
    // startTime and endTime is the duration that we need to save.
    //exportSession.timeRange = range;


    [exportSession exportAsynchronouslyWithCompletionHandler:^{

        switch ([exportSession status]) {
            case AVAssetExportSessionStatusCompleted:
                NSLog(@"Export Completed");

                break;
            case AVAssetExportSessionStatusWaiting:
                NSLog(@"Export Waiting");
                break;
            case AVAssetExportSessionStatusExporting:
                NSLog(@"Export Exporting");
                break;
            case AVAssetExportSessionStatusFailed:
            {
                NSError *error = [exportSession error];
                NSLog(@"Export failed: %@", [error localizedDescription]);

                break;
            }
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");

                break;
            default:
                break;
        }

        dispatch_async(dispatch_get_main_queue(), ^{

            //[activityIndicator stopAnimating];

            //CMTime range = CMTimeSubtract(self.endTime, self.startTime);
            //NSUInteger theLength = (int)CMTimeGetSeconds(range);

            //[ self.songPickedDelegate songPickerDidMakeSelection:self.songTitle :self.audioPath :theLength];





        });

        //[exportSession release];
    }];
}
4

1 に答える 1

5

-[AVMutableCompositionTrack scaleTimeRange:toDuration:] を使用して、アセット全体を 10 秒から 5 秒にスケーリングできます。frameDuration プロパティは、単純にフレーム レート変換を実行します。

于 2014-01-15T01:57:15.873 に答える