def process_item(self): abspath = self.current_task.get_source_abspath() self._log("{} processing job - {}".format(self.name, abspath)) # Create output path if not exists common.ensure_dir(self.current_task.cache_path) # Convert file success = False try: ffmpeg_args = self.current_task.ffmpeg.generate_ffmpeg_args() if ffmpeg_args: success = self.current_task.ffmpeg.convert_file_and_fetch_progress( abspath, self.current_task.cache_path, ffmpeg_args) self.current_task.ffmpeg_log = self.current_task.ffmpeg.ffmpeg_cmd_stdout except ffmpeg.FFMPEGHandleConversionError as e: # Fetch ffmpeg stdout and append it to the current task object (to be saved during post process) self.current_task.ffmpeg_log = self.current_task.ffmpeg.ffmpeg_cmd_stdout self._log( "Error while executing the FFMPEG command {}. " "Download FFMPEG command dump from history for more information." .format(abspath), message2=str(e), level="error") if success: # If file conversion was successful, we will get here self._log("Successfully converted file '{}'".format(abspath)) return True self._log("Failed to convert file '{}'".format(abspath), level='warning') return False
def process_file_with_configured_settings(self, vid_file_path): # Parse input path src_file = os.path.basename(vid_file_path) src_path = os.path.abspath(vid_file_path) src_folder = os.path.dirname(src_path) # Get container extension container = unffmpeg.containers.grab_module(self.settings.OUT_CONTAINER) container_extension = container.container_extension() # Parse an output cache path out_folder = "file_conversion-{}".format(time.time()) out_file = "{}-{}.{}".format(os.path.splitext(src_file)[0], time.time(), container_extension) out_path = os.path.join(self.settings.CACHE_PATH, out_folder, out_file) # Create output path if not exists common.ensure_dir(out_path) # Reset all info self.set_info_defaults() # Fetch file info self.set_file_in(vid_file_path) # Convert file success = False ffmpeg_args = self.generate_ffmpeg_args() if ffmpeg_args: success = self.convert_file_and_fetch_progress(src_path, out_path, ffmpeg_args) if success: # Move file back to original folder and remove source success = self.post_process_file(out_path) if success: destPath = os.path.join(src_folder, out_file) self._log("Moving file {} --> {}".format(out_path, destPath)) shutil.move(out_path, destPath) try: self.post_process_file(destPath) except FFMPEGHandlePostProcessError: success = False if success: # If successful move, remove source # TODO: Add env variable option to keep src if src_path != destPath: self._log("Removing source: {}".format(src_path)) os.remove(src_path) else: self._log("Copy / Replace failed during post processing '{}'".format(out_path), level='warning') return False else: self._log("Encoded file failed post processing test '{}'".format(out_path), level='warning') return False else: self._log("Failed processing file '{}'".format(src_path), level='warning') return False # If file conversion was successful, we will get here self._log("Successfully processed file '{}'".format(src_path)) return True
def process_item(self): abspath = self.current_task.get_source_abspath() self._log("{} running job - {}".format(self.name, abspath)) # Create output path if not exists common.ensure_dir(self.current_task.cache_path) # Convert file success = False ffmpeg_args = self.current_task.ffmpeg.generate_ffmpeg_args() if ffmpeg_args: success = self.current_task.ffmpeg.convert_file_and_fetch_progress(abspath, self.current_task.cache_path, ffmpeg_args) if success: # If file conversion was successful, we will get here self._log("Successfully converted file '{}'".format(abspath)) return True self._log("Failed to convert file '{}'".format(abspath), level='warning') return False
def convert_single_file(self, infile, outfile, test_for_failure=False): if not os.path.exists(infile): self._log("No such file: {}".format(infile)) sys.exit(1) # Ensure the directory exists common.ensure_dir(outfile) # Remove the output file if it already exists if os.path.exists(outfile): os.remove(outfile) # Setup ffmpeg args built_args = self.build_ffmpeg_args(test_for_failure) # Run conversion process self._log("Converting {} -> {}".format(infile, outfile)) # Fetch file info self.ffmpeg.set_file_in(infile) assert self.ffmpeg.convert_file_and_fetch_progress(infile, outfile, built_args) if not test_for_failure: assert self.ffmpeg.post_process_file(outfile) elif test_for_failure: import pytest with pytest.raises(ffmpeg.FFMPEGHandlePostProcessError): self.ffmpeg.post_process_file(outfile)