有一项测试的需求是判断录像是否和预期一致,检查项是:分辨率、录像时长等内容
文件的详细信息.png
os模块有一个stat()方法
st_mode: inode 保护模式
st_ino: inode 节点号。
st_dev: inode 驻留的设备。
st_nlink: inode 的链接数。
st_uid: 所有者的用户ID。
st_gid: 所有者的组ID。
st_size: 普通文件以字节为单位的大小;包含等待某些特殊文件的数据。
st_atime: 上次访问的时间。
st_mtime: 最后一次修改的时间。
st_ctime: 由操作系统报告的"ctime"。在某些系统上(如Unix)是最新的元数据更改的时间,在其它系统上(如Windows)是创建时间。常规属性
文件的常规属性.png
pymediainfo
pymediainfo 安装
1、使用pip安装
1pip install pymediainfo
2、下载MediaInfo
获取dll文件.png
将dll文件复制到python更目录下
以上就完成了环境的搭建
开始获取音频文件的详细信息
1.从网上下载一个ts媒体文件
1from pymediainfo import MediaInfo
2media_info = MediaInfo.parse('C:\\Users\\Administrator\\Desktop\\test.ts')
3data = media_info.to_json()
4print(data)
更多用法欢迎去pymediainfo的官方文档查找,虽然我没找到data中就包含了我们所需要的内容,大概长这样,不过里面不知道为什么有很多重复的内容,但是已经满足需求了。
1{
2 "tracks": [
3 {
4 "track_type": "General",
5 "count": "332",
6 "count_of_stream_of_this_kind": "1",
7 "kind_of_stream": "General",
8 "other_kind_of_stream": [
9 "General"
10 ],
11 "stream_identifier": "0",
12 "track_id": 1,
13 "other_track_id": [
14 "1 (0x1)"
15 ],
16 "count_of_video_streams": "1",
17 "count_of_audio_streams": "1",
18 "count_of_menu_streams": "1",
19 "video_format_list": "AVC",
20 "video_format_withhint_list": "AVC",
21 "codecs_video": "AVC",
22 "audio_format_list": "AAC",
23 "audio_format_withhint_list": "AAC",
24 "audio_codecs": "AAC LC",
25 "menu_format_list": "AVC / AAC",
26 "menu_format_withhint_list": "AVC / AAC",
27 "menu_codecs": "AVC / AAC LC",
28 "complete_name": "C:\\Users\\Administrator\\Desktop\\test.ts",
29 "folder_name": "C:\\Users\\Administrator\\Desktop",
30 "file_name": "test.ts",
31 "other_file_name": [
32 "test"
33 ],
34 "file_extension": "ts",
35 "format": "MPEG-TS",
36 "other_format": [
37 "MPEG-TS"
38 ],
39 "format_extensions_usually_used": "ts m2t m2s m4t m4s tmf ts tp trp ty",
40 "commercial_n