error in crop-detect logic

This commit is contained in:
2025-07-20 10:12:29 +02:00
parent a9adbc5954
commit ba4eac1775

View File

@@ -401,12 +401,30 @@ def main():
duration = int(float(duration_str)) duration = int(float(duration_str))
print(f"Detected duration: {duration}s") print(f"Detected duration: {duration}s")
# Probe for resolution, handling multiple video streams (e.g., with cover art)
probe_res_args = [ 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 input_file
] ]
resolution_str = subprocess.check_output(probe_res_args, stderr=subprocess.STDOUT, text=True) probe_output = subprocess.check_output(probe_res_args, stderr=subprocess.STDOUT, text=True)
width, height = map(int, resolution_str.strip().split('x')) 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}") print(f"Detected resolution: {width}x{height}")
except Exception as e: except Exception as e: