@ WWDC 15
AVAsset > AVComposition > AVMutableComposition
AVAsset > AVMovie > AVMutableMovie
AVAssetTrack > AVCompositionTrack > AVMutableCompositionTrack
AVMovieTrackc > AVMutableMovieTrack
- AVMoviee, AVMutableMovie
- AVMovieTrack, AVMutableMovieTrack
- AVMediaDataStorage
-
A Sequence of boxes (<- box๋ผ๋ ํํ์ ์ฌ์ฉํด์ ๋ฐ์ดํฐ๋ค์ ํํํ๋๋)
-
File Type / Unused / Movie / Sample Data
๊ทธ ์ค์์๋ Movie Box๋ global settings, metadata, track information์ ๊ฐ์ง
Global Settings | Movie Metadata | Track Boxes |
---|---|---|
Track count, duration, creation date, preferred rate | Copyright statement, Author, titlle, custom metadata | Track type, sample data location, track metadata, track associations |
ํธ๋ ๋ฐ์ค๋ ์ํ ๋ฐ์ดํฐ๋ฅผ ์ฐธ์กฐํด์ ํธ๋์ผ๋ก ์ ๋ฆฌํ๋ค. (Sample references) ๋, ์ธ๋ถ ์ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ๋ฆฌํฌ ์๋ ์๋ค.
- Provide a powerful workflow tool
- But sample reference movies are inherently fragile
- To help reduce that fragility, use relative URLs
- When it's time to deliver content, export it using AVAssetExportSession
-
AVMovie provides inspection and header-writing methods
- Get a list of tracks in th movie
- Retrieve the movie header from an existing file
- Write a movie header into a new file
-
let movie = AVMovie(URL: inputURL, options: nil)
-
let movie = AVMovie(data: inputData, options: nil)
-
Create a sample reference movie file
let movies = AVMovie(URL: inputURL, options: nil) let options = AVMovieWritingOptions.TruncateDestinationToMovieHeaderOnly try movie.writeMovieHeaderToURL(outputURL, fileType: AVFileTypeQuickTimeMovie, options: options)
-
AVMutableMovie adds editing methods:
- Perform range-based track editing
- Set track associations between tracks
- Add or modify track metadata
-
func removeTimeRange(timeRange: CMTimeRange)
-
func insertEmptyTimeRange(timeRange: CMTimeRange)
-
func scaleTimeRange(timeRange: CMTimeRange, toDuration: CMTime)
-
func insertTimeRange(timeRange, CMTimeRange, ofTrack: AVAssetTrack, atTiime: CMTime, copySampleData: Bool) throws
-
Setting the container for a track's new sample data
track.mediaDataStorage = AVMediaDataStorage(URL: movURL, options: nil)
-
func addTrackAssociationToTrack(movieTrack: AVMovieTrack, type: String)
-
func removeTrackAssociatioinToTrack(movieTrack: AVMovieTrack, type: String)
-
Use case: using relative URLs to reference data
let url = NSURL(fileURLWithPath: "/Users/monroe/tristo_boston/movies") for track in movies.tracks { track.sampleReferenceBaseURL = url }
์ฌ๊ธฐ์ ๋ณด์ฌ ์ค ์์ ๋ 1.5 ํ ๋ผ์ ๋ฐ์ดํฐ๋ฅผ ์ด๋ป๊ฒ ๋ค๋ฃฐ ๊ฒ์ธ์ง!
- Step 1: Combine each sortie's MPEG-4 fiiles into one sampple reference movie file
- Step 2: Add indexing metadata as movie metadata
- Steep 3: Add GPS data as a timed metadata track
Do this all without modifying the original files and minimizing data copying
Combine camera files into a sample reference movie file
let movie = AVMutableMovie(URL: url1, options: nil)
let asset = AVURLAsset(URL: url2, options: nil)
let range = CMTimeRangeMake(kCMTimeZero, asset.duration)
try movie.insertTimeRange(range, ofAsset: asset, atTime: movie.duration, copySampleData: false)
try movie.writeMovieHeaderToURL(dstURL, fileType: AVFileTypeQuickTimeMovie, options: AVMovieWritingOptions.AddMovieHeaderToDestination)
Add custom metadata
var metadataArray = movie.metadata
var newItem = AVMutableMetadataItem()
newItem.identifier = "mdta/com.example.weather.wind"
newItm.locale = NSLocale.currentLocale()
newItem.value = averageWindSpedValue
newItem.extraAttributes = nil
metadataArray.append(newItem)
movie.metadata = metadataArray
Create a movie file containing location timed metadata
- See "Harnessing Metadata in Audiovisual Media", WWDC 2014
- Sample code: AVCaptureLocation and AVTmedAnnotationWriter
Add a timed metadata track for l!)
let vidTrack = movie.tracksWithMediaTye(AVMediaTypeVideo).first
let type = AVTrackAssociationTypeMetadataReferent
newTrack.addTrackAssociationToTrack(vidTrack, type)
- New editing features pprovide accss to QuickTime movie file format
- Allows simplified editing workflows, especially when handling large amounts of data
- Sample code:
AVMovieEditor