digidau commited on
Commit
09b3ab2
·
verified ·
1 Parent(s): cb9619b

Update intro.py

Browse files
Files changed (1) hide show
  1. intro.py +70 -25
intro.py CHANGED
@@ -7,15 +7,28 @@ def prepend_intro(
7
  main_video,
8
  output_video
9
  ):
 
 
 
 
 
 
 
 
 
 
10
 
11
  if not intro_video:
12
  return main_video
13
 
14
- normalized_intro = os.path.abspath(
15
- "temp/intro_normalized.mp4"
16
- )
 
 
 
 
17
 
18
- # NORMALIZE INTRO
19
  subprocess.run(
20
  [
21
  "ffmpeg",
@@ -24,9 +37,21 @@ def prepend_intro(
24
  "-i",
25
  intro_video,
26
 
 
 
 
 
 
 
 
 
 
27
  "-vf",
28
- "scale=1920:1080:force_original_aspect_ratio=decrease,"
29
- "pad=1920:1080:(ow-iw)/2:(oh-ih)/2",
 
 
 
30
 
31
  "-r",
32
  "30",
@@ -43,6 +68,12 @@ def prepend_intro(
43
  "-c:a",
44
  "aac",
45
 
 
 
 
 
 
 
46
  "-b:a",
47
  "192k",
48
 
@@ -51,38 +82,52 @@ def prepend_intro(
51
  check=True
52
  )
53
 
54
- list_file = "temp/concat.txt"
55
-
56
- with open(list_file, "w") as f:
57
-
58
- f.write(
59
- f"file '{os.path.abspath(normalized_intro)}'\n"
60
- )
61
-
62
- f.write(
63
- f"file '{os.path.abspath(main_video)}'\n"
64
- )
65
 
66
  subprocess.run(
67
  [
68
  "ffmpeg",
69
  "-y",
70
 
71
- "-f",
72
- "concat",
73
-
74
- "-safe",
75
- "0",
76
 
77
  "-i",
78
- list_file,
 
 
 
79
 
80
- "-c",
81
- "copy",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  output_video
84
  ],
85
  check=True
86
  )
87
 
 
 
 
 
88
  return output_video
 
7
  main_video,
8
  output_video
9
  ):
10
+ """
11
+ Intro boleh:
12
+ - tanpa audio
13
+ - dengan audio
14
+ - codec apa saja
15
+ - resolusi apa saja
16
+
17
+ Akan dinormalisasi dulu lalu digabung
18
+ dengan video Quran utama.
19
+ """
20
 
21
  if not intro_video:
22
  return main_video
23
 
24
+ os.makedirs("temp", exist_ok=True)
25
+
26
+ normalized_intro = "temp/intro_normalized.mp4"
27
+
28
+ print("=" * 60)
29
+ print("NORMALIZING INTRO")
30
+ print("=" * 60)
31
 
 
32
  subprocess.run(
33
  [
34
  "ffmpeg",
 
37
  "-i",
38
  intro_video,
39
 
40
+ # tambahkan audio silent
41
+ "-f",
42
+ "lavfi",
43
+
44
+ "-i",
45
+ "anullsrc=r=48000:cl=stereo",
46
+
47
+ "-shortest",
48
+
49
  "-vf",
50
+ (
51
+ "scale=1920:1080:"
52
+ "force_original_aspect_ratio=decrease,"
53
+ "pad=1920:1080:(ow-iw)/2:(oh-ih)/2"
54
+ ),
55
 
56
  "-r",
57
  "30",
 
68
  "-c:a",
69
  "aac",
70
 
71
+ "-ar",
72
+ "48000",
73
+
74
+ "-ac",
75
+ "2",
76
+
77
  "-b:a",
78
  "192k",
79
 
 
82
  check=True
83
  )
84
 
85
+ print("=" * 60)
86
+ print("CONCAT INTRO + MAIN")
87
+ print("=" * 60)
 
 
 
 
 
 
 
 
88
 
89
  subprocess.run(
90
  [
91
  "ffmpeg",
92
  "-y",
93
 
94
+ "-i",
95
+ normalized_intro,
 
 
 
96
 
97
  "-i",
98
+ main_video,
99
+
100
+ "-filter_complex",
101
+ "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]",
102
 
103
+ "-map",
104
+ "[v]",
105
+
106
+ "-map",
107
+ "[a]",
108
+
109
+ "-c:v",
110
+ "libx264",
111
+
112
+ "-preset",
113
+ "veryfast",
114
+
115
+ "-crf",
116
+ "22",
117
+
118
+ "-c:a",
119
+ "aac",
120
+
121
+ "-b:a",
122
+ "192k",
123
 
124
  output_video
125
  ],
126
  check=True
127
  )
128
 
129
+ print("=" * 60)
130
+ print("INTRO CONCAT SUCCESS")
131
+ print("=" * 60)
132
+
133
  return output_video