fix end of vdeo captions issue
Browse files- yttemporal180m.py +9 -9
yttemporal180m.py
CHANGED
@@ -97,13 +97,9 @@ class yttemporal180m(datasets.GeneratorBasedBuilder):
|
|
97 |
|
98 |
# Divide video by segments of 15 sec
|
99 |
max_sec_per_segment = 15
|
|
|
100 |
num_chunks = (
|
101 |
-
int(
|
102 |
-
divmod(infos["subtitles"][-1]["time"], max_sec_per_segment)[
|
103 |
-
0
|
104 |
-
]
|
105 |
-
)
|
106 |
-
+ 1
|
107 |
)
|
108 |
time_chunks = [
|
109 |
i * max_sec_per_segment for i in range(num_chunks + 1)
|
@@ -111,9 +107,10 @@ class yttemporal180m(datasets.GeneratorBasedBuilder):
|
|
111 |
time_chunk_idx = 0
|
112 |
caption = ""
|
113 |
for el in infos["subtitles"]:
|
114 |
-
if
|
115 |
-
|
116 |
-
|
|
|
117 |
timestamp_start = float(time_chunks[time_chunk_idx])
|
118 |
timestamp_stop = float(time_chunks[time_chunk_idx + 1])
|
119 |
time_chunk_idx += 1
|
@@ -136,5 +133,8 @@ class yttemporal180m(datasets.GeneratorBasedBuilder):
|
|
136 |
}
|
137 |
idx += 1
|
138 |
caption = ""
|
|
|
|
|
|
|
139 |
if idx > 1000:
|
140 |
break
|
|
|
97 |
|
98 |
# Divide video by segments of 15 sec
|
99 |
max_sec_per_segment = 15
|
100 |
+
last_caption_timestamp = infos["subtitles"][-1]["time"]
|
101 |
num_chunks = (
|
102 |
+
int(divmod(last_caption_timestamp, max_sec_per_segment)[0]) + 1
|
|
|
|
|
|
|
|
|
|
|
103 |
)
|
104 |
time_chunks = [
|
105 |
i * max_sec_per_segment for i in range(num_chunks + 1)
|
|
|
107 |
time_chunk_idx = 0
|
108 |
caption = ""
|
109 |
for el in infos["subtitles"]:
|
110 |
+
if (
|
111 |
+
el["time"] > time_chunks[time_chunk_idx + 1]
|
112 |
+
or el["time"] == last_caption_timestamp
|
113 |
+
):
|
114 |
timestamp_start = float(time_chunks[time_chunk_idx])
|
115 |
timestamp_stop = float(time_chunks[time_chunk_idx + 1])
|
116 |
time_chunk_idx += 1
|
|
|
133 |
}
|
134 |
idx += 1
|
135 |
caption = ""
|
136 |
+
caption += el["word"] + " "
|
137 |
+
else:
|
138 |
+
caption += el["word"] + " "
|
139 |
if idx > 1000:
|
140 |
break
|