Library
json_encode
Encode JSON and return
def json_encode(j):
return json.JSONEncoder().encode(j)
json_decode
Decode JSON
def json_decode(j):
return json.JSONDecoder().decode(j)
ffmpeg
def ffmpeg(i, o):
system(f'ffmpeg -i {i} {o}')
ffmpeg_replace_input_extension
def ffmpeg_replace_input_extension(i, ext):
iext = i.split('.')[len(i.split('.'))-1]
output = i.replace(iext, ext)
system(f'ffmpeg -i {i} {output}')
ffmpeg_listen_on_dir
ffmpeg function that listens on an input directory. it will encode everything in the sdi directory to the specified format to the sdo directory, and delete any file in sdi that are completed. It will stop when the sdi (input) directory is empty. ffmpeg must be installed to use this function ffmpeg.org
def ffmpeg_listen_on_dir(sdi, sdo, f):
v = popen("ffmpeg -version").read()
if len(v) == 0:
print("Error: ffmpeg_listen_on_dir, ffmpeg not installed.")
raise SystemExit
while len(listdir(sdi)) > 0:
d = listdir(sdi)
for i in range(len(d)):
iext = d[i].split('.')[len(d[i].split('.'))-1]
output = d[i].replace(iext, ext)
system(f'ffmpeg -i {d[i]} {sdo}{output}')
remove(f'{sdi}{d[i]}')