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 回答