4

AVAssetWriterAPIを使用してビデオ(.mp4)メタ情報を変更するにはどうすればよいですか?

再エンコードしたくない。ビデオのメタ情報を変更したかっただけです。

次のコードを書く方法は?

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

間違えた場合は、ヒントを教えてください。

ありがとう!!

4

1 に答える 1

6

次のコードを参照してください。

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;
             }
         }];
于 2012-07-25T11:33:19.090 に答える