FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。
它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。
FFmpeg在Linux平台下开发,但它同样也可以在其它操作系统环境中编译运行,包括Windows、Mac OS X等。
这个项目最早由Fabrice Bellard发起,2004年至2015年间由Michael Niedermayer主要负责维护。许多FFmpeg的开发人员都来自MPlayer项目,而且当前FFmpeg也是放在MPlayer项目组的服务器上。
项目的名称来自MPEG视频编码标准,前面的"FF"代表"Fast Forward"。
多媒体视频处理工具FFmpeg有非常强大的功能包括视频采集功能、视频格式转换、视频抓图、给视频加水印等。
# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者:cacho_37967865
#博客:https://blog.csdn.net/sinat_37967865
#文件:ffmpegModel.py
#日期:2019-06-12
#备注:通过ffmpeg库处理视频信息 pip install ffmpeg-python ,在这之前还需要安装windows版本FFmpeg
https://ffmpeg.zeranoe.com/builds/
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import ffmpeg
def getInfo(file):
info = ffmpeg.probe(file)
dict_to_json(info)
if __name__ == '__main__':
#getInfo('F:\image\\temp\\d.mp4')
{
"format":{
"bit_rate":"1634932",
"duration":"334.067000",
"filename":"F:\\image\\d-min.mp4",
"format_long_name":"QuickTime / MOV",
"format_name":"mov,mp4,m4a,3gp,3g2,mj2",
"nb_programs":0,
"nb_streams":2,
"probe_score":100,
"size":"68272120",
"start_time":"0.000000",
"tags":{
"compatible_brands":"isomiso2avc1mp41",
"encoder":"Lavf58.20.100",
"major_brand":"isom",
"minor_version":"512"
}
},
"streams":[
{
"avg_frame_rate":"30/1",
"bit_rate":"1497468",
"bits_per_raw_sample":"8",
"chroma_location":"left",
"codec_long_name":"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"codec_name":"h264",
"codec_tag":"0x31637661",
"codec_tag_string":"avc1",
"codec_time_base":"1/60",
"codec_type":"video",
"coded_height":1280,
"coded_width":720,
"disposition":{
"attached_pic":0,
"clean_effects":0,
"comment":0,
"default":1,
"dub":0,
"forced":0,
"hearing_impaired":0,
"karaoke":0,
"lyrics":0,
"original":0,
"timed_thumbnails":0,
"visual_impaired":0
},
"duration":"334.066667",
"duration_ts":5131264,
"has_b_frames":2,
"height":1280,
"index":0,
"is_avc":"true",
"level":31,
"nal_length_size":"4",
"nb_frames":"10022",
"pix_fmt":"yuv420p",
"profile":"High",
"r_frame_rate":"30/1",
"refs":1,
"start_pts":0,
"start_time":"0.000000",
"tags":{
"handler_name":"VideoHandler",
"language":"eng"
},
"time_base":"1/15360",
"width":720
},
{
"avg_frame_rate":"0/0",
"bit_rate":"128807",
"bits_per_sample":0,
"channel_layout":"stereo",
"channels":2,
"codec_long_name":"AAC (Advanced Audio Coding)",
"codec_name":"aac",
"codec_tag":"0x6134706d",
"codec_tag_string":"mp4a",
"codec_time_base":"1/44100",
"codec_type":"audio",
"disposition":{
"attached_pic":0,
"clean_effects":0,
"comment":0,
"default":1,
"dub":0,
"forced":0,
"hearing_impaired":0,
"karaoke":0,
"lyrics":0,
"original":0,
"timed_thumbnails":0,
"visual_impaired":0
},
"duration":"334.029002",
"duration_ts":14730679,
"index":1,
"max_bit_rate":"128807",
"nb_frames":"14385",
"profile":"LC",
"r_frame_rate":"0/0",
"sample_fmt":"fltp",
"sample_rate":"44100",
"start_pts":0,
"start_time":"0.000000",
"tags":{
"handler_name":"SoundHandler",
"language":"eng"
},
"time_base":"1/44100"
}
]
}
ffmpeg.probe(mp3)结果中的streams参数介绍
"codec_type":"audio", -- 类型:audio-音频,video-视频
"codec_long_name":"MP3 (MPEG audio layer 3)"
"codec_name":"mp3",
"channel_layout":"stereo", -- 音频声道类型:stereo-双声道(立体声);mono-单声道
"channels":2, -- 音频声道数量
"sample_rate":"48000", -- 音频采样率 Hz
"bit_rate":"128000", -- 音频数据流量
ffmpeg.probe(mp4)结果中的streams参数介绍
"codec_type":"video",
"codec_long_name":"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"codec_name":"h264",
"coded_height":1280,
"coded_width":720,
"avg_frame_rate":"30/1", -- 平均帧率
"bit_rate":"1854254", -- 平均码率(比特率)