diff --git a/annolid/utils/videos.py b/annolid/utils/videos.py index 8a7bff4..184905b 100644 --- a/annolid/utils/videos.py +++ b/annolid/utils/videos.py @@ -2,7 +2,12 @@ import subprocess -def convert_mkv_to_mp4(input_folder, output_folder): +def convert_mkv_to_mp4(input_folder, output_folder, scale_factor): + # Ensure the input folder exists + if not os.path.exists(input_folder): + print("Input folder does not exist.") + return + # Ensure the output folder exists, create it if it doesn't if not os.path.exists(output_folder): os.makedirs(output_folder) @@ -10,6 +15,10 @@ def convert_mkv_to_mp4(input_folder, output_folder): # Get a list of all .mkv files in the input folder mkv_files = [f for f in os.listdir(input_folder) if f.endswith('.mkv')] + if not mkv_files: + print("No .mkv files found in the input folder.") + return + for mkv_file in mkv_files: input_path = os.path.join(input_folder, mkv_file) output_path = os.path.join( @@ -18,7 +27,7 @@ def convert_mkv_to_mp4(input_folder, output_folder): # Run ffmpeg command to convert mkv to mp4 and resize cmd = [ 'ffmpeg', '-i', input_path, - '-vf', 'scale=iw/2:ih/2', + '-vf', f'scale=iw*{scale_factor}:ih*{scale_factor}', '-c:v', 'libx264', '-crf', '23', '-c:a', 'aac', '-b:a', '128k', output_path @@ -35,4 +44,10 @@ def convert_mkv_to_mp4(input_folder, output_folder): input_folder = input("Enter the input folder path containing .mkv files: ") output_folder = input( "Enter the output folder path for converted .mp4 files: ") - convert_mkv_to_mp4(input_folder, output_folder) + scale_factor = float( + input("Enter the scale factor (e.g., 0.5 for half size): ")) + + if scale_factor <= 0: + print("Scale factor must be greater than 0.") + else: + convert_mkv_to_mp4(input_folder, output_folder, scale_factor)