ffmpeg 模块

一、ffmpeg-python 安装
pip3 install ffmpeg-python

也可以通过克隆源码返回式进行安装:

git clone git@github.com:kkroening/ffmpeg-python.git
export PYTHONPATH=${
   PYTHONPATH}:ffmpeg-python
python
>>> import ffmpeg
>>> help(ffmpeg) # 通过help()可以查看ffmpeg提供的相应的Python API

二、常用的ffmpegpython API
1、probe 获取视频文件的详细信息
语法格式:
probe(filePath[, cmd="ffprobe"]) 

用于获取视频文件的详细信息,filePath是文件路径的字符串表示。[...]中的内容可选,一般使用默认值。其返回值是一个字典,字典中有两个key-value对。

示例
import ffmpeg

info = ffmpeg.probe("/xxx/xxx/test.mp4")
"""
{
  "streams": [
    {
      "index": 0,
      "codec_name": "h264",
      "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
      "profile": "Main",
      "codec_type": "video",
      "codec_time_base": "1001/48000",
      "codec_tag_string": "avc1",
      "codec_tag": "0x31637661",
      "width": 1024,
      "height": 576,
      "coded_width": 1024,
      "coded_height": 576,
      "has_b_frames": 1,
      "sample_aspect_ratio": "1:1",
      "display_aspect_ratio": "16:9",
      "pix_fmt": "yuv420p",
      "level": 31,
      "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": "24000/1001",
      "avg_frame_rate": "24000/1001",
      "time_base": "1/48000",
      "start_pts": 0,
      "start_time": "0.000000",
      "duration_ts": 2883840,
      "duration": "60.080000",
      "bit_rate": "944746",
      "bits_per_raw_sample": "8",
      "nb_frames": "1515",
      "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": "Video Media Handler"
      }
    },
    {
      "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": 2,
      "channel_layout": "stereo",
      "bits_per_sample": 0,
      &
  • 10
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值