def comma_type(inp: str, min_args=1, max_args=None, name='') -> list: from usefulFunctions import cleanList inp = cleanList(inp.split(','), '\r\n\t') if(min_args > len(inp)): error(f'Too few comma arguments for {name}.') if(max_args is not None and len(inp) > max_args): error(f'Too many comma arguments for {name}.') return inp
def getAudioTracks(self, file): output = self.pipe([ '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'compact=p=0:nk=1', file ]).strip() numbers = cleanList(output.split('\n'), '\r\t') self.log(f'Track data: {numbers}') if (numbers[0].isnumeric()): return len(numbers) else: self.mylog.warning('ffprobe had an invalid output.') return 1 # Assume there's one audio track.
def getSubtitleTracks(self, file): output = self.pipe([ '-select_streams', 's', '-show_entries', 'stream=index', '-of', 'compact=p=0:nk=1', file ]).strip() numbers = cleanList(output.split('\n'), '\r\t') self.log(f'Track data: {numbers}') if (numbers[0].isnumeric()): return len(numbers) else: self.mylog.warning( 'Invalid output when detecting number of subtitle tracks.') return 0
def getInfo(files, ffmpeg, ffprobe, log): if (len(files) == 0): print('info: subcommand for inspecting media contents.') print('Add a file to inspect. Example:') print(' auto-editor info example.mp4') sys.exit() for file in files: if (os.path.exists(file)): print(f'file: {file}') else: log.error(f'Could not find file: {file}') hasVid = len( ffprobe.pipe(['-show_streams', '-select_streams', 'v', file])) > 5 hasAud = len( ffprobe.pipe(['-show_streams', '-select_streams', 'a', file])) > 5 if (hasVid): print(f' - fps: {ffprobe.getFrameRate(file)}') fps_mode = ffmpeg.pipe([ '-i', file, '-hide_banner', '-vf', 'vfrdet', '-an', '-f', 'null', '-' ]) fps_mode = cleanList(fps_mode.split('\n'), '\r\t') fps_mode = fps_mode.pop() if ('VFR:' in fps_mode): fps_mode = (fps_mode[fps_mode.index('VFR:'):]).strip() print(f' - mode: {fps_mode}') dur = ffprobe.getDuration(file) if (dur == 'N/A'): dur = ffprobe.pipe([ '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', file ]).strip() dur = removeZeroes(float(dur)) print(f' - duration: {dur} (container)') else: dur = removeZeroes(float(dur)) print(f' - duration: {dur}') res = ffprobe.getResolution(file) width, height = res.split('x') print(f' - resolution: {res} ({aspectRatio(width, height)})') print(f' - video codec: {ffprobe.getVideoCodec(file)}') vbit = ffprobe.getPrettyBitrate(file, 'v', track=0) print(f' - video bitrate: {vbit}') if (hasAud): tracks = ffprobe.getAudioTracks(file) print(f' - audio tracks: {tracks}') for track in range(tracks): print(f' - Track #{track}') print( f' - codec: {ffprobe.getAudioCodec(file, track)}') print( f' - samplerate: {ffprobe.getPrettySampleRate(file, track)}' ) abit = ffprobe.getPrettyBitrate(file, 'a', track) print(f' - bitrate: {abit}') else: print(' - audio tracks: 0') elif (hasAud): print(f' - duration: {ffprobe.getAudioDuration(file)}') print(f' - codec: {ffprobe.getAudioCodec(file, track=0)}') print( f' - samplerate: {ffprobe.getPrettySampleRate(file, track=0)}') abit = ffprobe.getPrettyBitrate(file, 'a', track=0) print(f' - bitrate: {abit}') else: print('Invalid media.') print('')
def comma_type(inp: str) -> list: from usefulFunctions import cleanList ms = inp.split(',') ms = cleanList(ms, '\r\n\t') return ms
def getFrameRate(self, file) -> float: nums = cleanList(self.getTimeBase(file).split('/'), '\r\t\n') try: return int(nums[0]) / int(nums[1]) except (ZeroDivisionError, IndexError, ValueError): self.mylog.error(f'getFrameRate had an invalid output: {output}')
def applyZooms(cmdZooms, audioData, sampleRate, mclip, mcut, fps, log): zooms = [] from usefulFunctions import cleanList for item in cmdZooms: ms = item.split(',') ms = cleanList(ms, '\r\n\t') if (len(ms) < 3): # Add more description later! log.error('Too few comma arguments for zoom option.' \ " Make sure you're wrapping the values in quotes.") start, end = ms[:2] start_zoom = float(ms[2]) if (len(ms) == 3): end_zoom = start_zoom else: end_zoom = float(ms[3]) x = 'centerX' y = 'centerY' inter = 'linear' hold = None if (len(ms) > 4): x, y = ms[4:6] if (len(ms) > 6): inter = ms[6] if (len(ms) > 7): hold = int(ms[7]) if (len(ms) > 8): log.error('Too many comma arguments for zoom option.') start_list, end_list = None, None if (start.startswith('audio')): start_list = handleBoolExp(start, audioData, sampleRate, fps, log) if (end.startswith('audio')): if (start_list is None): log.error( 'The start parameter must also have a boolean expression.') end_list = handleBoolExp(end, audioData, sampleRate, fps, log) if (start_list is None): zooms.append( ['zoom', start, end, start_zoom, end_zoom, x, y, inter, hold]) elif (end_list is None): # Handle if end is not a boolean expression. indexs = np.where(start_list)[0] if (indexs != []): zooms.append([ 'zoom', str(indexs[0]), end, start_zoom, end_zoom, x, y, inter, hold ]) else: chunks = applyBasicSpacing(merge(start_list, end_list), fps, 0, 0, log) for item in chunks: if (item[2] == 1): zooms.append([ 'zoom', str(item[0]), str(item[1]), start_zoom, end_zoom, x, y, inter, hold ]) if (zooms == []): log.warning('No zooms applied.') else: log.print(f' {len(zooms)} applied.') log.debug(zooms) return zooms