Skip to content

Instantly share code, notes, and snippets.

@Centzilius
Last active August 29, 2015 14:20
Show Gist options
  • Save Centzilius/af6630812f9be14d1377 to your computer and use it in GitHub Desktop.
Save Centzilius/af6630812f9be14d1377 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from subprocess import call
from os import listdir
class File:
def __init__(self, path, start, end):
self.path = path
self.start = start
self.end = end
class Encoder:
def __init__(self, fileobj, bitrate, maxrate, bufsize, threads, keyframe):
self.fileobj = fileobj
self.bitrate = bitrate
self.maxrate = maxrate
self.bufsize = bufsize
self.threads = threads
self.keyframe = keyframe
def encode(self):
call(["ffmpeg", "-i", self.fileobj.path, "-ss", str(self.fileobj.start), "-to", str(self.fileobj.end), "-pass", "1", "-b:v", self.bitrate, "-maxrate", self.maxrate, "-bufsize", self.bufsize, "-threads", str(self.threads),
"-speed", "4", "-g", str(self.keyframe), "-tile-columns", "6", "-frame-parallel", "1", "-auto-alt-ref", "1", "-lag-in-frames", "25", "-an", "-sn", "-c:v", "libvpx-vp9", "-f", "webm", "-y", "/dev/null"])
call(["ffmpeg", "-i", self.fileobj.path, "-ss", str(self.fileobj.start), "-to", str(self.fileobj.end), "-pass", "2", "-b:v", self.bitrate, "-maxrate", self.maxrate, "-bufsize", self.bufsize, "-threads", str(self.threads),
"-speed", "1", "-g", str(self.keyframe), "-tile-columns", "6", "-frame-parallel", "1", "-auto-alt-ref", "1", "-lag-in-frames", "25", "-sn", "-c:v", "libvpx-vp9", "-c:a", "libvorbis", "-b:a", "128k", "-f", "webm",
self.fileobj.path + "-Opening.webm"])
print("Openings Encoder v0.1")
potential_files = []
for file in listdir("."):
if ".mkv" in file:
potential_files.append(file)
if len(potential_files) > 0:
print("We've found the following potential files:")
for file in potential_files:
print(file)
else:
print("There is no file to encode")
exit()
print("---")
for file in potential_files:
print("File: " + file)
thisfile = input("Do you want to encode this file? [Y|n]: ")
if thisfile == "n":
continue
bitrate = input("Which bitrate shall be used? [3000k]: ")
if not bitrate:
bitrate = "3000k"
maxrate = input("What shall be the maxrate? [3500k]: ")
if not maxrate:
maxrate = "3500k"
bufsize = input("What shall be the buffsize? [6000k]: ")
if not bufsize:
bufsize = "6000k"
threads = input("How many threads shall be used? [4]: ")
if not threads:
threads = 4
keyframe = input("What keyframe setting should be used?? [250]: ")
if not keyframe:
keyframe = 250
starttime = ""
while starttime == "":
starttime = input("When does the opening begin?: ")
endtime = ""
while endtime == "":
endtime = input("When does the opening ends?: ")
fileobject = File(file, starttime, endtime)
print("Press Return to start the encoding")
encoder = Encoder(fileobject, bitrate, maxrate, bufsize, threads, keyframe)
encoder.encode()
print("Everything done :3")
print("Have a nyan day :3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment