def create(self): self.write_text_files() if self.config.cache_video and os.path.exists(self.video_path): return self.get_images() self.fix_images() if self.config.use_audio and not os.path.exists(self.audio_path) or not self.config.cache_audio: util.from_text_to_speech(self.get_column("J"), self.audio_path) if self.config.use_audio: audio_length = util.get_audio_length(self.audio_path) else: audio_length = 45.0 args3 = ["ffmpeg", "-y", "-t", str(audio_length)] index = 0 # max_ = max(len(self.img_paths), audio_length / 5.0) max_ = len(self.img_paths) min_ = 0 for path in self.img_paths: if index >= min_ and index < max_: args3.extend(["-loop", "1", "-t", "2.5", "-i", path]) index += 1 if self.config.use_audio: args3.extend(["-i", self.audio_path]) args3.extend(["-filter_complex"]) filter = "" index = 0 outputs = "" for path in self.img_paths: if index >= min_ and index < max_ - 1: real_index = index - min_ i = str(real_index) i2 = str(real_index + 1) filter += ( "[" + i2 + ":v][" + i + ":v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b" + i2 + "v];\n" ) outputs += "[" + i + ":v][b" + i2 + "v]" index += 1 c = str((real_index + 1) * 2 + 1) i = str(real_index + 1) filter += outputs + "[" + i + ":" + "v]concat=n=" + c + ":v=1:a=0,format=yuvj422p," text = util.apply_text( self.get_column("A"), self.config.font_file_avenir_black, 36, color="black", movement_x="151", movement_y="51", ) text += "," + util.apply_text( self.get_column("A"), self.config.font_file_avenir_black, 36, color="white", movement_x="150", movement_y="50", ) filter += "" + text filter += "[v]" args3.append(filter) args3.extend(["-map", "[v]"]) if self.config.use_audio: args3.extend(["-map", str(max_) + ":0"]) args3.extend(["-t", str(audio_length), self.video_path]) if util.run_args(args3) != 0: self.logger.warn("Video creation failed!") if os.path.exists(self.video_path): os.remove(self.video_path)
def fix_images(self): self.logger.debug("Fixing images.") util.run_args( ["mogrify", "-sampling-factor", "2x2,1x1,1x1", "-resample", "300x300", "-resize", "1024x768!", "*.jpg"], cwd=self.img_dir, )