scripts/bin/ffmpeg.py

45 lines
954 B
Python
Executable file

#!/usr/bin/env python3
###
# Upload a video and pipe it through ffmpeg
###
import cgitb, cgi, os, subprocess
cgitb.enable()
form = cgi.FieldStorage()
videoData = form.getvalue('filename')
video = "/home/zoey/.config/caddy/www/main/misc/video.mp4"
tmp = '/tmp/video.mp4'
if videoData != None:
try:
os.remove(video)
except OSError:
pass
try:
os.remove(tmp)
except OSError:
pass
open(tmp, 'wb').write(videoData)
subprocess.Popen(['ffmpeg', '-i', tmp, video])
print("""\
Content-Type: text/html\n
<html>
<body>
<p><a href="/misc/video.mp4">Download Video</a></p>
</body>
</html>
""")
else:
print("""\
Content-Type: text/html\n
<html>
<body>
<form enctype = "multipart/form-data" action = "/ffmpeg" method = "post">
<p>File: <input type = "file" name = "filename" /></p>
<p><input type = "submit" value = "Upload" /></p>
</form>
</body>
</html>""")