import os import requests import subprocess def download_video(url, filename='input.mp4'): print("Downloading video...") r = requests.get(url, stream=True) with open(filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024 * 1024): if chunk: f.write(chunk) print("Download completed.") def convert_video(input_file, output_file='output_720p.mp4', resolution='720'): print(f"Converting to {resolution}p...") height = resolution cmd = [ 'ffmpeg', '-i', input_file, '-vf', f'scale=-2:{height}', # maintain aspect ratio '-c:a', 'copy', output_file ] subprocess.run(cmd, check=True) print(f"Conversion completed: {output_file}") def cleanup(files): for file in files: if os.path.exists(file): os.remove(file) # --- Example usage --- remote_url = "https://cdn.discordapp.com/attachments/1203085435778367529/1366808458627911710/2025-04-29_11-57-59.mp4?ex=68144552&is=6812f3d2&hm=53d8b063a910c0c3306b9e0f8f36941afce65064cfc9b823e22be8a4f1bfc00b&" download_video(remote_url) convert_video('input.mp4', 'video_480p.mp4', resolution='480') # cleanup(['input.mp4']) # optional cleanup