api&github
官方api
官方github
参数说明
实例代码
import ffmpeg
from pathlib import Path
class VideoEd:
image_extend = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
def extract_video(self, input_file, output_dir, output_ext='png', fps=0):
'''
视频每帧截图
:param input_file: 视频文件
:param output_dir: 输出目录
:param output_ext: 截取的图片后缀名称 :'png' or 'jpg'
:param fps: 每帧的fps
:return: True
'''
input_file_path = Path(input_file)
output_path = Path(output_dir)
if not input_file_path.exists():
raise Exception('input file not find')
if not output_path.exists():
output_path.mkdir(exist_ok=True)
job = ffmpeg.input(str(input_file_path))
kwargs = {
'pix_fmt': 'rgb24'}
if fps != 0:
kwargs.update({
'r': str(fps)})
if output_ext == 'jpg':
kwargs.update({
'q:v': '2'})
job = job.output(str(output_path / ('%5d.' + output_ext)), **kwargs)
try:
job