Commit
·
c7cbbf8
1
Parent(s):
2140c28
add highlight color option, edit bg_color selection
Browse files- main.py +2 -1
- static/process_settings.html +34 -25
- utils/process_video.py +12 -11
- utils/subtitler.py +3 -2
main.py
CHANGED
@@ -115,11 +115,12 @@ async def process_video_api(video_path: str = Form(...),
|
|
115 |
bg_color: Optional[str] = Form("#070a13b3"),
|
116 |
text_color: Optional[str] = Form("white"),
|
117 |
highlight_mode: Optional[bool] = Form(False),
|
|
|
118 |
caption_mode: Optional[str] = Form("desktop"),
|
119 |
temp_dir: TemporaryDirectory = Depends(get_temp_dir)
|
120 |
):
|
121 |
try:
|
122 |
-
output_path = process_video(video_path, srt_string, srt_json, fontsize, font, bg_color, text_color, highlight_mode, caption_mode)
|
123 |
with open(os.path.join(temp_dir.name, f"{video_path.split('.')[0]}.srt"), 'w+') as temp_srt_file:
|
124 |
logging.info("Processing the video...")
|
125 |
temp_srt_file.write(srt_string)
|
|
|
115 |
bg_color: Optional[str] = Form("#070a13b3"),
|
116 |
text_color: Optional[str] = Form("white"),
|
117 |
highlight_mode: Optional[bool] = Form(False),
|
118 |
+
highlight_color: Optional[str] = Form("LightBlue"),
|
119 |
caption_mode: Optional[str] = Form("desktop"),
|
120 |
temp_dir: TemporaryDirectory = Depends(get_temp_dir)
|
121 |
):
|
122 |
try:
|
123 |
+
output_path = process_video(video_path, srt_string, srt_json, fontsize, font, bg_color, text_color, highlight_mode, highlight_color, caption_mode)
|
124 |
with open(os.path.join(temp_dir.name, f"{video_path.split('.')[0]}.srt"), 'w+') as temp_srt_file:
|
125 |
logging.info("Processing the video...")
|
126 |
temp_srt_file.write(srt_string)
|
static/process_settings.html
CHANGED
@@ -24,9 +24,9 @@
|
|
24 |
}
|
25 |
|
26 |
.form-section {
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
}
|
31 |
|
32 |
.column {
|
@@ -115,29 +115,29 @@
|
|
115 |
|
116 |
<div class="form-section">
|
117 |
<!-- Left Column -->
|
118 |
-
|
119 |
<h3>Highlighting Mode</h3>
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
</div>
|
140 |
</div>
|
|
|
141 |
|
142 |
<!-- Right Column -->
|
143 |
<div class="column">
|
@@ -152,13 +152,20 @@
|
|
152 |
</select>
|
153 |
|
154 |
<label for="bg_color">Background color</label>
|
155 |
-
<
|
|
|
|
|
156 |
|
157 |
<label for="text_color">Text color</label>
|
158 |
<select id="text_color" name="text_color">
|
159 |
<option>Loading colors...</option>
|
160 |
</select>
|
161 |
|
|
|
|
|
|
|
|
|
|
|
162 |
<label for="caption_mode">Caption mode</label>
|
163 |
<select name="caption_mode">
|
164 |
<option value="desktop">Desktop</option>
|
@@ -213,7 +220,9 @@
|
|
213 |
}
|
214 |
|
215 |
populateDropdown('font', '/static/fonts.txt', "Helvetica");
|
|
|
216 |
populateDropdown('text_color', '/static/colors.txt', "white");
|
|
|
217 |
|
218 |
toggleTranscriptionFields(); // Set proper display state
|
219 |
});
|
|
|
24 |
}
|
25 |
|
26 |
.form-section {
|
27 |
+
display: flex;
|
28 |
+
flex-direction: row;
|
29 |
+
gap: 3rem;
|
30 |
}
|
31 |
|
32 |
.column {
|
|
|
115 |
|
116 |
<div class="form-section">
|
117 |
<!-- Left Column -->
|
118 |
+
<div class="column">
|
119 |
<h3>Highlighting Mode</h3>
|
120 |
+
<div class="radio-container">
|
121 |
+
<div class="radio-option">
|
122 |
+
<label for="mode_normal">Normal</label>
|
123 |
+
<input type="radio" name="highlight_mode" value="false" id="mode_normal" checked onchange="toggleTranscriptionFields()">
|
124 |
+
</div>
|
125 |
+
<div class="radio-option">
|
126 |
+
<label for="mode_highlight">Word-level</label>
|
127 |
+
<input type="radio" name="highlight_mode" value="true" id="mode_highlight" onchange="toggleTranscriptionFields()">
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
|
131 |
+
<div id="normal_input">
|
132 |
+
<label for="srt_string">Transcription (SRT)</label>
|
133 |
+
<textarea name="srt_string" id="srt_string">{{ transcription_text }}</textarea>
|
134 |
+
</div>
|
135 |
+
|
136 |
+
<div id="highlight_input" style="display: none;">
|
137 |
+
<label for="srt_json">Transcription (JSON)</label>
|
138 |
+
<textarea name="srt_json" id="srt_json"></textarea>
|
|
|
139 |
</div>
|
140 |
+
</div>
|
141 |
|
142 |
<!-- Right Column -->
|
143 |
<div class="column">
|
|
|
152 |
</select>
|
153 |
|
154 |
<label for="bg_color">Background color</label>
|
155 |
+
<select id="bg_color" name="bg_color">
|
156 |
+
<option>Loading colors...</option>
|
157 |
+
</select>
|
158 |
|
159 |
<label for="text_color">Text color</label>
|
160 |
<select id="text_color" name="text_color">
|
161 |
<option>Loading colors...</option>
|
162 |
</select>
|
163 |
|
164 |
+
<label for="highlight_color">Highlight color</label>
|
165 |
+
<select id="highlight_color" name="highlight_color">
|
166 |
+
<option>Loading colors...</option>
|
167 |
+
</select>
|
168 |
+
|
169 |
<label for="caption_mode">Caption mode</label>
|
170 |
<select name="caption_mode">
|
171 |
<option value="desktop">Desktop</option>
|
|
|
220 |
}
|
221 |
|
222 |
populateDropdown('font', '/static/fonts.txt', "Helvetica");
|
223 |
+
populateDropdown('bg_color', '/static/colors.txt', "grey");
|
224 |
populateDropdown('text_color', '/static/colors.txt', "white");
|
225 |
+
populateDropdown('highlight_color', '/static/colors.txt', "LightBlue");
|
226 |
|
227 |
toggleTranscriptionFields(); // Set proper display state
|
228 |
});
|
utils/process_video.py
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
-
import logging, os
|
2 |
from utils.subtitler import subtitler
|
3 |
|
4 |
def process_video(invideo_file: str,
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
invideo_path_parts = os.path.normpath(invideo_file).split(os.path.sep)
|
15 |
VIDEO_NAME = os.path.basename(invideo_file)
|
16 |
OUTVIDEO_PATH = os.path.join(os.path.normpath('/'.join(invideo_path_parts[:-1])), f"result_{VIDEO_NAME}")
|
17 |
logging.info("Subtitling...")
|
18 |
-
subtitler(invideo_file, srt_string, srt_json, OUTVIDEO_PATH, fontsize, font, bg_color, text_color, highlight_mode, caption_mode)
|
19 |
return OUTVIDEO_PATH
|
|
|
1 |
+
import logging, os
|
2 |
from utils.subtitler import subtitler
|
3 |
|
4 |
def process_video(invideo_file: str,
|
5 |
+
srt_string:str,
|
6 |
+
srt_json: str,
|
7 |
+
fontsize:str,
|
8 |
+
font:str,
|
9 |
+
bg_color:str,
|
10 |
+
text_color:str,
|
11 |
+
highlight_mode: bool,
|
12 |
+
highlight_color: str,
|
13 |
+
caption_mode:str
|
14 |
+
):
|
15 |
invideo_path_parts = os.path.normpath(invideo_file).split(os.path.sep)
|
16 |
VIDEO_NAME = os.path.basename(invideo_file)
|
17 |
OUTVIDEO_PATH = os.path.join(os.path.normpath('/'.join(invideo_path_parts[:-1])), f"result_{VIDEO_NAME}")
|
18 |
logging.info("Subtitling...")
|
19 |
+
subtitler(invideo_file, srt_string, srt_json, OUTVIDEO_PATH, fontsize, font, bg_color, text_color, highlight_mode, highlight_color, caption_mode)
|
20 |
return OUTVIDEO_PATH
|
utils/subtitler.py
CHANGED
@@ -37,6 +37,7 @@ def subtitler(video_file: str,
|
|
37 |
bg_color: str,
|
38 |
text_color: str,
|
39 |
highlight_mode: bool,
|
|
|
40 |
caption_mode: str
|
41 |
):
|
42 |
"""Add subtitles to a video, with optional word-level highlighting."""
|
@@ -55,7 +56,7 @@ def subtitler(video_file: str,
|
|
55 |
line_end = float(line["end"])
|
56 |
line_text = line["text"]
|
57 |
|
58 |
-
base_clip = TextClip(line_text, fontsize=fontsize, color=text_color,
|
59 |
base_clip = base_clip.set_start(line_start).set_end(line_end)
|
60 |
|
61 |
# Center the full line
|
@@ -73,7 +74,7 @@ def subtitler(video_file: str,
|
|
73 |
|
74 |
# Create a background-only word clip
|
75 |
word_clip = TextClip(word, fontsize=fontsize, color=text_color, stroke_color=text_color, stroke_width=2, font=font,
|
76 |
-
method='label', bg_color=
|
77 |
word_clip = word_clip.set_start(word_start).set_end(word_end)
|
78 |
word_clip = word_clip.set_position((current_x - 7.5, subtitle_y_position))
|
79 |
subtitle_clips.append(word_clip)
|
|
|
37 |
bg_color: str,
|
38 |
text_color: str,
|
39 |
highlight_mode: bool,
|
40 |
+
highlight_color: str,
|
41 |
caption_mode: str
|
42 |
):
|
43 |
"""Add subtitles to a video, with optional word-level highlighting."""
|
|
|
56 |
line_end = float(line["end"])
|
57 |
line_text = line["text"]
|
58 |
|
59 |
+
base_clip = TextClip(line_text, fontsize=fontsize, font=font, color=text_color, bg_color=bg_color, method='label')
|
60 |
base_clip = base_clip.set_start(line_start).set_end(line_end)
|
61 |
|
62 |
# Center the full line
|
|
|
74 |
|
75 |
# Create a background-only word clip
|
76 |
word_clip = TextClip(word, fontsize=fontsize, color=text_color, stroke_color=text_color, stroke_width=2, font=font,
|
77 |
+
method='label', bg_color=highlight_color)
|
78 |
word_clip = word_clip.set_start(word_start).set_end(word_end)
|
79 |
word_clip = word_clip.set_position((current_x - 7.5, subtitle_y_position))
|
80 |
subtitle_clips.append(word_clip)
|