Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import subprocess
|
| 4 |
+
|
| 5 |
+
def download_video(url, filename='input.mp4'):
|
| 6 |
+
print("Downloading video...")
|
| 7 |
+
r = requests.get(url, stream=True)
|
| 8 |
+
with open(filename, 'wb') as f:
|
| 9 |
+
for chunk in r.iter_content(chunk_size=1024 * 1024):
|
| 10 |
+
if chunk:
|
| 11 |
+
f.write(chunk)
|
| 12 |
+
print("Download completed.")
|
| 13 |
+
|
| 14 |
+
def convert_video(input_file, output_file='output_720p.mp4', resolution='720'):
|
| 15 |
+
print(f"Converting to {resolution}p...")
|
| 16 |
+
height = resolution
|
| 17 |
+
cmd = [
|
| 18 |
+
'ffmpeg',
|
| 19 |
+
'-i', input_file,
|
| 20 |
+
'-vf', f'scale=-2:{height}', # maintain aspect ratio
|
| 21 |
+
'-c:a', 'copy',
|
| 22 |
+
output_file
|
| 23 |
+
]
|
| 24 |
+
subprocess.run(cmd, check=True)
|
| 25 |
+
print(f"Conversion completed: {output_file}")
|
| 26 |
+
|
| 27 |
+
def cleanup(files):
|
| 28 |
+
for file in files:
|
| 29 |
+
if os.path.exists(file):
|
| 30 |
+
os.remove(file)
|
| 31 |
+
|
| 32 |
+
# --- Example usage ---
|
| 33 |
+
remote_url = "https://cdn.discordapp.com/attachments/1203085435778367529/1366808458627911710/2025-04-29_11-57-59.mp4?ex=68144552&is=6812f3d2&hm=53d8b063a910c0c3306b9e0f8f36941afce65064cfc9b823e22be8a4f1bfc00b&"
|
| 34 |
+
download_video(remote_url)
|
| 35 |
+
convert_video('input.mp4', 'video_480p.mp4', resolution='480')
|
| 36 |
+
# cleanup(['input.mp4']) # optional cleanup
|