timecodes ¶
Classes:
-
Keyframes–Class representing keyframes, or scenechanges.
-
LWIndex– -
Timecodes–A list of frame durations, together representing a (possibly variable) frame rate.
FrameDur dataclass ¶
A fraction representing the duration of a specific frame.
Methods:
-
to_fraction–Convert the FrameDur to a Fraction that represents the frame duration.
Attributes:
-
denominator(int) –The frame duration's denominator.
-
frame(int) –The frame number.
-
numerator(int) –The frame duration's numerator.
to_fraction ¶
to_fraction() -> Fraction
Convert the FrameDur to a Fraction that represents the frame duration.
Source code in vstools/functions/timecodes.py
53 54 55 56 57 58 | |
Keyframes ¶
Class representing keyframes, or scenechanges.
They follow the convention of signaling the start of the new scene.
Methods:
-
from_clip– -
from_file– -
from_param– -
to_clip– -
to_file– -
unique–Get the keyframes from a clip and write them to a file.
Attributes:
Source code in vstools/functions/timecodes.py
386 387 388 389 390 391 | |
from_clip classmethod ¶
from_clip(
clip: VideoNode,
mode: SceneChangeMode | int = WWXD,
height: int | Literal[False] = 360,
**kwargs: Any
) -> Self
Source code in vstools/functions/timecodes.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
from_file classmethod ¶
Source code in vstools/functions/timecodes.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
from_param classmethod ¶
Source code in vstools/functions/timecodes.py
570 571 572 573 574 575 576 577 578 | |
to_clip ¶
to_clip(
clip: VideoNode,
*,
mode: SceneChangeMode | int = WWXD,
height: int | Literal[False] = 360,
prop_key: str = next(iter(prop_keys)),
scene_idx_prop: bool = False
) -> VideoNode
Source code in vstools/functions/timecodes.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
to_file ¶
to_file(
out: FilePathType,
format: int = V1,
func: FuncExcept | None = None,
header: bool = True,
force: bool = False,
) -> None
Source code in vstools/functions/timecodes.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
unique classmethod ¶
Get the keyframes from a clip and write them to a file.
This method tries to generate a unique filename based on the clip's properties and the key prefix. If a file with that name exists and is not empty, the keyframes are loaded from the file. Otherwise, they are detected from the clip and then written to the file.
Example
When working on a TV series, the episode number can be a convenient key (e.g. "01" for episode 1, "02" for episode 2, etc.):
keyframes = Keyframes.unique(clip, "01")
Parameters:
-
(clip¶VideoNode) –The clip to get keyframes from.
-
(key¶str) –A prefix for the filename.
-
(**kwargs¶Any, default:{}) –Additional keyword arguments passed to vstools.Keyframes.from_file or vstools.Keyframes.from_clip.
Returns:
-
Self–An instance of vstools.Keyframes containing the keyframes.
Source code in vstools/functions/timecodes.py
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 | |
LWIndex dataclass ¶
LWIndex(stream_info: StreamInfo, frame_data: list[Frame], keyframes: Keyframes)
Classes:
-
Frame– -
Regex– -
StreamInfo–
Methods:
Attributes:
-
frame_data(list[Frame]) – -
keyframes(Keyframes) – -
stream_info(StreamInfo) –
Frame ¶
Regex ¶
Attributes:
frame_first class-attribute instance-attribute ¶
frame_first = compile(
"Index=(?P<Index>-?[0-9]+),POS=(?P<POS>-?[0-9]+),PTS=(?P<PTS>-?[0-9]+),DTS=(?P<DTS>-?[0-9]+),EDI=(?P<EDI>-?[0-9]+)"
)
StreamInfo ¶
Bases: NamedTuple
Attributes:
from_file classmethod ¶
from_file(
file: FilePathType,
ref_or_length: int | VideoNode | None = None,
*,
func: FuncExcept | None = None
) -> LWIndex
Source code in vstools/functions/timecodes.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
SceneAverageStats ¶
SceneAverageStats(
clip: VideoNode,
keyframes: Keyframes | str,
prop: str = "SceneStats",
plane: int = 0,
cache_size: int = 5,
)
Bases: SceneBasedDynamicCache
Methods:
Attributes:
-
cache_size– -
clip– -
keyframes– -
prop_keys– -
scene_avgs–
Source code in vstools/functions/timecodes.py
624 625 626 627 628 629 630 631 632 633 634 635 | |
from_clip classmethod ¶
Source code in vstools/functions/timecodes.py
594 595 596 | |
get_clip ¶
get_clip(key: int) -> VideoNode
Source code in vstools/functions/timecodes.py
637 638 | |
get_eval ¶
get_eval() -> VideoNode
Source code in vstools/functions/timecodes.py
591 592 | |
SceneBasedDynamicCache ¶
Bases: DynamicClipsCache[int]
Methods:
Attributes:
-
cache_size– -
clip– -
keyframes–
Source code in vstools/functions/timecodes.py
582 583 584 585 586 | |
from_clip classmethod ¶
Source code in vstools/functions/timecodes.py
594 595 596 | |
get_clip abstractmethod ¶
get_clip(key: int) -> VideoNode
Source code in vstools/functions/timecodes.py
588 589 | |
get_eval ¶
get_eval() -> VideoNode
Source code in vstools/functions/timecodes.py
591 592 | |
Timecodes ¶
A list of frame durations, together representing a (possibly variable) frame rate.
Methods:
-
accumulate_norm_timecodes– -
assume_vfr–Force the given clip to be assumed to be vfr by other applications.
-
from_clip–Get the timecodes from a given clip.
-
from_file– -
normalize_range_timecodes–Convert from normalized ranges to a list of frame duration.
-
separate_norm_timecodes– -
to_file–Write timecodes to a file.
-
to_fractions–Convert to a list of frame lengths, representing the individual framerates.
-
to_normalized_ranges–Convert to a list of normalized frame ranges and their assigned framerate.
Attributes:
-
V1–V1 timecode format, containing a list of frame ranges with associated frame rates. For example:
-
V2–V2 timecode format, containing a timestamp for each frame, including possibly a final timestamp after the last frame
V1 class-attribute instance-attribute ¶
V1 = 1
V1 timecode format, containing a list of frame ranges with associated frame rates. For example:
# timecodes format v1
Assume 23.976023976024
544,548,29.97002997003
721,725,29.97002997003
770,772,17.982017982018
V2 class-attribute instance-attribute ¶
V2 = 2
V2 timecode format, containing a timestamp for each frame, including possibly a final timestamp after the last frame to specify the final frame's duration. For example:
# timecode format v2
0.000000
41.708333
83.416667
125.125000
166.833333
accumulate_norm_timecodes classmethod ¶
accumulate_norm_timecodes(
timecodes: Timecodes | dict[tuple[int, int], Fraction],
) -> tuple[Fraction, dict[Fraction, list[tuple[int, int]]]]
Source code in vstools/functions/timecodes.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
assume_vfr ¶
Force the given clip to be assumed to be vfr by other applications.
Parameters:
-
(clip¶VideoNode) –Clip to process.
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling. This should only be set by VS package developers.
Returns:
-
VideoNode–Clip that should always be assumed to be vfr by other applications.
Source code in vstools/functions/timecodes.py
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 | |
from_clip classmethod ¶
Get the timecodes from a given clip.
Parameters:
-
(clip¶VideoNode) –Clip to gather metrics from.
-
(**kwargs¶Any, default:{}) –Keyword arguments to pass on to
clip_async_render.
Source code in vstools/functions/timecodes.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
from_file classmethod ¶
from_file(
file: FilePathType, ref: VideoNode, /, *, func: FuncExcept | None = None
) -> Self
from_file(
file: FilePathType,
ref_or_length: int | VideoNode,
den: int | None = None,
/,
func: FuncExcept | None = None,
) -> Self
Source code in vstools/functions/timecodes.py
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 260 261 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 | |
normalize_range_timecodes classmethod ¶
normalize_range_timecodes(
timecodes: dict[tuple[int | None, int | None], Fraction],
length: int,
assume: Fraction | None = None,
) -> list[Fraction]
Convert from normalized ranges to a list of frame duration.
Source code in vstools/functions/timecodes.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
separate_norm_timecodes classmethod ¶
separate_norm_timecodes(
timecodes: Timecodes | dict[tuple[int, int], Fraction],
) -> tuple[Fraction, dict[tuple[int, int], Fraction]]
Source code in vstools/functions/timecodes.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
to_file ¶
Write timecodes to a file.
This file should always be muxed into the video container when working with Variable Frame Rate video.
Parameters:
-
(out¶FilePathType) –Path to write the file to.
-
(format¶int, default:V2) –Format to write the file to.
Source code in vstools/functions/timecodes.py
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 354 355 356 357 358 359 360 361 | |
to_fractions ¶
Convert to a list of frame lengths, representing the individual framerates.
Source code in vstools/functions/timecodes.py
104 105 106 107 108 109 | |
to_normalized_ranges ¶
Convert to a list of normalized frame ranges and their assigned framerate.
Source code in vstools/functions/timecodes.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |