def next_frame(self): """ Call and save the next frame. """ success = False while not success: success, image = self.cap.read() if success: cv2.imwrite( self.extracted_frames_dir + "frame_temp_%s.jpg" % self.count, image, [cv2.IMWRITE_JPEG_QUALITY, 100]) cv2.imwrite( self.compressed_frames_dir + "compressed_temp_%s.jpg" % self.count, image, [cv2.IMWRITE_JPEG_QUALITY, self.compressed_quality]) rename_file_wait( self.extracted_frames_dir + "frame_temp_%s.jpg" % self.count, self.extracted_frames_dir + "frame%s.jpg" % self.count) rename_file_wait( self.compressed_frames_dir + "compressed_temp_%s.jpg" % self.count, self.compressed_frames_dir + "compressed_%s.jpg" % self.count) self.count += 1
def upscale_file(self, input_image: str, output_image: str) -> None: exec_command = copy.copy(self.upscale_command) console_output = open( self.context.console_output_dir + "vulkan_upscale_frames.txt", "w") """ note: so waifu2x-ncnn-vulkan actually doesn't allow jpg outputs. We have to work around this by simply renaming it as png here, then changing it to jpg (for consistency elsewhere) """ output_image = output_image.replace(".jpg", ".png") # replace the exec command with the files we're concerned with for x in range(len(exec_command)): if exec_command[x] == "[input_file]": exec_command[x] = input_image if exec_command[x] == "[output_file]": exec_command[x] = output_image console_output.write(str(exec_command)) self.active_waifu2x_subprocess = subprocess.Popen( exec_command, shell=False, stderr=console_output, stdout=console_output, cwd=os.path.dirname(self.waifu2x_vulkan_path)) self.active_waifu2x_subprocess.wait() rename_file_wait(output_image, output_image.replace(".png", ".jpg"))
def _noise_image_sub_thread(self, frame_number: int): extracted_image = self.extracted_frames_dir + "frame%s.png" % frame_number noise_extracted_image_temp = self.noised_frames_dir + "temp%s.png" % frame_number noise_extracted_image = self.noised_frames_dir + "frame%s.png" % frame_number apply_noise_to_image(ffmpeg_dir=self.ffmpeg_path, input_image=extracted_image, output_file=noise_extracted_image_temp) rename_file_wait(noise_extracted_image_temp, noise_extracted_image)
def next_frame(self): """ Call and save the next frame. """ success = False image = self.cap.get_frame() temp_image = self.extracted_frames_dir + "frame_temp_%s.png" % self.count final_image = self.extracted_frames_dir + "frame%s.png" % self.count image.save(Path(temp_image)) rename_file_wait(temp_image, final_image) self.count += 1
def next_frame(self): """ Call and save the next frame. """ success = False while not success: success, image = self.cap.read() if success: temp_image = self.extracted_frames_dir + "frame_temp_%s.png" % self.count final_image = self.extracted_frames_dir + "frame%s.png" % self.count cv2.imwrite(temp_image, image) rename_file_wait(temp_image, final_image) self.count += 1
def upscale_file(self, input_image: str, output_image: str) -> None: exec_command = copy.copy(self.upscale_command) console_output_path = self.context.console_output_dir + "vulkan_upscale_frames.txt" with open(console_output_path, "w") as console_output: """ note: so waifu2x-ncnn-vulkan actually doesn't allow jpg outputs. We have to work around this by simply renaming it as png here, then changing it to jpg (for consistency elsewhere) """ output_image = output_image.replace(".jpg", ".png") # replace the exec command with the files we're concerned with for x in range(len(exec_command)): if exec_command[x] == "[input_file]": exec_command[x] = input_image if exec_command[x] == "[output_file]": exec_command[x] = output_image console_output.write(str(exec_command)) self.active_waifu2x_subprocess = subprocess.Popen( exec_command, shell=False, stderr=console_output, stdout=console_output, cwd=os.path.dirname(self.waifu2x_vulkan_path)) self.active_waifu2x_subprocess.wait() if not os.path.exists(output_image): self.log.info( "Could not upscale first frame: printing %s console log" % __name__) with open(console_output_path) as f: for line in f: self.log.critical("%s", str(line)) raise Exception("Could not upscale file %s" % input_image) rename_file_wait(output_image, output_image.replace(".png", ".jpg"))