Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 416
Devin Avatar asked Oct 19 '22 08:10

Devin


1 Answers

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

like image 82
Alexander Vasenin Avatar answered Oct 21 '22 04:10

Alexander Vasenin