FFMPEG 来处理多种媒体文件, 对帧进行操作的时候非常的复杂, 下面介绍下使用 FFMPEG 对视频文件的操作.
1, 安装
Windows 安装 FFMPEG:
下载 FFMPEG 文件解压文件到 c 盘
配置环境变量 C:\FFMPEG\bin
修改 python 文件 subprocess.py
shell=False 改为 true
pip install FFMPEG-python
CentOS 安装 FFMPEG
- sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
- sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
- sudo yum install FFMPEG FFMPEG-devel -y
- pip3 install FFMPEG-python
2, 应用
- # 读取视频信息
- info = FFMPEG.probe("./test.mp4")
- #截图操作
- times = [1,10]
- for time in times:
- input_file = './test.mp4'
- output_file = './image-' + str(time) + '.jpg'
- out, err = (
- FFMPEG
- .input(input_file, ss=time)
- .output(output_file, vframes='1', f='image2')
- .run(quiet=False, overwrite_output=True)
- )
- if out == b'':
- print('do nothing')
- # 视频转换
- os.system('ffmpeg -i a.mp4 -ss 5 -t 10 b.avi')
- # 视频截取转换 gif
- os.system('ffmpeg -ss 00:00:10 -t 3 -i test.mp4 test.gif')
由于时间问题, 今天就介绍到这里
后续有时间随便 FFmepg 进行视频推流进行直播搭建.
来源: http://www.bubuko.com/infodetail-3053110.html