AVFoundation – AVMetadataItem 获取媒体属性元数据
目錄
- 一.前言
- 1.AVAsset
- 2.AVAssetTrack
- 3.AVComposition / AVMutableComposition
- 4.AVMutableVideoComposition
- 5.AVMutableCompositionTrack
- 6.AVMutableVideoCompositionLayerInstruction
- 7.AVMutableVideoCompositionInstruction
- 8.AVAssetExportSession
- 二.AVMetadataItem 簡介
- 三.使用 availableMetadataFormats 獲取元數(shù)據(jù)
- 四.使用 metadata 獲取元數(shù)據(jù)
- 五.編輯元數(shù)據(jù)
- 六.猜你喜歡
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> Object-C 基礎(chǔ)
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> Object-C 線程
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> OpenGL ES
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> GPUImage
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> AVFoundation
零基礎(chǔ) Object-C 學(xué)習(xí)路線推薦 : Object-C 學(xué)習(xí)目錄 >> CocoaPods
一.前言
1.AVAsset
Assets 可以來自一個文件或用戶的相冊,可以理解為多媒體資源,通過 URL 作為一個 asset 對象的標(biāo)識. 這個 URL 可以是本地文件路徑或網(wǎng)絡(luò)流;
2.AVAssetTrack
AVAsset 包含很多軌道 **AVAssetTrack **的結(jié)合,如 audio, video, text, closed captions, subtitles…
3.AVComposition / AVMutableComposition
**使用 AVMutableComposition 類可以增刪 AVAsset 來將單個或者多個 AVAsset 集合到一起,用來合成新視頻。**除此之外,若想將集合到一起的視聽資源以自定義的方式進(jìn)行播放,需要使用 AVMutableAudioMix 和 AVMutableVideoComposition 類對其中的資源進(jìn)行協(xié)調(diào)管理;
4.AVMutableVideoComposition
AVFoundation 類 API 中最核心的類是 AVVideoComposition / AVMutableVideoComposition 。
AVVideoComposition / AVMutableVideoComposition 對兩個或多個視頻軌道組合在一起的方法給出了一個總體描述。它由一組時間范圍和描述組合行為的介紹內(nèi)容組成。這些信息出現(xiàn)在組合資源內(nèi)的任意時間點(diǎn)。
AVVideoComposition / AVMutableVideoComposition 管理所有視頻軌道,可以決定最終視頻的尺寸,裁剪需要在這里進(jìn)行;
5.AVMutableCompositionTrack
將多個 AVAsset 集合到一起合成新視頻中軌道信息,有音頻軌、視頻軌等,里面可以插入各種對應(yīng)的素材(畫中畫,水印等);
6.AVMutableVideoCompositionLayerInstruction
AVMutableVideoCompositionLayerInstruction 主要用于對視頻軌道中的一個視頻處理縮放、模糊、裁剪、旋轉(zhuǎn)等;
7.AVMutableVideoCompositionInstruction
表示一個指令,決定一個 timeRange 內(nèi)每個軌道的狀態(tài),每一個指令包含多個 AVMutableVideoCompositionLayerInstruction ;而 AVVideoComposition 由多個 AVVideoCompositionInstruction 構(gòu)成;
AVVideoCompositionInstruction 所提供的最關(guān)鍵的一段數(shù)據(jù)是組合對象時間軸內(nèi)的時間范圍信息。這一時間范圍是在某一組合形式出現(xiàn)時的時間范圍。要執(zhí)行的組全特質(zhì)是通過其 AVMutableVideoCompositionLayerInstruction 集合定義的。
8.AVAssetExportSession
AVAssetExportSession 主要用于導(dǎo)出視頻;
二.AVMetadataItem 簡介
AVAsset 和 AVAssetTrack 都可以實(shí)現(xiàn)查詢相關(guān)元數(shù)據(jù)的功能.一般使用 AVAsset 提供的元數(shù)據(jù)當(dāng)涉及獲取曲目一級元數(shù)據(jù)等情況時會使用 AVAssetTrack ,使用 AVAsset 獲取元數(shù)據(jù)相關(guān)如下:
/* 包含著當(dāng)前視頻常見格式類型的元數(shù)據(jù) */ @property (nonatomic, readonly) NSArray<AVMetadataItem *> *commonMetadata;// 包含當(dāng)前視頻所有格式類型的元數(shù)據(jù). @property (nonatomic, readonly) NSArray<AVMetadataItem *> *metadata API_AVAILABLE(macos(10.10), ios(8.0), tvos(9.0), watchos(1.0));// 包含當(dāng)前視頻所有可用元數(shù)據(jù)的格式類型元數(shù)據(jù)的格式類型在AVMetadataFormat中定義了很多種,常見的有title、creator、subject、publisher等. @property (nonatomic, readonly) NSArray<AVMetadataFormat> *availableMetadataFormats;AVMetadataFormat 如下:
// Metadata common keysAVF_EXPORT AVMetadataKey const AVMetadataCommonKeyTitle ;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyCreator;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeySubject;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyDescription;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyPublisher;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyContributor;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyCreationDate;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyLastModifiedDate;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyType;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyFormat;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyIdentifier;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeySource;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyLanguage;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyRelation;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyLocation;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyCopyrights;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyAlbumName;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyAuthor;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyArtist;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyArtwork;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyMake;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyModel ;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeySoftware ;AVF_EXPORT AVMetadataKey const AVMetadataCommonKeyAccessibilityDescription;三.使用 availableMetadataFormats 獲取元數(shù)據(jù)
/******************************************************************************************/ //@Author:猿說編程 //@Blog(個人博客地址): www.codersrc.com //@File:C語言教程 - AVMetadataItem 獲取媒體屬性元數(shù)據(jù) //@Time:2021/07/29 07:30 //@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累! /******************************************************************************************/NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"456.mp3" ofType:nil]];AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:url options:nil];for (AVMetadataFormat item in [asset availableMetadataFormats]) {NSArray *medata = [asset metadataForFormat:item];for (AVMetadataItem *mitem in medata) {NSLog(@"%@:%@",mitem.key,mitem.value);} }/* 2021-07-24 23:22:28.863338+0800 LearnAVFoundation[7405:497502] TXXX:3923013_396752 2021-07-24 23:22:28.863393+0800 LearnAVFoundation[7405:497502] TCON:3923013_396752 2021-07-24 23:22:28.863429+0800 LearnAVFoundation[7405:497502] TSSE:Lavf56.4.101 2021-07-24 23:22:28.863464+0800 LearnAVFoundation[7405:497502] TPOS:1 2021-07-24 23:22:28.863499+0800 LearnAVFoundation[7405:497502] TRCK:12 2021-07-24 23:22:28.863529+0800 LearnAVFoundation[7405:497502] TPE1:Thia Megia 2021-07-24 23:22:28.863574+0800 LearnAVFoundation[7405:497502] APIC:{length = 665140, bytes = 0x89504e47 0d0a1a0a 0000000d 49484452 ... 49454e44 ae426082 } 2021-07-24 23:22:28.863606+0800 LearnAVFoundation[7405:497502] COMM:163 key(Don't modify):L64FU3W4YxX3ZFTmbZ+8/cmlcJixcHCmHiX1THVPt/hhwCr8IK4+AdU6ba2JAq6yLF2az6pftnczEio2AkbRn47o8pfzLEbtKa3vNxCKaBpQujCz48iUDx0+FASY522oYNHmaeewFYBc+xLPSfsyaUgHaQaa/ojLxzzWUVv50Mg/I2IoOKyxPTUquetcGKXGgEofzvAcSlem6yEo7nkM9Nkmbhv7/ne7NlU5GvpG8nOvoBYZiG5otuvxV8pc7ti7ATYNINAs3qHiA2LTuJ9l6CxYtCboFlRr29BVyJSH1eMjIA9m04AEobEgVsuiyG+VXTNeh8imOV8WG268fh5dRxD0EEYDscUALQfptmS3TWSoyM7LF6ASZYn7aBZNkheSYNjgijkkEAt31UpVbNbLjW+HyJwvJyJ/Tls9A9h0PFfmIbeSTrjenxpMz22eRkw/WM3snECea8IhyNFe71F0VXmiZFi5/A6aiBv2EJrHFDKQWD1ktANXSTiTcjmLIEIb7b8cQdI8quSJAZ02VcS4zA== 2021-07-24 23:22:28.863647+0800 LearnAVFoundation[7405:497502] TIT2:Colors Of The Wind 2021-07-24 23:22:28.863676+0800 LearnAVFoundation[7405:497502] TALB:American Idol Top 12 Season 10 */四.使用 metadata 獲取元數(shù)據(jù)
/******************************************************************************************/ //@Author:猿說編程 //@Blog(個人博客地址): www.codersrc.com //@File:C語言教程 - AVMetadataItem 獲取媒體屬性元數(shù)據(jù) //@Time:2021/07/29 07:30 //@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累! /******************************************************************************************/NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"456.mp3" ofType:nil]];AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:url options:nil];[asset loadValuesAsynchronouslyForKeys:@[@"metadata"] completionHandler:^{AVKeyValueStatus commonStatus = [asset statusOfValueForKey:@"metadata" error:nil];if (commonStatus == AVKeyValueStatusLoaded) {// 歌曲名稱AVMetadataItem *titleItem = [AVMetadataItem metadataItemsFromArray:asset.metadata filteredByIdentifier:AVMetadataCommonIdentifierTitle].firstObject;// 演唱者AVMetadataItem *artistItem = [AVMetadataItem metadataItemsFromArray:asset.metadata filteredByIdentifier:AVMetadataCommonIdentifierArtist].firstObject;// 專輯名稱AVMetadataItem *albumItem = [AVMetadataItem metadataItemsFromArray:asset.metadata filteredByIdentifier:AVMetadataCommonIdentifierAlbumName].firstObject;NSLog(@"%@ : %@", titleItem.key, titleItem.value);NSLog(@"%@ : %@", artistItem.key, artistItem.value);NSLog(@"%@ : %@", albumItem.key, albumItem.value);} }];/* 2021-07-24 23:25:12.442039+0800 LearnAVFoundation[7441:500002] TIT2 : Colors Of The Wind 2021-07-24 23:25:12.442086+0800 LearnAVFoundation[7441:500002] TPE1 : Thia Megia 2021-07-24 23:25:12.442113+0800 LearnAVFoundation[7441:500002] TALB : American Idol Top 12 Season 10 */五.編輯元數(shù)據(jù)
AVAsset 是一個不可變類,如果要保存元數(shù)據(jù)的修改,使用 AVAssetExportSession 導(dǎo)出一個新的資源副本以及元數(shù)據(jù)改動。
AVAssetExportSession 用于將 AVAsset 內(nèi)容根據(jù)導(dǎo)出預(yù)設(shè)條件進(jìn)行轉(zhuǎn)碼,并將導(dǎo)出資源寫到磁盤。它提供了多個功能來實(shí)現(xiàn)將一種格式轉(zhuǎn)換為另一種格式、修訂資源的內(nèi)容、修改資源的音頻和視頻行為、寫入新的元數(shù)據(jù)。
創(chuàng)建一個 AVAssetExportSession 實(shí)例需要提供資源和導(dǎo)出預(yù)設(shè)。導(dǎo)出預(yù)設(shè)用于確定導(dǎo)出內(nèi)容的質(zhì)量、大小等屬性。創(chuàng)建導(dǎo)出會話后,還要指定導(dǎo)出內(nèi)容地址 outputURL ,最后調(diào)用 exportAsynchronouslyWithCompletionHandler 開始導(dǎo)出。
跳轉(zhuǎn)閱讀全文…
**注意:**AVAssetExportPresetPassthrough 可以修改存在的元數(shù)據(jù)信息,不過它不能添加新的元數(shù)據(jù),添加元數(shù)據(jù)唯一方法是使用轉(zhuǎn)碼預(yù)設(shè)值。
六.猜你喜歡
- AVAsset 加載媒體
- AVAssetTrack 獲取視頻 音頻信息
- AVMetadataItem 獲取媒體屬性元數(shù)據(jù)
- AVAssetImageGenerator 截圖
- AVAssetImageGenerator 獲取多幀圖片
- AVAssetExportSession 裁剪/轉(zhuǎn)碼
- AVPlayer 播放視頻
- AVPlayerItem 管理資源對象
- AVPlayerLayer 顯示視頻
- AVQueuePlayer 播放多個媒體文件
- AVComposition AVMutableComposition 將多個媒體合并
- AVVideoComposition AVMutableVideoComposition 管理所有視頻軌道
未經(jīng)允許不得轉(zhuǎn)載:猿說編程 ? AVFoundation – AVMetadataItem 獲取媒體屬性元數(shù)據(jù)
總結(jié)
以上是生活随笔為你收集整理的AVFoundation – AVMetadataItem 获取媒体属性元数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pypi.python.org_在Pyp
- 下一篇: qt获取当前场景中的所有图形项的层次