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 进行视频推流进行直播搭建。
原文:https://www.cnblogs.com/xcsg/p/10841265.html