api
Simple interface for extracting audio, clips, frames, and gifs from a video file.
extract
Extract audio, individual frames, short clips and GIFs from videos.
See the documentation for list of options, or:
extract_audio: Extract audio from a video file.extract_clip: Extract a short clip from a video file asmp4.extract_frames: Extract individual frames from a video and save them as images.extract_gif: Create a GIF from a video between two specified points.
Args:
`method` (str):
The extraction method to use ("audio", "clip", "frames", "gif").
`filepath` (Path | str):
Path to the video file with extension.
`skip_validation` (bool):
If True, skips validation of the extraction options. This can slightly
improve speed, but it is not recommended unless you are sure that the
options are valid.
`**options` (dict[str, Any] | None):
Extraction options specific to the chosen extraction method.
Returns:
`Result`: A dataclass containing the extraction details.
Raises:
`InvalidExtractionMethod`:
If the extraction method is neither "audio", "clip", "frames", nor "gif".
Source code in videoxt/api.py
extract_audio
extract_audio(filepath, start_time=0, stop_time=None, destdir=None, filename=None, verbose=False, overwrite=False, fps=None, audio_format='mp3', speed=1, bounce=False, reverse=False, volume=1, normalize=False)
Extract audio from a video file.
Args:
`filepath` (Path | str):
Path to the video file with extension.
`start_time` (float | int | str):
Specify the extraction's start time in seconds, or as a string in "HH:MM:SS"
format. Defaults to 0 if not specified.
`stop_time` (float | int | str | None):
Specify the extraction's stop time in seconds, or as a string in "HH:MM:SS"
format. Defaults to the video duration if not specified.
`destdir` (Path | None):
Specify the directory you want to save output to. Defaults to the video's
directory if not specified.
`filename` (str | None):
Specify the name of the extracted file(s). Defaults to the video filename
if not specified.
`verbose` (bool):
If True, the prepared request and extraction results will be printed as JSON
to console. Defaults to False if not specified.
`overwrite` (bool):
If True, permits overwriting the destination path if the file or directory
already exists. Defaults to False if not specified.
`fps` (float | None):
Override the frames per second (fps) value obtained from `cv2` when reading
the video. This value is used to set the start and stop frames for the
extraction range. This option should be used only in rare cases where `cv2`
fails to accurately read the fps. If not specified, it defaults to the fps
of the video as read by `cv2`.
`audio_format` (str):
Set the extracted audio file format. Defaults to 'mp3' if not specified.
See: `videoxt.constants.SUPPORTED_AUDIO_FORMATS`.
`speed` (float):
Set the speed of the extracted audio. A value of 0.5 will halve the speed of
the extracted audio. Defaults to 1.0 if not specified (no change).
`bounce` (bool):
If True, bounce the extracted audio bommerang-style. Defaults to False if
not specified.
`reverse` (bool):
If True, reverse the extracted audio. Defaults to False if not specified.
`volume` (float):
Set the volume of the extracted audio. A value of 0.5 will halve the volume
of the extracted audio. Defaults to 1.0 if not specified (no change).
`normalize` (bool):
If True, normalize the audio. Normalization adjusts the gain of the audio to
ensure consistent levels, preventing distortion and enhancing clarity in
some cases. Defaults to False if not specified.
Returns:
`Result`: A dataclass containing the extraction details.
Source code in videoxt/api.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
extract_clip
extract_clip(filepath, start_time=0, stop_time=None, destdir=None, filename=None, verbose=False, overwrite=False, fps=None, dimensions=None, resize=1.0, rotate=0, speed=1.0, bounce=False, reverse=False, monochrome=False, volume=0, normalize=False)
Extract a clip from a video file as mp4.
Recommended usage: Set a short extraction range. The process can be slow for long or high-resolution videos.
Args:
`filepath` (Path | str):
Path to the video file with extension.
`start_time` (float | int | str):
Specify the extraction's start time in seconds, or as a string in "HH:MM:SS"
format. Defaults to 0 if not specified.
`stop_time` (float | int | str | None):
Specify the extraction's stop time in seconds, or as a string in "HH:MM:SS"
format. Defaults to the video duration if not specified.
`destdir` (Path | None):
Specify the directory you want to save output to. Defaults to the video's
directory if not specified.
`filename` (str | None):
Specify the name of the extracted file(s). Defaults to the video filename
if not specified.
`verbose` (bool):
If True, the prepared request and extraction results will be printed as JSON
to console. Defaults to False if not specified.
`overwrite` (bool):
If True, permits overwriting the destination path if the file or directory
already exists. Defaults to False if not specified.
`fps` (float | None):
Override the frames per second (fps) value obtained from `cv2` when reading
the video. This value is used to set the start and stop frames for the
extraction range. This option should be used only in rare cases where `cv2`
fails to accurately read the fps. If not specified, it defaults to the fps
of the video as read by `cv2`.
`dimensions` (tuple[int, int] | None):
Specify the dimensions (frame width, frame height) of the clip. Defaults to
the video dimensions if not specified.
`resize` (float):
Resize the dimensions of the clip by a factor of `n`. A value of 0.5
will halve the dimensions. If you specify `dimensions`, `resize` will apply
to the dimensions you specify. Defaults to 1.0 if not specified (no change).
`rotate` (int):
Rotate the clip by `n` degrees. Allowed values: 0, 90, 180 or 270. Defaults
to 0 if not specified (no change).
`speed` (float):
Set the speed of the extracted clip. A value of 0.5 will halve the playback
speed of the clip. Defaults to 1.0 if not specified (no change).
`bounce` (bool):
If True, bounce the extracted clip bommerang-style. Defaults to False if
not specified.
`reverse` (bool):
If True, reverse the extracted clip. Defaults to False if not specified.
`monochrome` (bool):
If True, apply a black-and-white filter to the clip. Defaults to False if
not specified.
`volume` (float):
Set the volume of the extracted clip's audio. A value of 0.5 will halve the
volume of the clip's audio. Defaults to 1.0 if not specified (no change).
`normalize` (bool):
If True, normalize the audio. Normalization adjusts the gain of the audio to
ensure consistent levels, preventing distortion and enhancing clarity in
some cases. Defaults to False if not specified.
Returns:
`Result`: A dataclass containing the extraction details.
Source code in videoxt/api.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
extract_frames
extract_frames(filepath, start_time=0, stop_time=None, destdir=None, filename=None, verbose=False, overwrite=False, fps=None, image_format='jpg', capture_rate=1, dimensions=None, resize=1.0, rotate=0, monochrome=False)
Extract individual frames from a video and save them to disk as images.
The images are saved to a directory named after the video file, or to a directory you specify.
Args:
`filepath` (Path | str):
Path to the video file with extension.
`start_time` (float | int | str):
Specify the extraction's start time in seconds, or as a string in "HH:MM:SS"
format. Defaults to 0 if not specified.
`stop_time` (float | int | str | None):
Specify the extraction's stop time in seconds, or as a string in "HH:MM:SS"
format. Defaults to the video duration if not specified.
`destdir` (Path | None):
Specify the directory you want to save output to. Defaults to the video's
directory if not specified.
`filename` (str | None):
Specify the name of the extracted file(s). Defaults to the video filename
if not specified.
`verbose` (bool):
If True, the prepared request and extraction results will be printed as JSON
to console. Defaults to False if not specified.
`overwrite` (bool):
If True, permits overwriting the destination path if the file or directory
already exists. Defaults to False if not specified.
`fps` (float | None):
Override the frames per second (fps) value obtained from `cv2` when reading
the video. This value is used to set the start and stop frames for the
extraction range. This option should be used only in rare cases where `cv2`
fails to accurately read the fps. If not specified, it defaults to the fps
of the video as read by `cv2`.
`image_format` (str):
Set the extracted image file format. Defaults to 'jpg' if not specified.
See: `videoxt.constants.SUPPORTED_IMAGE_FORMATS`.
`capture_rate` (int):
Capture every Nth video frame. Defaults to 1 if not specified, which
extracts every frame within the extraction range.
`dimensions` (tuple[int, int] | None):
Specify the dimensions (frame width, frame height) of the images. Defaults
to the video dimensions if not specified.
`resize` (float):
Resize the dimensions of the images by a factor of `n`. A value of 0.5
will halve the dimensions. If you specify `dimensions`, `resize` will apply
to the dimensions you specify. Defaults to 1.0 if not specified (no change).
`rotate` (int):
Rotate the images by `n` degrees. Allowed values: 0, 90, 180 or 270.
Defaults to 0 if not specified (no change).
`monochrome` (bool):
If True, apply a black-and-white filter to the images. Defaults to False if
not specified.
Returns:
`Result`: A dataclass containing the extraction details.
Source code in videoxt/api.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
extract_gif
extract_gif(filepath, start_time=0, stop_time=None, destdir=None, filename=None, verbose=False, overwrite=False, fps=None, dimensions=None, resize=1.0, rotate=0, speed=1.0, bounce=False, reverse=False, monochrome=False)
Extract a GIF from a video file.
Recommended usage: Set a short extraction range. The process can be slow for long or high-resolution videos.
Args:
`filepath` (Path | str):
Path to the video file with extension.
`start_time` (float | int | str):
Specify the extraction's start time in seconds, or as a string in "HH:MM:SS"
format. Defaults to 0 if not specified.
`stop_time` (float | int | str | None):
Specify the extraction's stop time in seconds, or as a string in "HH:MM:SS"
format. Defaults to the video duration if not specified.
`destdir` (Path | None):
Specify the directory you want to save output to. Defaults to the video's
directory if not specified.
`filename` (str | None):
Specify the name of the extracted file(s). Defaults to the video filename
if not specified.
`verbose` (bool):
If True, the prepared request and extraction results will be printed as JSON
to console. Defaults to False if not specified.
`overwrite` (bool):
If True, permits overwriting the destination path if the file or directory
already exists. Defaults to False if not specified.
`fps` (float | None):
Override the frames per second (fps) value obtained from `cv2` when reading
the video. This value is used to set the start and stop frames for the
extraction range. This option should be used only in rare cases where `cv2`
fails to accurately read the fps. If not specified, it defaults to the fps
of the video as read by `cv2`.
`dimensions` (tuple[int, int] | None):
Specify the dimensions (frame width, frame height) of the gif. Defaults to
the video dimensions if not specified.
`resize` (float):
Resize the dimensions of the gif by a factor of `n`. A value of 0.5
will halve the dimensions. If you specify `dimensions`, `resize` will apply
to the dimensions you specify. Defaults to 1.0 if not specified (no change).
`rotate` (int):
Rotate the gif by `n` degrees. Allowed values: 0, 90, 180 or 270. Defaults
to 0 if not specified (no change).
`speed` (float):
Set the speed of the extracted gif. A value of 0.5 will halve the playback
speed of the gif. Defaults to 1.0 if not specified (no change).
`bounce` (bool):
If True, bounce the extracted gif bommerang-style. Defaults to False if
not specified.
`reverse` (bool):
If True, reverse the extracted gif. Defaults to False if not specified.
`monochrome` (bool):
If True, apply a black-and-white filter to the gif. Defaults to False if
not specified.
Returns:
`Result`:
A Result object containing the result of the extraction process.
Source code in videoxt/api.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |