How to add metaData in video(.mov) in iOS

2.9k Views Asked by At

I already capture video via phone's camera with AVCaptureMovieFileOutput Object,

I want to add new meta data into file,

I try to use AVAssetExportSession to do it, it works !

BUT it cost a lot of time, I guess, this method has re-encode the file,

I just want to add new meta(Location),

I try to use setMetadata method in AVCaptureMovieFileOutput

But I have no idea about how to do so,

I try

meta :

AVMutableMetadataItem *newItem = [AVMutableMetadataItem metadataItem];
newItem.identifier = [AVMutableMetadataItem identifierForKey:AVMetadataQuickTimeMetadataKeyLocationISO6709 keySpace:AVMetadataKeySpaceCommon];
newItem.key = AVMetadataQuickTimeMetadataKeyLocationISO6709;
newItem.value = [self gpsStringForVideo:gps];

first:

[_movieFileOutput setMetadata:@[meta]];
[_movieFileOutput startRecordingToOutputFileURL:outPutUrL recordingDelegate:self];

But I can't get delegate's response.

then:

[_movieFileOutput startRecordingToOutputFileURL:outPutUrL recordingDelegate:self];
[_movieFileOutput setMetadata:@[meta]];

I can start record normally, but output file does not contain any information!

Anyone have any suggestion? Thanks!

1

There are 1 best solutions below

0
Alexander Vasenin On

This works for me:

let metadata = AVMutableMetadataItem()
metadata.keySpace = AVMetadataKeySpaceQuickTimeMetadata
metadata.key = AVMetadataQuickTimeMetadataKeyLocationISO6709 as NSString
metadata.identifier = AVMetadataIdentifierQuickTimeMetadataLocationISO6709
metadata.value = String(format: "%+09.5f%+010.5f%+.0fCRSWGS_84", location.coordinate.latitude, location.coordinate.longitude, location.altitude) as NSString
movieFileOutput.metadata = [metadata]
movieFileOutput.startRecording(toOutputFileURL: temporaryFileUrl(), recordingDelegate: self)

for Objective-C you don't need casts to NSString