python 读取音频文件的详细信息

有一项测试的需求是判断录像是否和预期一致,检查项是:分辨率录像时长等内容
刚开始考虑使用os模块直接获取文件的详细信息

文件的详细信息.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安装

pip install pymediainfo 

2、下载MediaInfo
点击MediaInfo下载MediaInfo,安装到本地,打开安装所在的路径

获取dll文件.png

将dll文件复制到python更目录下
以上就完成了环境的搭建

开始获取音频文件的详细信息

1.从网上下载一个ts媒体文件

from pymediainfo import MediaInfo
media_info = MediaInfo.parse('C:\\Users\\Administrator\\Desktop\\test.ts')
data = media_info.to_json()
print(data)

更多用法欢迎去pymediainfo的官方文档查找,虽然我没找到
data中就包含了我们所需要的内容,大概长这样,不过里面不知道为什么有很多重复的内容,但是已经满足需求了。

{
  "tracks": [
    {
      "track_type": "General",
      "count": "332",
      "count_of_stream_of_this_kind": "1",
      "kind_of_stream": "General",
      "other_kind_of_stream": [
        "General"
      ],
      "stream_identifier": "0",
      "track_id": 1,
      "other_track_id": [
        "1 (0x1)"
      ],
      "count_of_video_streams": "1",
      "count_of_audio_streams": "1",
      "count_of_menu_streams": "1",
      "video_format_list": "AVC",
      "video_format_withhint_list": "AVC",
      "codecs_video": "AVC",
      "audio_format_list": "AAC",
      "audio_format_withhint_list": "AAC",
      "audio_codecs": "AAC LC",
      "menu_format_list": "AVC / AAC",
      "menu_format_withhint_list": "AVC / AAC",
      "menu_codecs": "AVC / AAC LC",
      "complete_name": "C:\\Users\\Administrator\\Desktop\\test.ts",
      "folder_name": "C:\\Users\\Administrator\\Desktop",
      "file_name": "test.ts",
      "other_file_name": [
        "test"
      ],
      "file_extension": "ts",
      "format": "MPEG-TS",
      "other_format": [
        "MPEG-TS"
      ],
      "format_extensions_usually_used": "ts m2t m2s m4t m4s tmf ts tp trp ty",
      "commercial_name": "MPEG-TS",
      "internet_media_type": "video/MP2T",
      "codec": "MPEG-TS",
      "other_codec": [
        "MPEG-TS"
      ],
      "codec_extensions_usually_used": "ts m2t m2s m4t m4s tmf ts tp trp ty",
      "file_size": 4721808,
      "other_file_size": [
        "4.50 MiB",
        "5 MiB",
        "4.5 MiB",
        "4.50 MiB",
        "4.503 MiB"
      ],
      "duration": "31240.000000",
      "other_duration": [
        "31 s 240 ms",
        "31 s 240 ms",
        "31 s 240 ms",
        "00:00:31.240",
        "00:00:31.240"
      ],
      "overall_bit_rate_mode": "VBR",
      "other_overall_bit_rate_mode": [
        "Variable"
      ],
      "overall_bit_rate": 1208833,
      "other_overall_bit_rate": [
        "1 209 kb/s"
      ],
      "file_creation_date": "UTC 2018-08-26 04:05:47.439",
      "file_creation_date__local": "2018-08-26 12:05:47.439",
      "file_last_modification_date": "UTC 2018-08-26 04:05:49.220",
      "file_last_modification_date__local": "2018-08-26 12:05:49.220",
      "overallbitrate_precision_min": "1208813",
      "overallbitrate_precision_max": "1208852"
    },
    {
      "track_type": "Video",
      "count": "344",
      "count_of_stream_of_this_kind": "1",
      "kind_of_stream": "Video",
      "other_kind_of_stream": [
        "Video"
      ],
      "stream_identifier": "0",
      "streamorder": "0-0",
      "track_id": 256,
      "other_track_id": [
        "256 (0x100)"
      ],
      "menu_id": 1,
      "other_menu_id": [
        "1 (0x1)"
      ],
      "format": "AVC",
      "format_info": "Advanced Video Codec",
      "format_url": "http://developers.videolan.org/x264.html",
      "commercial_name": "AVC",
      "format_profile": "Main@L3.1",
      "format_settings": "CABAC / 4 Ref Frames",
      "format_settings__cabac": "Yes",
      "other_format_settings__cabac": [
        "Yes"
      ],
      "format_settings__reframes": 4,
      "other_format_settings__reframes": [
        "4 frames"
      ],
      "internet_media_type": "video/H264",
      "codec_id": "27",
      "codec": "AVC",
      "other_codec": [
        "AVC"
      ],
      "codec_family": "AVC",
      "codec_info": "Advanced Video Codec",
      "codec_url": "http://developers.videolan.org/x264.html",
      "codec_profile": "Main@L3.1",
      "codec_settings": "CABAC / 4 Ref Frames",
      "codec_settings__cabac": "Yes",
      "codec_settings_refframes": "4",
      "duration": 31280,
      "other_duration": [
        "31 s 280 ms",
        "31 s 280 ms",
        "31 s 280 ms",
        "00:00:31.280",
        "00:00:31.280"
      ],
      "nominal_bit_rate": 1024000,
      "other_nominal_bit_rate": [
        "1 024 kb/s"
      ],
      "width": 1280,
      "other_width": [
        "1 280 pixels"
      ],
      "height": 720,
      "other_height": [
        "720 pixels"
      ],
      "sampled_width": "1280",
      "sampled_height": "720",
      "pixel_aspect_ratio": "1.000",
      "display_aspect_ratio": "1.778",
      "other_display_aspect_ratio": [
        "16:9"
      ],
      "frame_rate_mode": "VFR",
      "other_frame_rate_mode": [
        "Variable"
      ],
      "resolution": 8,
      "other_resolution": [
        "8 bits"
      ],
      "colorimetry": "4:2:0",
      "color_space": "YUV",
      "chroma_subsampling": "4:2:0",
      "other_chroma_subsampling": [
        "4:2:0"
      ],
      "bit_depth": 8,
      "other_bit_depth": [
        "8 bits"
      ],
      "scan_type": "Progressive",
      "other_scan_type": [
        "Progressive"
      ],
      "interlacement": "PPF",
      "other_interlacement": [
        "Progressive"
      ],
      "delay": "1481.000",
      "other_delay": [
        "1 s 481 ms",
        "1 s 481 ms",
        "1 s 481 ms",
        "00:00:01.481"
      ],
      "delay__origin": "Container",
      "other_delay__origin": [
        "Container"
      ],
      "writing_library": "x264 - core 148",
      "other_writing_library": [
        "x264 core 148"
      ],
      "encoded_library_name": "x264",
      "encoded_library_version": "core 148",
      "encoding_settings": "cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x1:0 / me=dia / subme=2 / psy=0 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=4 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=0 / open_gop=0 / weightp=2 / keyint=75 / keyint_min=25 / scenecut=60 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=1024 / ratetol=1.0 / qcomp=0.40 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=1500 / vbv_bufsize=1500 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00"
    },
    {
      "track_type": "Audio",
      "count": "275",
      "count_of_stream_of_this_kind": "1",
      "kind_of_stream": "Audio",
      "other_kind_of_stream": [
        "Audio"
      ],
      "stream_identifier": "0",
      "streamorder": "0-1",
      "track_id": 257,
      "other_track_id": [
        "257 (0x101)"
      ],
      "menu_id": 1,
      "other_menu_id": [
        "1 (0x1)"
      ],
      "format": "AAC",
      "format_info": "Advanced Audio Codec",
      "commercial_name": "AAC",
      "format_version": "Version 4",
      "format_profile": "LC",
      "muxing_mode": "ADTS",
      "codec_id": "15",
      "codec": "AAC LC",
      "other_codec": [
        "AAC LC"
      ],
      "duration": 31093,
      "other_duration": [
        "31 s 93 ms",
        "31 s 93 ms",
        "31 s 93 ms",
        "00:00:31.093",
        "00:00:31.093"
      ],
      "bit_rate_mode": "VBR",
      "other_bit_rate_mode": [
        "Variable"
      ],
      "channel_s": 2,
      "other_channel_s": [
        "2 channels"
      ],
      "channel_positions": "Front: L R",
      "other_channel_positions": [
        "2/0/0"
      ],
      "channellayout": "L R",
      "samples_per_frame": "1024",
      "sampling_rate": 44100,
      "other_sampling_rate": [
        "44.1 kHz"
      ],
      "samples_count": "1371201",
      "frame_rate": "43.066",
      "other_frame_rate": [
        "43.066 FPS (1024 SPF)"
      ],
      "compression_mode": "Lossy",
      "other_compression_mode": [
        "Lossy"
      ],
      "delay": "1400.000",
      "other_delay": [
        "1 s 400 ms",
        "1 s 400 ms",
        "1 s 400 ms",
        "00:00:01.400"
      ],
      "delay__origin": "Container",
      "other_delay__origin": [
        "Container"
      ],
      "delay_relative_to_video": -81,
      "other_delay_relative_to_video": [
        "-81 ms",
        "-81 ms",
        "-81 ms",
        "-00:00:00.081"
      ],
      "video0_delay": -81,
      "other_video0_delay": [
        "-81 ms",
        "-81 ms",
        "-81 ms",
        "-00:00:00.081"
      ]
    },
    {
      "track_type": "Menu",
      "count": "94",
      "count_of_stream_of_this_kind": "1",
      "kind_of_stream": "Menu",
      "other_kind_of_stream": [
        "Menu"
      ],
      "stream_identifier": "0",
      "streamorder": "0",
      "track_id": 4096,
      "other_track_id": [
        "4096 (0x1000)"
      ],
      "menu_id": 1,
      "other_menu_id": [
        "1 (0x1)"
      ],
      "format": "AVC / AAC",
      "commercial_name": "AVC / AAC",
      "codec": "AVC / AAC LC",
      "other_codec": [
        "AVC / AAC LC"
      ],
      "duration": "31240.000000",
      "other_duration": [
        "31 s 240 ms",
        "31 s 240 ms",
        "31 s 240 ms",
        "00:00:31.240",
        "00:00:31.240"
      ],
      "delay": "1401.000000",
      "other_delay": [
        "1 s 401 ms",
        "1 s 401 ms",
        "1 s 401 ms",
        "00:00:01.401"
      ],
      "list_streamkind": "1 / 2",
      "list_streampos": "0 / 0",
      "list": "256 / 257",
      "other_list": [
        "256 (0x100) (AVC) / 257 (0x101) (AAC)"
      ],
      "service_name": "Service01",
      "service_provider": "FFmpeg",
      "service_type": "digital television",
      "pointer_field": "0",
      "section_length": "23"
    }
  ]
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266

推荐阅读更多精彩内容

  • 一个基本的计算机系统由“硬件”和“软件”组成,一台Linux设备,主要的组成如下图所示: 一般情况下,我们所说的L...
    时待吾阅读 1,580评论 0 16
  • LINUX下文件的操作 以下均已为ubuntu 18.04 LTS环境。 文件的打开open打开文件的函数原型:*...
    快扶我起来搬砖阅读 234评论 0 0
  • 把雨伞放在了家里,看了天气预报说今天不会下雨,带着它觉得增加了重量。可能在某天下班时会下雨,然后想起来没带伞。这是...
    厘鱼阅读 329评论 0 2
  • 2018-07-18 姓名:郭祥华 组别:315期六项精进努力一组 【日精进打卡第260】 【知~学习】 背诵《六...
    华英雄_712d阅读 168评论 0 0
  • 期末考试简直败了怎么破!嘤嘤嘤嘤嘤嘤
    赵夏曦阅读 104评论 0 0