]> code.delx.au - webdl/commitdiff
webdl: support for ffmpeg as well as avconv
authorJames Bunton <jamesbunton@delx.net.au>
Sat, 8 Nov 2014 12:32:38 +0000 (23:32 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Sat, 8 Nov 2014 12:32:38 +0000 (23:32 +1100)
common.py

index 2f2cf5f48d2a76053e63730dac0bb058566c7bdd..def60fe03957f13f050db73923d48e6782d592fb 100644 (file)
--- a/common.py
+++ b/common.py
@@ -166,15 +166,39 @@ def exec_subprocess(cmd):
     return False
 
 
-def avconv_remux(infile, outfile):
+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):
     print "Converting %s to mp4" % infile
-    cmd = [
-        "avconv",
-        "-i", infile,
-        "-acodec", "copy",
-        "-vcodec", "copy",
-        outfile,
-    ]
+    cmd = generate_remux_cmd(infile, outfile)
     if not exec_subprocess(cmd):
         # failed, error has already been logged
         return False
@@ -203,7 +227,7 @@ def convert_to_mp4(filename):
 
     if ext in (".flv", ".ts"):
         filename_mp4 = basename + ".mp4"
-        return avconv_remux(filename, filename_mp4)
+        return remux(filename, filename_mp4)
 
     return ext == ".mp4"