-def convert_flv_mp4(orig_filename):
- basename = os.path.splitext(orig_filename)[0]
- flv_filename = basename + ".flv"
- mp4_filename = basename + ".mp4"
- if orig_filename != flv_filename:
- os.rename(orig_filename, flv_filename)
- print "Converting %s to mp4" % flv_filename
- cmd = [
- "avconv",
- "-i", flv_filename,
- "-acodec", "copy",
- "-vcodec", "copy",
- mp4_filename,
- ]
+def check_command_exists(cmd):
+ try:
+ subprocess.check_output(cmd)
+ return True
+ except Exception:
+ return False
+
+def generate_remux_cmd(infile, outfile):
+ if check_command_exists(["avconv", "--help"]):
+ return [
+ "avconv",
+ "-i", infile,
+ "-bsf:a", "aac_adtstoasc",
+ "-acodec", "copy",
+ "-vcodec", "copy",
+ outfile,
+ ]
+
+ if check_command_exists(["ffmpeg", "--help"]):
+ return [
+ "ffmpeg",
+ "-i", infile,
+ "-bsf:a", "aac_adtstoasc",
+ "-acodec", "copy",
+ "-vcodec", "copy",
+ outfile,
+ ]
+
+ raise Exception("You must install ffmpeg or libav-tools")
+
+def remux(infile, outfile):
+ logging.info("Converting %s to mp4", infile)
+ cmd = generate_remux_cmd(infile, outfile)