QingfengLee
3/28/2016 - 5:49 PM

use python convert video to gif image

use python convert video to gif image

import cv2
from PIL import Image
import numpy as np
import sys,os

filename = sys.argv[1]
 
#open the video
videoCapture = cv2.VideoCapture(filename)

#get video fps
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)
 
#read frame
success, frame = videoCapture.read()

frames = []
while success :
	data = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
	frames.append(Image.fromarray(data))
	success, frame = videoCapture.read()

#save as gif
from images2gif import writeGif
writeGif('result.gif', frames, duration=1/fps, dither=0)