python-video-to-gif.py 634 B

123456789101112131415161718192021222324
  1. import imageio
  2. import os
  3. def convertVideoToGifFile(inputFile, outputFile=None):
  4. if not outputFile:
  5. outputFile = os.path.splitext(inputFile)[0] + ".gif"
  6. print("Converting {0} to {1}".format(inputFile, outputFile))
  7. reader = imageio.get_reader(inputFile)
  8. fps = reader.get_meta_data()['fps']
  9. writer = imageio.get_writer(outputFile, fps=fps)
  10. for i,im in enumerate(reader):
  11. writer.append_data(im)
  12. writer.close()
  13. print("\r\nConversion done.")
  14. #Convert Input Files
  15. convertVideoToGifFile("sample_960x540.avi")
  16. convertVideoToGifFile("SampleVideo_1280x720_1mb.mp4", "SampleVideo.gif")