2012-07-16 2 views
3

AVAssetWriter API를 사용하여 동영상 (.mp4) 메타 정보를 변경하는 방법은 무엇입니까?AVAssetWriter를 사용하여 비디오 메타 데이터를 변경하는 방법은 무엇입니까?

다시 인코딩하지 않겠습니다. 동영상 메타 정보 만 수정하려고했습니다.

다음 코드를 작성하는 방법은 무엇입니까?

AVAssetWriter *writer = [AVAssetWriter assetWriterWithURL:[NSURL URLWithString:myPath] fileType:AVFileTypeQuickTimeMovie error:nil]; 

내가 잘못하면 몇 가지 힌트를 제공합니다.

감사합니다.

답변

3

은 다음 코드를 참조하십시오.

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:"your path"] options:nil]; 
NSMutableArray *metadata = [NSMutableArray array]; 
AVMutableMetadataItem *metaItem = [AVMutableMetadataItem metadataItem]; 
metaItem.key = AVMetadataCommonKeyPublisher; 
metaItem.keySpace = AVMetadataKeySpaceCommon; 
metaItem.value = @"your_value"; 
[metadata addObject:metaItem]; 


AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough]; 
exportSession.outputURL = [NSURL fileURLWithPath:"your output path"]; 
CMTime start = CMTimeMakeWithSeconds(0.0, BASIC_TIMESCALE); 
CMTimeRange range = CMTimeRangeMake(start, [asset duration]); 
exportSession.timeRange = range; 
exportSession.outputFileType = AVFileTypeAppleM4V // AVFileTypeMPEG4 or AVFileTypeQuickTimeMovie (video format); 
exportSession.metadata = metadata; 
exportSession.shouldOptimizeForNetworkUse = YES; 
[exportSession exportAsynchronouslyWithCompletionHandler:^{ 
    switch ([exportSession status]) 
    { 
     case AVAssetExportSessionStatusCompleted: 
      NSLog(@"Export sucess"); 
     case AVAssetExportSessionStatusFailed: 
      NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);     
     case AVAssetExportSessionStatusCancelled: 
      NSLog(@"Export canceled"); 
       default: 
        break; 
      } 
     }]; 
+0

이 코드는 기기에서 실행될 때 많은 시간이 소요되는 것 같습니다. 이것을 할 수있는 다른 방법이 있습니까? – NSRover

관련 문제