From ba4eac17751289b3a528d1612b0a02ee15f7e689 Mon Sep 17 00:00:00 2001 From: pat-e Date: Sun, 20 Jul 2025 10:12:29 +0200 Subject: [PATCH] error in crop-detect logic --- cropdetect.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cropdetect.py b/cropdetect.py index 0f691d1..92d9dba 100644 --- a/cropdetect.py +++ b/cropdetect.py @@ -401,12 +401,30 @@ def main(): duration = int(float(duration_str)) print(f"Detected duration: {duration}s") + # Probe for resolution, handling multiple video streams (e.g., with cover art) probe_res_args = [ - 'ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=s=x:p=0', + 'ffprobe', '-v', 'error', + '-select_streams', 'v', # Select all video streams + '-show_entries', 'stream=width,height,disposition', + '-of', 'json', input_file ] - resolution_str = subprocess.check_output(probe_res_args, stderr=subprocess.STDOUT, text=True) - width, height = map(int, resolution_str.strip().split('x')) + probe_output = subprocess.check_output(probe_res_args, stderr=subprocess.STDOUT, text=True) + streams_data = json.loads(probe_output) + + video_stream = None + # Find the first video stream that is NOT an attached picture + for stream in streams_data.get('streams', []): + if stream.get('disposition', {}).get('attached_pic', 0) == 0: + video_stream = stream + break + + if not video_stream or 'width' not in video_stream or 'height' not in video_stream: + # If no suitable stream is found, raise an error. + raise ValueError("Could not find a valid video stream to probe for resolution.") + + width = int(video_stream['width']) + height = int(video_stream['height']) print(f"Detected resolution: {width}x{height}") except Exception as e: