How to change video metadata using AVAssetWriter?

我怕爱的太早我们不能终老 提交于 2019-12-10 17:47:37

问题


How to change a video(.mp4) meta-info using a AVAssetWriter API?

I want to not re-encode. only wanted to modify the video meta-info.

how to write a next code?

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

if I mistaken, give me some hint.

Thanks!!


回答1:


refer a following code.

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;
             }
         }];


来源:https://stackoverflow.com/questions/11505489/how-to-change-video-metadata-using-avassetwriter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!