From 7ceed58e7b70645ade9b5528a74aa7901fe2ff2c Mon Sep 17 00:00:00 2001 From: Javanaut Date: Sun, 2 Feb 2025 12:10:04 +0100 Subject: [PATCH] add cropdetect stub --- src/ffx/ffx.py | 35 +++++++++++++++++++++ src/ffx/file_properties.py | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/src/ffx/ffx.py b/src/ffx/ffx.py index 27fde19..e922621 100755 --- a/src/ffx/ffx.py +++ b/src/ffx/ffx.py @@ -212,6 +212,41 @@ def unmux(ctx, ctx.obj['logger'].warning(f"Skipping File {sourcePath} ({ex})") +@ffx.command() +@click.pass_context + +@click.argument('paths', nargs=-1) +@click.option('--nice', type=int, default=99, help='Niceness of started processes') +@click.option('--cpu', type=int, default=0, help='Limit CPU for started processes to percent') +def cropdetect(ctx, + paths, + label, + output_directory, + subtitles_only, + nice, + cpu): + + existingSourcePaths = [p for p in paths if os.path.isfile(p)] + ctx.obj['logger'].debug(f"\nUnmuxing {len(existingSourcePaths)} files") + + ctx.obj['resource_limits'] = {} + ctx.obj['resource_limits']['niceness'] = nice + ctx.obj['resource_limits']['cpu_percent'] = cpu + + for sourcePath in existingSourcePaths: + + + try: + + fp = FileProperties(ctx.obj, sourcePath) + cropParams = fp.findCropParams() + + click.echo(cropParams) + + except Exception as ex: + ctx.obj['logger'].warning(f"Skipping File {sourcePath} ({ex})") + + @ffx.command() @click.pass_context diff --git a/src/ffx/file_properties.py b/src/ffx/file_properties.py index ec31153..d8ac319 100644 --- a/src/ffx/file_properties.py +++ b/src/ffx/file_properties.py @@ -174,6 +174,69 @@ class FileProperties(): return json.loads(ffprobeOutput)['streams'] + + def findCropParams(self): + """Returns ffprobe stream data as array with elements according to the following example + { + "index": 4, + "codec_name": "hdmv_pgs_subtitle", + "codec_long_name": "HDMV Presentation Graphic Stream subtitles", + "codec_type": "subtitle", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/1000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 1421035, + "duration": "1421.035000", + "disposition": { + "default": 1, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "non_diegetic": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "language": "ger", + "title": "German Full" + } + } + """ + + # ffmpeg -i -vf cropdetect -f null - + ffprobeOutput, ffprobeError, returnCode = executeProcess(["ffmpeg" "-i", + self.__sourcePath, + "-vf", "cropdetect", + "-t", "180", + "-f", "null", "-" + ]) + + errorLines = ffprobeError.split('\n') + + for el in errorLines: + + print(el) + + + # return json.loads(ffprobeOutput)['streams'] + + + def getMediaDescriptor(self): return MediaDescriptor.fromFfprobe(self.context, self.getFormatData(), self.getStreamData())