def stack(file1, file2, direction, out_file = None): util.logger.debug("stack(%s, %s, %s, _)", file1, file2, direction) if not util.is_image_file(file1): raise media.FileTypeError('File %s is not an image file' % file1) if not util.is_image_file(file2): raise media.FileTypeError('File %s is not an image file' % file2) out_file = util.automatic_output_file_name(out_file, file1, "stacked") w1, h1 = ImageFile(file1).get_dimensions() w2, h2 = ImageFile(file2).get_dimensions() tmpfile1 = file1 tmpfile2 = file2 util.logger.debug("Images dimensions: %d x %d and %d x %d", w1, h1, w2, h2) if direction == 'horizontal': filter_name = 'hstack' if h1 > h2: new_w2 = w2 * h1 // h2 tmpfile2 = rescale(file2, new_w2, h1) elif h2 > h1: new_w1 = w1 * h2 // h1 tmpfile1 = rescale(file1, new_w1, h2) else: filter_name = 'vstack' if w1 > w2: new_h2 = h2 * w1 // w2 tmpfile2 = rescale(file2, w1, new_h2) elif w2 > w1: new_h1 = h1 * w2 // w1 tmpfile1 = rescale(file1, w2, new_h1) # ffmpeg -i a.jpg -i b.jpg -filter_complex hstack output util.run_ffmpeg('-i "%s" -i "%s" -filter_complex %s "%s"' % (tmpfile1, tmpfile2, filter_name, out_file)) if tmpfile1 is not file1: util.delete_files(tmpfile1) if tmpfile2 is not file2: util.delete_files(tmpfile2) return out_file
def encode_file(args, options): '''Encodes a single file''' if util.is_audio_file(args.inputfile): file_object = audio.AudioFile(args.inputfile) elif util.is_image_file(args.inputfile): file_object = img.ImageFile(args.inputfile) else: file_object = video.VideoFile(args.inputfile) if args.width is not None: specs = file_object.get_properties() w = int(specs[opt.media.WIDTH]) h = int(specs[opt.media.HEIGHT]) new_w = int(args.width) new_h = (int(h * new_w / w) // 8) * 8 options[opt.media.SIZE] = "%dx%d" % (new_w, new_h) if args.timeranges is None: file_object.encode(args.outputfile, args.profile, **options) return if args.outputfile is None: ext = util.get_profile_extension(args.profile) count = 0 filelist = [] timeranges = re.split(',', args.timeranges) for video_range in timeranges: options[opt.media.START], options[opt.media.STOP] = re.split( '-', video_range) count += 1 target_file = util.automatic_output_file_name(args.outputfile, args.inputfile, str(count), ext) filelist.append(target_file) outputfile = file_object.encode(target_file, args.profile, **options) util.logger.info("File %s generated", outputfile) if len(timeranges) > 1: # If more than 1 file generated, concatenate all generated files target_file = util.automatic_output_file_name(args.outputfile, args.inputfile, "combined", ext) video.concat(target_file, filelist)
if util.is_audio_file(file): util.logger.info('Encoding album art %s in file %s', image_file, file) audio.encode_album_art(file, image_file, **{'scale': DEFAULT_RESCALING}) def dir_album_art(directory): filelist = util.filelist(directory) dir_album_art_file = find_image(filelist) if dir_album_art_file is None: util.logger.error("No image file in directory %s", directory) else: filelist_album_art(filelist, dir_album_art_file) util.logger.setLevel(util.get_logging_level(5)) file_list = [] album_art_file = None for file_arg in sys.argv: if os.path.isdir(file_arg): dir_album_art(file_arg) elif util.is_image_file(file_arg): album_art_file = file_arg else: file_list.append(file_arg) if album_art_file is None: util.logger.error("No image file found in %s", str(sys.argv)) else: filelist_album_art(file_list, album_art_file)
def find_image(filelist): for file in filelist: if util.is_image_file(file): return file return None
props = all_props nb_files = len(filelist) for file in filelist: try: if not util.is_media_file(file): raise media.FileTypeError( "File %s is not a supported file format" % file) if util.is_video_file(file): file_object = video.VideoFile(file) if nb_files == 1: props = VIDEO_PROPS elif util.is_audio_file(file): file_object = audio.AudioFile(file) if nb_files == 1: props = AUDIO_PROPS elif util.is_image_file(file): file_object = img.ImageFile(file) if nb_files == 1: props = IMAGE_PROPS specs = file_object.get_properties() util.logger.debug("Specs = %s", util.json_fmt(specs)) for prop in props: if args.format != "csv": try: if prop in UNITS: divider = UNITS[prop][0] unit = UNITS[prop][1] if unit == 'hms': print("%-20s : %s" % (prop, util.to_hms_str(specs[prop])))