1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import os import uuid from ffmpy import FFmpeg
def cut_out_video(video_path: str, output_dir: str, start_pix: tuple, size: tuple): ext = os.path.basename(video_path).strip().split('.')[-1] if ext not in ['mp4', 'avi', 'flv']: raise Exception('format error') result = os.path.join(output_dir, '{}.{}'.format(uuid.uuid1().hex, ext)) ff = FFmpeg(inputs={video_path: None}, outputs={ result: '-vf crop={}:{}:{}:{} -y -threads 5 -preset ultrafast -strict -2'.format(size[0], size[1], start_pix[0], start_pix[1])}) print(ff.cmd) ff.run() return result
if __name__ == '__main__': print(cut_out_video(r'C:\Users\huyi\Desktop\test2.mp4', r'C:\Users\huyi\Desktop', (0, 0), (512, 512)))
|