Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
from moviepy.editor import * clip = (VideoFileClip("video.mp4") .subclip((1,22.65),(1,23.2)) .resize(0.3)) clip.write_gif("annimation.gif")
def crop_and_anim(self): video = imageio.get_reader(os.path.join(self.pathTo, self.videoFile), 'ffmpeg') all_signs = self.parse_xml() for sign in all_signs: cropped_signs = [] for frame in sign: image = video.get_data(int(frame[0])) image_frame = Image.fromarray(image) tags = [float(tag) for tag in frame[1:5]] cropped = image_frame.crop(tags) cropped = cropped.convert("RGB") cropped_signs.append(cropped) path_to_animated = os.path.join(self.pathTo, self.dir2, 'animated__%d.gif' % int(all_signs.index(sign))) imageio.mimsave(path_to_animated, cropped_signs)
import imageio reader = imageio.get_reader('2.mp4') for frame_number, im in enumerate(reader): # im is numpy array if frame_number % 1 == 0: imageio.imwrite(f'frame_{frame_number}.jpg', im)