- def __init__(self):
- self.source = None
- self.dest = None
- self.crop_start = None
- self.crop_end = None
- self.color_matrix = None
- self.audio_normalize = True
-
- def set_source(self, arg):
- self.source = os.path.join(SOURCE_DIR, arg)
-
- def set_dest(self, arg):
- self.dest = os.path.join(DEST_DIR, arg)
- if not self.dest.endswith(".avi"):
- self.dest += ".avi"
-
- def set_crop(self, arg):
- a, b = arg.split("-")
- self.crop_start = int(a)
- self.crop_end = int(b)
-
- def set_colormatrix(self, arg):
- [float(x) for x in arg.split(" ") if x] # check it's valid
- self.color_matrix = arg
-
- def set_whitecolor(self, arg):
- arg = arg.split(" ")
- color = arg[0]
- r = 0xff / int(color[0:2], 16)
- g = 0xff / int(color[2:4], 16)
- b = 0xff / int(color[4:6], 16)
- # don't change the brightness
- avg = (r + g + b) / 3
- if (avg - 1) > 0.02:
- diff = avg - 1.0
- r -= diff
- g -= diff
- b -= diff
- if len(arg) == 2:
- brightness = float(arg[1])
- r *= brightness
- g *= brightness
- b *= brightness
- self.set_colormatrix("%.3f 0 0 0 %.3f 0 0 0 %.3f" % (r, g, b))
-
- def set_audionormalize(self, arg):
- self.audio_normalize = int(arg)
-
- def validate(self, line_count, unique):
- if self.dest in unique:
- fail(line_count, "Non-unique output file: " + self.dest)
- if self.source is None:
- fail(line_count, "Missing source")
- if self.dest is None:
- fail(line_count, "Missing dest")
- if not os.path.isfile(self.source):
- fail(line_count, "Unable to find source: " + self.source)
-
- def is_done(self):
- return os.path.isfile(self.dest)
-
- def run(self):
- image_cache_dir = explode_video_to_png(self.source)
- image_dir = apply_image_effects(image_cache_dir, self.crop_start, self.crop_end, self.color_matrix)
-
- audio_cache_file = explode_video_to_wav(self.source)
- audio_file = os.path.join(TMP_DIR, "audio_processed.wav")
- apply_audio_effects(audio_cache_file, audio_file, self.crop_start, self.crop_end, self.audio_normalize)
-
- combine_audio_video(audio_file, image_dir, self.dest+".tmp")
- os.rename(self.dest+".tmp", self.dest)
-
- def __str__(self):
- return "Job :: %s (%s)" % (self.dest, self.source)
+ def __init__(self):
+ self.source = None
+ self.dest = None
+ self.crop_start = None
+ self.crop_end = None
+ self.color_matrix = None
+ self.audio_normalize = True
+
+ def set_source(self, arg):
+ self.source = os.path.join(SOURCE_DIR, arg)
+
+ def set_dest(self, arg):
+ self.dest = os.path.join(DEST_DIR, arg)
+ if not self.dest.endswith(".avi"):
+ self.dest += ".avi"
+
+ def set_crop(self, arg):
+ a, b = arg.split("-")
+ self.crop_start = int(a)
+ self.crop_end = int(b)
+
+ def set_colormatrix(self, arg):
+ [float(x) for x in arg.split(" ") if x] # check it's valid
+ self.color_matrix = arg
+
+ def set_whitecolor(self, arg):
+ arg = arg.split(" ")
+ color = arg[0]
+ r = 0xff / int(color[0:2], 16)
+ g = 0xff / int(color[2:4], 16)
+ b = 0xff / int(color[4:6], 16)
+ # don't change the brightness
+ avg = (r + g + b) / 3
+ if (avg - 1) > 0.02:
+ diff = avg - 1.0
+ r -= diff
+ g -= diff
+ b -= diff
+ if len(arg) == 2:
+ brightness = float(arg[1])
+ r *= brightness
+ g *= brightness
+ b *= brightness
+ self.set_colormatrix("%.3f 0 0 0 %.3f 0 0 0 %.3f" % (r, g, b))
+
+ def set_audionormalize(self, arg):
+ self.audio_normalize = int(arg)
+
+ def validate(self, line_count, unique):
+ if self.dest in unique:
+ fail(line_count, "Non-unique output file: " + self.dest)
+ if self.source is None:
+ fail(line_count, "Missing source")
+ if self.dest is None:
+ fail(line_count, "Missing dest")
+ if not os.path.isfile(self.source):
+ fail(line_count, "Unable to find source: " + self.source)
+
+ def is_done(self):
+ return os.path.isfile(self.dest)
+
+ def run(self):
+ image_cache_dir = explode_video_to_png(self.source)
+ image_dir = apply_image_effects(image_cache_dir, self.crop_start, self.crop_end, self.color_matrix)
+
+ audio_cache_file = explode_video_to_wav(self.source)
+ audio_file = os.path.join(TMP_DIR, "audio_processed.wav")
+ apply_audio_effects(audio_cache_file, audio_file, self.crop_start, self.crop_end, self.audio_normalize)
+
+ combine_audio_video(audio_file, image_dir, self.dest+".tmp")
+ os.rename(self.dest+".tmp", self.dest)
+
+ def __str__(self):
+ return "Job :: %s (%s)" % (self.dest, self.source)