vsmuxtools.utils.source
SourceFilter
Bases: IntEnum
Filter used to index the source file
Source code in
vsmuxtools/utils/source.py
AUTO
class-attribute
instance-attribute
LSMASH for m2ts regardless of previewing; FFMS2 if previewing, BESTSOURCE otherwise.
BESTSOURCE
class-attribute
instance-attribute
Slow initial indexing but guaranteed accuracy. https://github.com/vapoursynth/bestsource
FFMS2
class-attribute
instance-attribute
Fast, generally good enough. https://github.com/FFMS/ffms2
LSMASH
class-attribute
instance-attribute
Also fast but notably the only thing that isn't affected by a certain m2ts ffmpeg bug.
May be deprecated once a new FFMS2 build is available.
https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works
src_file
src_file(file: PathLike | GlobSearch | Sequence[PathLike], trim: Trim | list[Trim] | None = None, preview_sourcefilter: SourceFilter | None = SourceFilter.FFMS2, sourcefilter: SourceFilter = SourceFilter.BESTSOURCE, idx: Callable[[str], VideoNode] | None = None, **kwargs)
Bases: VSObject
Custom FileInfo kind of thing for convenience
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | GlobSearch | Sequence[PathLike]
|
Either a string based filepath or a Path object |
required |
trim
|
Trim | list[Trim] | None
|
A single trim or ordered list, e.g. [(24, 500), (700, None)]. Ends are exclusive. A negative first start pads frozen frames/silence; later negative starts count from the source end. None ends keep the remainder; 0 is invalid. Ranges apply after concatenating input files. |
None
|
preview_sourcefilter
|
SourceFilter | None
|
Source filter to be used when previewing using vspreview.
|
FFMS2
|
sourcefilter
|
SourceFilter
|
Source filter to be used otherwise. |
BESTSOURCE
|
idx
|
Callable[[str], VideoNode] | None
|
Custom indexer for the input file. Pass a function that takes a string in and returns a vs.VideoNode. |
None
|
Source code in
vsmuxtools/utils/source.py
init
init(bits: int | None = 16, matrix: MatrixLike | None = None, transfer: TransferLike | None = None, primaries: PrimariesLike | None = None, chroma_location: ChromaLocationLike | None = None, color_range: ColorRangeLike | None = None, field_based: FieldBasedLike | None = None, dither_type: DitherType = DitherType.RANDOM) -> vs.VideoNode
Getter that calls vstools.initialize_clip on the src clip for convenience
Source code in
vsmuxtools/utils/source.py
init_cut
init_cut(bits: int | None = 16, matrix: MatrixLike | None = None, transfer: TransferLike | None = None, primaries: PrimariesLike | None = None, chroma_location: ChromaLocationLike | None = None, color_range: ColorRangeLike | None = None, field_based: FieldBasedLike | None = None, dither_type: DitherType = DitherType.RANDOM) -> vs.VideoNode
Getter that calls vstools.initialize_clip on the src_cut clip for convenience
Source code in
vsmuxtools/utils/source.py
get_audio
Indexes the specified audio track from the input file(s).
Source code in
vsmuxtools/utils/source.py
get_audio_trimmed
Applies the source's ordered frame ranges to the indexed audio, padding a negative first start with silence. Requires constant video FPS when trimming. Open ends retain the audio tail; explicit ends use available samples.
Source code in
vsmuxtools/utils/source.py
src
src(filePath: PathLike, preview_sourcefilter: SourceFilter | None = SourceFilter.AUTO, sourcefilter: SourceFilter = SourceFilter.BESTSOURCE, **kwargs: KwargsT) -> vs.VideoNode
Uses lsmas for previewing and bestsource otherwise. Still supports dgi files directly if dgdecodenv is installed to not break existing scripts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path to video or dgi file |
required | |
preview_sourcefilter
|
SourceFilter | None
|
Source filter to be used when previewing using vspreview.
|
AUTO
|
sourcefilter
|
SourceFilter
|
Source filter to be used otherwise. |
BESTSOURCE
|
kwargs
|
KwargsT
|
Other arguments you may or may not wanna pass to the indexer. |
{}
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Video Node |
Source code in
vsmuxtools/utils/source.py
frames_to_samples
frames_to_samples(frame: int | None, sample_rate: AudioNode | int = 48000, fps: VideoNode | Fraction = Fraction(24000, 1001)) -> int
Converts a frame number to a sample number
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int | None
|
The frame number |
required |
sample_rate
|
AudioNode | int
|
Can be a flat number like 48000 (=48 kHz) or an AudioNode to get the sample rate from |
48000
|
fps
|
VideoNode | Fraction
|
Can be a Fraction or a VideoNode to get the fps from |
Fraction(24000, 1001)
|
Returns:
| Type | Description |
|---|---|
int
|
The sample number |
Source code in
vsmuxtools/utils/source.py
generate_svt_av1_keyframes
generate_svt_av1_keyframes(clip: VideoNode, start_frame: int = 0, min_scene_length: int = 129, min_still_scene_length: int = 193, max_scene_length: int = 321) -> list[int]
Run generate_keyframes, and then filter the WWXD keyframe result for SVT-AV1 derived encoders.
A huge contribution to the efficiency of SVT-AV1 derived encoders comes from its referencing system.
SVT-AV1 derived encoders by default have a 32 frame hierarchical structure.
It will first encode frame 0 as a key frame, followed by frame 32 referencing frame 0.
Since later frames will all be referencing these frames, these frames of the lowest temporal layer will be given very good q.
After that, the encoder will continue with frame 16, referencing both frame 0 and frame 32.
And then after frame 16, it'll be frame 8, frame 4, frame 2, frame 1, in this order.
The frames in higher temporal layer will be given a bad q, mostly relying on information in the frame they reference to get a good encoding quality.
It's very efficient to allow SVT-AV1 derived encoders to build a full hierarchical structure like this, with lower level frames being given a good q, and higher level frames relying on referencing and saving bitrate.
For scene detection, the scenes that gives the best efficiency should have a length of (integer * 32) + 1, followed by scenes that has a length of (integer * 16) + 1, and then 8, and then 4, et cetera.
Additionally, since both frame 0 and frame 32 will be given very good q, if there were a real scene change in the middle of this 32 frame structure, it will be handled well because frame 32 will certainly be given a good enough q to encode the new scene. On the other hand, making too much scenecut in scene detection, resulting in a lot of smaller and incomplete hierarchical strctures in each scene is generally a very bad idea. Since WWXD often has the tendency to place way too much scenecuts in challenging sections, the purpose of this function is to filter the result from WWXD and create scenes that has more efficient hierarchical structure as much as possible.
Source code in
vsmuxtools/utils/source.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |