Skip to content

Instantly share code, notes, and snippets.

@ragekit
Created April 6, 2015 13:00
Show Gist options
  • Save ragekit/adf3433b9408878f503b to your computer and use it in GitHub Desktop.
Save ragekit/adf3433b9408878f503b to your computer and use it in GitHub Desktop.
convert video to webm + embed it in webpage using base64 and store it in dropbox
#!/usr/bin/env python
import sys
import os
import base64
from subprocess import call
from subprocess import Popen, PIPE
from os.path import expanduser
for f in sys.argv[1:]:
pathToDropBoxFolder = expanduser("~")+"/Dropbox/"
pathToScreenCastFolder = "screencasts/"
fileName, fileExtension = os.path.splitext(f)
if(fileExtension == ".mov" or fileExtension == ".mp4"):
call(["env","ffmpeg","-i",f,"-an","-qmin","10","-qmax","42","-b:v","400k","-quality","good","-cpu-used", "0",fileName+".webm"])
videoFile = open(fileName+".webm",'rb')
encoded_string = "data:video/webm;base64,"+base64.b64encode(videoFile.read())
videoFile.close()
file = open(pathToDropBoxFolder + pathToScreenCastFolder + fileName+".html",'w')
file.write("<html><body><video src='"+encoded_string+"' autoplay loop></video></body></html>")
file.close()
os.remove(fileName+".webm")
ret = Popen(["dropbox_uploader.sh","share",pathToScreenCastFolder + fileName + ".html"],stdin=PIPE, stdout=PIPE, stderr=PIPE)
ret = ret.communicate()[0]
end = ret.index("\n")
copy = Popen(['pbcopy'], stdin=PIPE)
copy.stdin.write("https://dl."+ret[27:end])
copy.stdin.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment