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版本FFmpeghttps://ffmpeg.zeranoe.com/builds/
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''import ffmpegdef 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",? ? ? ? ? ? ? ?-- 平均碼率(比特率)
總結
以上是生活随笔為你收集整理的【Python】ffmpeg模块查询视频、音频信息的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。