我們可以使用 Mutagen 和 Python 中的 eyeD3 模組存取音訊檔案的元資料。對於視訊元數據,我們可以使用電影和 Python 中的 OpenCV 庫。元資料是提供有關其他資料(例如音訊和視訊資料)的資訊的資料。音訊和視訊檔案的元資料包括檔案格式、檔案解析度、檔案大小、持續時間、位元率等。透過存取這些元數據,我們可以更有效地管理媒體並分析元數據以獲得一些有用的信息。在本文中,我們將了解 Python 提供的一些用於存取音訊和視訊檔案元資料的庫或模組。
存取音訊元資料
一些用於存取音訊檔案元資料的庫是 -
使用誘變劑庫
Mutagen 是一個開源 Python 模組,用於處理音訊元資料。它支援幾乎所有類型的音訊文件,如mp3、mp4、OGG、FLAC等。 Mutagen用於存取音訊檔案的元數據,也用於操作音訊資料。
在使用mutagen之前,我們可以使用Python中的pip指令安裝mutagen。
pip install mutagen
Pip 是一個 Python 套件管理器。 Pip install mutagen 會在您的本機檔案中安裝 mutagen 函式庫。
文法
audio["TIT2"].text[0]
audio[“TIT2”] 屬性以鍵值對的形式傳回一個對象,其中包含有關音訊檔案的各種資訊。使用物件中的文字鍵存取音訊檔案的標題。
audio.info.length
audio.info傳回一個包含音訊檔案所有資訊的物件。可以使用audio.info.length來存取音訊檔案的長度,它會返回以秒為單位的長度。
範例
以下是如何使用 mutagen 中的 mutagen.mp3 模組存取 mp3 檔案的元資料的範例。
from mutagen.mp3 import MP3 audio = MP3("audio.mp3") # put your audio file in the place of audio.mp3 print(audio.info.length) # Print the length of the audio file print(audio["TIT2"].text[0]) # Print the title of the audio file
輸出
222.17142857142858 Suhana Safar Par Prem Nagar Hai
使用eyeD3函式庫
eyeD3 也是一個 Python 開源程式庫,用於處理音訊文件,特別是 mp3 音訊檔案。使用eyeD3,我們可以讀取和寫入音訊檔案的元數據,還可以操作或更新音訊檔案。
在使用 eyeD3 之前,我們可以使用 python 中的 pip 指令來安裝它 -
pip install eyeD3
Pip 是一個 Python 套件管理器。 Pip install eyeD3 在本機檔案中安裝 eyeD3 函式庫。
文法
eyed3.load(your_audio_file)
eyed3.load()函數載入音訊檔案並且可以儲存在變數中。參數your_audio_file是您需要載入的音訊檔案的路徑。
演算法
使用eyed3.load函數載入任何音訊檔案
#使用audio.info.time_secs屬性存取音訊檔案長度。
使用 audio.tag.title 屬性存取音訊檔案的標題。
範例
這裡是使用eyeD3存取音訊檔案元資料的範例。
import eyed3 audio = eyed3.load("audio.mp3") # put your audio file in the place of audio.mp3 print(audio.info.time_secs) # Print the length of the audio file print(audio.tag.title) # Print the title of the audio file
輸出
223.33 Suhana Safar Par Prem Nagar Hai
存取視訊元資料
Python 還有一些用於存取視訊檔案元資料的開源庫,例如 -
方法1:使用Moviepy庫
moviepy 是一個開源的 Python 函式庫,用於影片編輯。它還可以用來存取視訊檔案的元資料。 Moviepy 支援多種影片檔案格式,如 mp4、AVI、MOV 等。 Moviepy 可以幫助我們讀取和寫入影片檔案的元數據,並對影片檔案進行操作。
在使用 moviepy 之前,您必須使用 python 中的 pip 指令安裝 moviepy 函式庫: -
pip install moviepy
演算法
要使用moviepy來存取視訊檔案的元數據,我們必須 -
從moviepy.editor匯入VideoFileClip模組
#使用VideoClipFile載入影片檔案
使用movipy的屬性(如duration,size等)存取已載入的視訊檔案的元資料。
範例
我們將從moviepy.editor套件中匯入VideoFileClip模組,然後使用VideoFileClip模組載入我們的影片檔案。 Video.duration和video.size分別傳回影片檔案的持續時間和顯示尺寸。
from moviepy.editor import VideoFileClip video = VideoFileClip("video.mp4") print(video.duration) # Print the duration of the video print(video.size) # Print the size of the video
輸出
50.74 [1920, 1080]
使用OpenCV函式庫
OpenCV是一個在Python中使用的開源電腦視覺庫,用於處理視訊資料。它還可以用於存取各種視訊檔案格式(如MP4、AVI、MOV等)的元資料。可以使用OpenCV讀取和寫入視訊檔案的元數據,並進行視訊處理。
在使用 cv2 模組之前,我們必須使用 Python 中的 pip 指令安裝 opencv-python-headless -
pip install opencv-python-headless
Pip 是一個 Python 套件管理器。 Pip install opencv-python-headless 在您的本機檔案中安裝了 openCv 程式庫。
文法
video.get(cv2.CAP_PROP_FPS)
Cv2 .CAP_PROP_FPS 傳回視訊檔案的幀速率。使用 video.get() 函數傳回特定影片的幀速率。
video.get(cv2.CAP_PROP_FRAME_WIDTH)
cv2.CAP_PROP_FRAME_WIDTH傳回視訊檔案的幀寬度。使用video.get()函數可以傳回特定視訊的幀寬度。
video.get(cv2.CAP_PROP_FRAME_HEIGHT)
cv2.CAP_PROP_FRAME_HEIGHT 傳回視訊檔案的幀高度。使用 video.get() 函數傳回特定影片的幀高度。
算法
要使用OpenCV访问视频文件的元数据,我们必须执行以下操作−
导入opencv
使用 cv2.VideoCapture 属性加载视频文件
使用 CAP_PROP_FRAME_WIDTH、FRAME_HEIGHT 等属性访问文件的各种元数据。
示例
使用 cv2.VideoCapture 模块将视频文件导入变量中。现在,这个存储的视频文件可用于使用 cv2 模块中的 CAP_PROP_FPS、CAP_PROP_FRAME_WIDTH 等属性获取元数据。
import cv2 video = cv2.VideoCapture("video.mp4") fps = video.get(cv2.CAP_PROP_FPS) # Get the frame rate of the video width = video.get(cv2.CAP_PROP_FRAME_WIDTH) # Get the width of the video height = video.get(cv2.CAP_PROP_FRAME_HEIGHT) # Get the height of the video print(fps, width, height) # Print the frame rate, width, and height of the video
输出
60.0 1920.0 1080.0
结论
在本文中,我们讨论了 Python 提供的一些用于访问音频和视频文件元数据的库。对于音频文件,我们探索了 mutagen 和 eyeD3 库;对于视频文件,我们探索了 moviepy 和 openCV 库。 Python 中还有许多其他库可用于访问音频和视频文件的元数据。最好浏览这些库的文档,以便更好地了解这些库提供的功能。
以上是使用Python存取各種音訊和視訊檔案的元數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

ThescriptisrunningwiththewrongPythonversionduetoincorrectdefaultinterpretersettings.Tofixthis:1)CheckthedefaultPythonversionusingpython--versionorpython3--version.2)Usevirtualenvironmentsbycreatingonewithpython3.9-mvenvmyenv,activatingit,andverifying

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中