Split a video into several shorter ones of equal duration. Parameters ---------- n_splits : int Number of shorter videos to produce suffix: str, optional String added to the name of the splits ('short' by default). dest_folder: str,
(self, n_splits, suffix="split", dest_folder=None)
| 251 | return output_path |
| 252 | |
| 253 | def split(self, n_splits, suffix="split", dest_folder=None): |
| 254 | """Split a video into several shorter ones of equal duration. |
| 255 | |
| 256 | Parameters |
| 257 | ---------- |
| 258 | n_splits : int |
| 259 | Number of shorter videos to produce |
| 260 | |
| 261 | suffix: str, optional |
| 262 | String added to the name of the splits ('short' by default). |
| 263 | |
| 264 | dest_folder: str, optional |
| 265 | Folder the video splits are saved into (by default, same as the original video) |
| 266 | |
| 267 | Returns |
| 268 | ------- |
| 269 | list |
| 270 | Paths of the video splits |
| 271 | """ |
| 272 | if not n_splits > 1: |
| 273 | raise ValueError("The video should at least be split in half.") |
| 274 | chunk_dur = self.calc_duration() / n_splits |
| 275 | splits = np.arange(n_splits + 1) * chunk_dur |
| 276 | |
| 277 | def time_formatter(val): |
| 278 | return str(datetime.timedelta(seconds=val)) |
| 279 | |
| 280 | clips = [] |
| 281 | for n, (start, end) in enumerate(zip(splits, splits[1:], strict=False), start=1): |
| 282 | clips.append( |
| 283 | self.shorten( |
| 284 | time_formatter(start), |
| 285 | time_formatter(end), |
| 286 | f"{suffix}{n}", |
| 287 | dest_folder, |
| 288 | validate_inputs=False, |
| 289 | ) |
| 290 | ) |
| 291 | return clips |
| 292 | |
| 293 | def crop(self, suffix="crop", dest_folder=None): |
| 294 | x1, _, y1, _ = self.get_bbox() |