FFmpeg之ffprobe

   本文章内容局限于本人当前知识水平,如果有不当的地方或者更好的方法,欢迎大家批评指正。谢谢。 

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。

Part Description
libavformat 用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和读取音视频帧等功能
libavcodec 用于各种类型声音/图像编解码
libavutil 包含一些公共的工具函数
libswscale 用于视频场景比例缩放、色彩映射转换
libpostproc 用于后期效果处理
ffmpeg 该项目提供的一个工具,可用于格式转换、解码或电视卡即时编码等
ffsever 一个 HTTP 多媒体即时广播串流服务器
ffplay 是一个简单的播放器,使用ffmpeg 库解析和解码,通过SDL显示

其中目前我最常用的是ffmpeg,简直说是一个视频/图像领域十分强大的工具,值得CV处理领域的人深入学习。
再说ffprobe,最近正在做视频的手工特征提取,在提取比特率的时候遇到了意想不到的困难,查看一个视频的比特率十分简单,直接ffmpeg -i xxx.mp4就可以查看一个视频几乎所有的信息,当然opencv也可以查看视频的某一些信息,但是没有比特率,甚至你右击视频的属性也能可能到比特率。问题是,加上我需要处理数量十分庞大的视频,目前而前言我没有发现什么比较好的处理方法。经过一下午的思考(疯狂百度,疯狂Debug),找到了比较好的方案,在这里和大家分享一下,就用了ffporbe,ffprobe可以从多媒体流中收集信息,并且以人类和机器可读的方式进行输出,或者打印。
在使用之前需要先安装ffmpeg,具体安装方法可以找度娘,安装相对来说十分简单。我只讲一下自己暂时用到的,我这里在python中调用cmd,执行ffprobe命令,并且将cmd执行命令的结果以json的形式写出到文件。
代码如下:

 cmd = 'ffprobe -v quiet'                ' -print_format json'                ' -show_format '                '-show_streams '                'D:/DATA/{}.mp4 >>'                ' D:/DATA/{}_json.txt'.format(file_name,file_name)  os.popen(cmd)  #subprocess.call(cmd) 

这里要注意一下,不能用subprocess.call来执行cmd命令,因为最后会写不出文件,用os.popen()则能正常写出,原因未知。写出文件的json格式如下(我全部贴出来了,大家只需要找自己用的到的参数即可,具体参数含义大家自行百度):

{     "streams": [         {             "index": 0,             "codec_name": "h264",             "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",             "profile": "High",             "codec_type": "video",             "codec_time_base": "1201/72000",             "codec_tag_string": "avc1",             "codec_tag": "0x31637661",             "width": 1920,             "height": 1080,             "coded_width": 1920,             "coded_height": 1088,             "closed_captions": 0,             "has_b_frames": 0,             "pix_fmt": "yuv420p",             "level": 41,             "color_range": "tv",             "color_space": "bt709",             "color_transfer": "bt709",             "color_primaries": "bt709",             "chroma_location": "left",             "refs": 1,             "is_avc": "true",             "nal_length_size": "4",             "r_frame_rate": "30000/1001",             "avg_frame_rate": "36000/1201",             "time_base": "1/19200",             "start_pts": 0,             "start_time": "0.000000",             "duration_ts": 192160,             "duration": "10.008333",             "bit_rate": "16753618",             "bits_per_raw_sample": "8",             "nb_frames": "300",             "disposition": {                 "default": 1,                 "dub": 0,                 "original": 0,                 "comment": 0,                 "lyrics": 0,                 "karaoke": 0,                 "forced": 0,                 "hearing_impaired": 0,                 "visual_impaired": 0,                 "clean_effects": 0,                 "attached_pic": 0,                 "timed_thumbnails": 0             },             "tags": {                 "language": "und",                 "handler_name": "VideoHandler"             }         },         {             "index": 1,             "codec_name": "aac",             "codec_long_name": "AAC (Advanced Audio Coding)",             "profile": "LC",             "codec_type": "audio",             "codec_time_base": "1/44100",             "codec_tag_string": "mp4a",             "codec_tag": "0x6134706d",             "sample_fmt": "fltp",             "sample_rate": "44100",             "channels": 1,             "channel_layout": "mono",             "bits_per_sample": 0,             "r_frame_rate": "0/0",             "avg_frame_rate": "0/0",             "time_base": "1/44100",             "start_pts": 0,             "start_time": "0.000000",             "duration_ts": 441344,             "duration": "10.007800",             "bit_rate": "62856",             "max_bit_rate": "63469",             "nb_frames": "431",             "disposition": {                 "default": 1,                 "dub": 0,                 "original": 0,                 "comment": 0,                 "lyrics": 0,                 "karaoke": 0,                 "forced": 0,                 "hearing_impaired": 0,                 "visual_impaired": 0,                 "clean_effects": 0,                 "attached_pic": 0,                 "timed_thumbnails": 0             },             "tags": {                 "language": "und",                 "handler_name": "SoundHandler"             }         }     ],     "format": {         "filename": "D:/DATA/A007.mp4",         "nb_streams": 2,         "nb_programs": 0,         "format_name": "mov,mp4,m4a,3gp,3g2,mj2",         "format_long_name": "QuickTime / MOV",         "start_time": "0.000000",         "duration": "10.009000",         "size": "21047968",         "bit_rate": "16823233",         "probe_score": 100,         "tags": {             "major_brand": "isom",             "minor_version": "512",             "compatible_brands": "isomiso2avc1mp41",             "encoder": "Lavf57.58.102"         }     } } {     "streams": [         {             "index": 0,             "codec_name": "h264",             "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",             "profile": "High",             "codec_type": "video",             "codec_time_base": "1201/72000",             "codec_tag_string": "avc1",             "codec_tag": "0x31637661",             "width": 1920,             "height": 1080,             "coded_width": 1920,             "coded_height": 1088,             "closed_captions": 0,             "has_b_frames": 0,             "pix_fmt": "yuv420p",             "level": 41,             "color_range": "tv",             "color_space": "bt709",             "color_transfer": "bt709",             "color_primaries": "bt709",             "chroma_location": "left",             "refs": 1,             "is_avc": "true",             "nal_length_size": "4",             "r_frame_rate": "30000/1001",             "avg_frame_rate": "36000/1201",             "time_base": "1/19200",             "start_pts": 0,             "start_time": "0.000000",             "duration_ts": 192160,             "duration": "10.008333",             "bit_rate": "16753618",             "bits_per_raw_sample": "8",             "nb_frames": "300",             "disposition": {                 "default": 1,                 "dub": 0,                 "original": 0,                 "comment": 0,                 "lyrics": 0,                 "karaoke": 0,                 "forced": 0,                 "hearing_impaired": 0,                 "visual_impaired": 0,                 "clean_effects": 0,                 "attached_pic": 0,                 "timed_thumbnails": 0             },             "tags": {                 "language": "und",                 "handler_name": "VideoHandler"             }         },         {             "index": 1,             "codec_name": "aac",             "codec_long_name": "AAC (Advanced Audio Coding)",             "profile": "LC",             "codec_type": "audio",             "codec_time_base": "1/44100",             "codec_tag_string": "mp4a",             "codec_tag": "0x6134706d",             "sample_fmt": "fltp",             "sample_rate": "44100",             "channels": 1,             "channel_layout": "mono",             "bits_per_sample": 0,             "r_frame_rate": "0/0",             "avg_frame_rate": "0/0",             "time_base": "1/44100",             "start_pts": 0,             "start_time": "0.000000",             "duration_ts": 441344,             "duration": "10.007800",             "bit_rate": "62856",             "max_bit_rate": "63469",             "nb_frames": "431",             "disposition": {                 "default": 1,                 "dub": 0,                 "original": 0,                 "comment": 0,                 "lyrics": 0,                 "karaoke": 0,                 "forced": 0,                 "hearing_impaired": 0,                 "visual_impaired": 0,                 "clean_effects": 0,                 "attached_pic": 0,                 "timed_thumbnails": 0             },             "tags": {                 "language": "und",                 "handler_name": "SoundHandler"             }         }     ],     "format": {         "filename": "D:/DATA/A007.mp4",         "nb_streams": 2,         "nb_programs": 0,         "format_name": "mov,mp4,m4a,3gp,3g2,mj2",         "format_long_name": "QuickTime / MOV",         "start_time": "0.000000",         "duration": "10.009000",         "size": "21047968",         "bit_rate": "16823233",         "probe_score": 100,         "tags": {             "major_brand": "isom",             "minor_version": "512",             "compatible_brands": "isomiso2avc1mp41",             "encoder": "Lavf57.58.102"         }     } } 

差点忘记说了,因为出发点是批量处理对嘛,可以用opencv读取视频序列,for循环一下然后将写出的json格式的文件再读入,查找自己需要的视频参数。

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » FFmpeg之ffprobe

提供最优质的资源集合

立即查看 了解详情