| import os |
| import subprocess |
|
|
|
|
| def prepend_intro( |
| intro_video, |
| main_video, |
| output_video |
| ): |
| """ |
| Intro boleh: |
| - tanpa audio |
| - dengan audio |
| - codec apa saja |
| - resolusi apa saja |
| |
| Akan dinormalisasi dulu lalu digabung |
| dengan video Quran utama. |
| """ |
|
|
| if not intro_video: |
| return main_video |
|
|
| os.makedirs("temp", exist_ok=True) |
|
|
| normalized_intro = "temp/intro_normalized.mp4" |
|
|
| print("=" * 60) |
| print("NORMALIZING INTRO") |
| print("=" * 60) |
|
|
| subprocess.run( |
| [ |
| "ffmpeg", |
| "-y", |
|
|
| "-i", |
| intro_video, |
|
|
| |
| "-f", |
| "lavfi", |
|
|
| "-i", |
| "anullsrc=r=48000:cl=stereo", |
|
|
| "-shortest", |
|
|
| "-vf", |
| ( |
| "scale=1920:1080:" |
| "force_original_aspect_ratio=decrease," |
| "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" |
| ), |
|
|
| "-r", |
| "30", |
|
|
| "-c:v", |
| "libx264", |
|
|
| "-preset", |
| "veryfast", |
|
|
| "-crf", |
| "22", |
|
|
| "-c:a", |
| "aac", |
|
|
| "-ar", |
| "48000", |
|
|
| "-ac", |
| "2", |
|
|
| "-b:a", |
| "192k", |
|
|
| normalized_intro |
| ], |
| check=True |
| ) |
|
|
| print("=" * 60) |
| print("CONCAT INTRO + MAIN") |
| print("=" * 60) |
|
|
| subprocess.run( |
| [ |
| "ffmpeg", |
| "-y", |
|
|
| "-i", |
| normalized_intro, |
|
|
| "-i", |
| main_video, |
|
|
| "-filter_complex", |
| "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]", |
|
|
| "-map", |
| "[v]", |
|
|
| "-map", |
| "[a]", |
|
|
| "-c:v", |
| "libx264", |
|
|
| "-preset", |
| "veryfast", |
|
|
| "-crf", |
| "22", |
|
|
| "-c:a", |
| "aac", |
|
|
| "-b:a", |
| "192k", |
|
|
| output_video |
| ], |
| check=True |
| ) |
|
|
| print("=" * 60) |
| print("INTRO CONCAT SUCCESS") |
| print("=" * 60) |
|
|
| return output_video |