Spaces:
Runtime error
Runtime error
Commit
·
9002374
1
Parent(s):
ce07bfe
big fixes
Browse files- adjust.py +1 -1
- file_name.py +12 -11
- set_up.py +2 -1
- transcribe.py +7 -5
- video_tool.py +6 -6
adjust.py
CHANGED
@@ -116,7 +116,7 @@ def start_adjust(input_file, to_name, start_time, end_time, progress=gr.Progress
|
|
116 |
# Adding subtitle to video
|
117 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
118 |
add_subtitle_to_video(
|
119 |
-
input_file,
|
120 |
|
121 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
122 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(
|
|
|
116 |
# Adding subtitle to video
|
117 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
118 |
add_subtitle_to_video(
|
119 |
+
input_file, base_subtitle_adjusted_file, video_subtitle_file, start_time, end_time)
|
120 |
|
121 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
122 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(
|
file_name.py
CHANGED
@@ -3,16 +3,17 @@ import os
|
|
3 |
|
4 |
current_working_directory = os.getcwd()
|
5 |
|
6 |
-
download_file = f"{current_working_directory}
|
7 |
-
audio_file = f"{current_working_directory}
|
8 |
-
transcribe_file = f"{current_working_directory}
|
|
|
9 |
|
10 |
-
subtitle_file = f"{current_working_directory}
|
11 |
-
|
12 |
-
subtitle_adjusted_file = f"{current_working_directory}
|
13 |
-
|
14 |
|
15 |
-
transcribe_adjusted_file = f"{current_working_directory}
|
16 |
-
video_subtitle_file = f"{current_working_directory}
|
17 |
-
sample_groups_json = f"{current_working_directory}
|
18 |
-
speaker_groups_json = f"{current_working_directory}
|
|
|
3 |
|
4 |
current_working_directory = os.getcwd()
|
5 |
|
6 |
+
download_file = f"{current_working_directory}\\download_video.mp4"
|
7 |
+
audio_file = f"{current_working_directory}\\input.wav"
|
8 |
+
transcribe_file = f"{current_working_directory}\\transcribe.txt"
|
9 |
+
cut_video_file = "cut_video.mp4"
|
10 |
|
11 |
+
subtitle_file = f"{current_working_directory}\\subtitle.srt"
|
12 |
+
base_subtitle_file = "subtitle.srt"
|
13 |
+
subtitle_adjusted_file = f"{current_working_directory}\\subtitle_adjusted.srt"
|
14 |
+
base_subtitle_adjusted_file = "subtitle_adjusted.srt"
|
15 |
|
16 |
+
transcribe_adjusted_file = f"{current_working_directory}\\transcribe_adjusted.txt"
|
17 |
+
video_subtitle_file = f"{current_working_directory}\\output.mp4"
|
18 |
+
sample_groups_json = f"{current_working_directory}\\sample_groups.json"
|
19 |
+
speaker_groups_json = f"{current_working_directory}\\speaker_groups.json"
|
set_up.py
CHANGED
@@ -21,6 +21,7 @@ def prepare_input(input_file, start_time, end_time, lang, model_size, progress=g
|
|
21 |
if validate_time_format(end_time) is False:
|
22 |
gr.Warning(ui_lang["end_time_warning"])
|
23 |
return [None, None, [None, None]]
|
|
|
24 |
if lang is None:
|
25 |
gr.Warning(ui_lang["lang_radio_warning"])
|
26 |
return [None, None, [None, None]]
|
@@ -46,7 +47,7 @@ def prepare_input(input_file, start_time, end_time, lang, model_size, progress=g
|
|
46 |
|
47 |
# Add subtitle to video
|
48 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
49 |
-
add_subtitle_to_video(input_file,
|
50 |
video_subtitle_file, start_time, end_time)
|
51 |
|
52 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
|
|
21 |
if validate_time_format(end_time) is False:
|
22 |
gr.Warning(ui_lang["end_time_warning"])
|
23 |
return [None, None, [None, None]]
|
24 |
+
# Check if start time is lower than end time
|
25 |
if lang is None:
|
26 |
gr.Warning(ui_lang["lang_radio_warning"])
|
27 |
return [None, None, [None, None]]
|
|
|
47 |
|
48 |
# Add subtitle to video
|
49 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
50 |
+
add_subtitle_to_video(input_file, base_subtitle_file,
|
51 |
video_subtitle_file, start_time, end_time)
|
52 |
|
53 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
transcribe.py
CHANGED
@@ -33,11 +33,12 @@ def start_transcribe(input_file, lang_choice: int, model_size_choice: int, progr
|
|
33 |
|
34 |
speaker_txt_list = []
|
35 |
shift = speaker_groups[speaker][0] + 1
|
36 |
-
print(
|
|
|
37 |
name = str(speaker)[:10]
|
38 |
for segment in segments_list:
|
39 |
-
start =
|
40 |
-
end =
|
41 |
|
42 |
segment_txt = segment.text
|
43 |
speaker_txt_list.append(segment_txt)
|
@@ -46,13 +47,14 @@ def start_transcribe(input_file, lang_choice: int, model_size_choice: int, progr
|
|
46 |
subtitle_txt_list.append(subtitle)
|
47 |
|
48 |
speaker_txt = " ".join(speaker_txt_list)
|
49 |
-
transcribe_txt_list.append(
|
|
|
50 |
|
51 |
utils.write_transcribe_subtitle_file(
|
52 |
input_file, transcribe_txt_list, subtitle_txt_list, False)
|
53 |
|
54 |
|
55 |
-
def
|
56 |
return '{0:02d}:{1:02d}:{2:06.3f}'.format(round(t // 3600),
|
57 |
round(t % 3600 // 60),
|
58 |
t % 60)
|
|
|
33 |
|
34 |
speaker_txt_list = []
|
35 |
shift = speaker_groups[speaker][0] + 1
|
36 |
+
print(
|
37 |
+
f"Current starting point: {shift}s or {time_str_subtitle(shift)}")
|
38 |
name = str(speaker)[:10]
|
39 |
for segment in segments_list:
|
40 |
+
start = time_str_subtitle(segment.start + shift)
|
41 |
+
end = time_str_subtitle(segment.end + shift)
|
42 |
|
43 |
segment_txt = segment.text
|
44 |
speaker_txt_list.append(segment_txt)
|
|
|
47 |
subtitle_txt_list.append(subtitle)
|
48 |
|
49 |
speaker_txt = " ".join(speaker_txt_list)
|
50 |
+
transcribe_txt_list.append(
|
51 |
+
f"[{time_str(shift)}]\n[{name}] {speaker_txt}\n")
|
52 |
|
53 |
utils.write_transcribe_subtitle_file(
|
54 |
input_file, transcribe_txt_list, subtitle_txt_list, False)
|
55 |
|
56 |
|
57 |
+
def time_str_subtitle(t):
|
58 |
return '{0:02d}:{1:02d}:{2:06.3f}'.format(round(t // 3600),
|
59 |
round(t % 3600 // 60),
|
60 |
t % 60)
|
video_tool.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import ffmpeg
|
|
|
2 |
|
3 |
|
4 |
def convert_video_to_audio(input_file, output_file, start_time, end_time):
|
@@ -14,21 +15,20 @@ def convert_video_to_audio(input_file, output_file, start_time, end_time):
|
|
14 |
|
15 |
|
16 |
def add_subtitle_to_video(input_file, subtitle_file, output_file, start_time, end_time):
|
17 |
-
print("ADD SUBTITLE")
|
18 |
print(f"INPUT: {input_file}")
|
19 |
print(f"SUBTITLE: {subtitle_file}")
|
20 |
print(f"OUTPUT: {output_file}")
|
21 |
-
|
22 |
(
|
23 |
ffmpeg
|
24 |
.input(input_file)
|
25 |
-
.output(
|
26 |
.run(overwrite_output=True)
|
27 |
)
|
28 |
-
|
29 |
(
|
30 |
ffmpeg
|
31 |
-
.input(
|
32 |
-
.output(output_file,
|
33 |
.run(overwrite_output=True)
|
34 |
)
|
|
|
1 |
import ffmpeg
|
2 |
+
import file_name
|
3 |
|
4 |
|
5 |
def convert_video_to_audio(input_file, output_file, start_time, end_time):
|
|
|
15 |
|
16 |
|
17 |
def add_subtitle_to_video(input_file, subtitle_file, output_file, start_time, end_time):
|
|
|
18 |
print(f"INPUT: {input_file}")
|
19 |
print(f"SUBTITLE: {subtitle_file}")
|
20 |
print(f"OUTPUT: {output_file}")
|
21 |
+
|
22 |
(
|
23 |
ffmpeg
|
24 |
.input(input_file)
|
25 |
+
.output(file_name.cut_video_file, ss=start_time, to=end_time, acodec='copy', vcodec='copy')
|
26 |
.run(overwrite_output=True)
|
27 |
)
|
28 |
+
|
29 |
(
|
30 |
ffmpeg
|
31 |
+
.input(file_name.cut_video_file)
|
32 |
+
.output(output_file, vf=f'subtitles={subtitle_file}', acodec='copy')
|
33 |
.run(overwrite_output=True)
|
34 |
)
|