Simple example scriptΒΆ
This is a simple example of how to use Yukine to encode and mux a video.
We will create a Source object, and then use Default option Default option List ListEncode and mux to encode and mux the video.
In this example, we will use one Source object for a single encode.Simple script
from yukine import (
mux,
Encode,
Source,
ImportMethod,
Encoder,
EncodingMethod,
AudioEncoder,
SetAudioTrack,
SetSubtitleTrack,
)
from pathlib import Path
source_file: Path = Path("video.mkv")
vid1 = Source(
video_input=source_file,
importer=ImportMethod.FFMS2, # Use FFMS2 as the importer
av1an_settings="--workers 4", # Set av1an settings
encoder_settings="--preset 2 --crf 30", # Set encoder settings
video_encoder=Encoder.svt_av1, # Use SVT-AV1 as the video encoder (1)
encoding_method=EncodingMethod.av1an, # Use av1an as the encoding method (2)
# Encode all audio tracks from the source file as opus
audio=[#(3)!
SetAudioTrack(
file=source_file,
encoder=AudioEncoder.OPUS,
),
],
# Use all subtitle tracks from the source file
subs=[#(4)!
SetSubtitleTrack(
file=source_file,
),
]
)
Encode(vid1).run()
# Mux the video by providing the Source object
# This uses the files within the temp folder generated by Encode to mux the video
mux(vid1)
Encoder.svt_av1
is the default option. No need to specify it if you want to use it.EncodingMethod.av1an
is the default option. No need to specify it if you want to use it. Multiple audio tracks can be specified.
The order of the tracks in the list will be the order
of the audio tracks in the muxed video.
Multiple subtitle tracks can be specified.
The order of the tracks in the list will be the order
of the subtitle tracks in the muxed video.
Simple script with two Source objects
from yukine import (
mux,
Encode,
Source,
ImportMethod,
Encoder,
EncodingMethod,
AudioEncoder,
SetAudioTrack,
SetSubtitleTrack,
)
from pathlib import Path
source_file: Path = Path("video.mkv")
vid1 = Source(
video_input=source_file,
importer=ImportMethod.FFMS2, # Use FFMS2 as the importer
av1an_settings="--workers 4", # Set av1an settings
encoder_settings="--preset 2 --crf 30", # Set encoder settings
video_encoder=Encoder.svt_av1, # Use SVT-AV1 as the video encoder (1)
encoding_method=EncodingMethod.av1an, # Use av1an as the encoding method (2)
# Encode all audio tracks from the source file as opus
audio=[#(3)!
SetAudioTrack(
file=source_file,
encoder=AudioEncoder.OPUS,
),
],
# Use all subtitle tracks from the source file
subs=[#(4)!
SetSubtitleTrack(
file=source_file,
),
]
)
vid2 = Source(
video_input=source_file,
importer=ImportMethod.FFMS2, # Use FFMS2 as the importer
av1an_settings="--workers 4", # Set av1an settings
encoder_settings="--preset 10 --crf 20", # Set encoder settings
video_encoder=Encoder.svt_av1, # Use SVT-AV1 as the video encoder (5)
encoding_method=EncodingMethod.av1an, # Use av1an as the encoding method (6)
# Encode the first audio track from the source file as opus
audio=[#(7)!
SetAudioTrack(
file=source_file,
track=0,#(8)!
),
],
# Don't include subtitles
)
vids: list[Source] = [vid1, vid2]
for vid in vids:
Encode(vid).run()
# Mux the video by providing the Source object
# This uses the files within the temp folder generated by Encode to mux the video
mux(vid)
Default option
Encoder.svt_av1is the default option. No need to specify it if you want to use it.Default option
EncodingMethod.av1anis the default option. No need to specify it if you want to use it.List
Multiple audio tracks can be specified. The order of the tracks in the list will be the order of the audio tracks in the muxed video.List
Multiple subtitle tracks can be specified. The order of the tracks in the list will be the order of the subtitle tracks in the muxed video.Default option
Encoder.svt_av1is the default option. No need to specify it if you want to use it.Default option
EncodingMethod.av1anis the default option. No need to specify it if you want to use it.List
Multiple audio tracks can be specified. The order of the tracks in the list will be the order of the audio tracks in the muxed video.Selecting a track
0 selects the first track from the file. by default, it is set to -1 which selects all tracks from the file.