Context: I upload GIFs to my blog from the screencasts I create on my iPad. a-shell provides ffmpeg, but, it runs out of memory often.
Solution: Send video to server and run a Python script to convert to GIF and get the content back
I use two scripts:
First called convert-video-gif.py that uses moviepy (FFMPEG under the hood) to convert an MP4 to a GIF
from moviepy.editor import *
import sys
= sys.argv[1]
vid = vid.split(".")[0]
vid_name = (VideoFileClip(vid).speedx(10).resize(0.3))
clip + ".gif") clip.write_gif(vid_name
Second called convert_video.py that accepts: - a video file as a command line argument - transfers the video files to the server using SFTP - transfers the convert-video-gif.py file to the server using SFTP - runs the python file convert-video-gif.py on the server and create the GIF - retreive the GIF back to my local machine
import sys
import paramiko
# The file you wish to convert to GIF
= sys.argv[1]
f = f.split(".")[0]
f_name_without_ext = f_name_without_ext + ".gif"
f_name_gif
=paramiko.SSHClient()
ssh_client
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())connect(hostname='MY-HOSTNAME', username='MY-USERNAME', password='MY-PASSWORD')
ssh_client.=ssh_client.open_sftp()
ftp_client
# Transferring convert-video-gif.py to server
'convert-video-gif.py', 'convert-video-gif.py')
ftp_client.put(
# Transferring video to server
ftp_client.put(f, f)
# Running Python script
= ssh_client.exec_command(f"python convert-video-gif.py {f}")
stdin, stdout, stderr = stderr.readlines()
e
# Retreiving the video back from server
ftp_client.get(f_name_gif, f_name_gif)
In another previous post, I had also mentioned about the amazing SSH/SFTP apps: Termius and ShellFish. I am again pasting the GIF showing a similar to above workflow initiated via ShellFish.