Scene Detection¶
Yukine has its own scene detection system, which is based on PySceneDetect.
With yukine.scene_detect.SceneDetect, you can detect scenes, load scenes from a file including those from Av1an, and handle zones too.
Generating Scenes¶
We will be using the default settings for scene detection, but you can adjust them as needed.Setting scene detection example
sd = SceneDetect(video_path=Path("video.mkv"))
sd.scene_detect()
Simple right?
Now, at this stage you can save the scenes with SceneDetect.save and use them with EncodingMethod.av1an or EncodingMethod.chunked_encoder. However, if you want to do zoning, you’ll need to add them with SceneDetect.add_zones.
Adding zones¶
Adding zones example
sd = SceneDetect(video_path=Path("video.mkv"))
sd.scene_detect()
sd.add_zones(
encode_params="--preset 10 --crf 30",
# zones are optional
zones=[
{
"start_frame": 0, # Must match the start and end frame of a scene.
"end_frame": 100,
"params": "--preset 2 --crf 20",
"encoder": Encoder.svt_av1, # Required even if you don't intend to change the encoder.
# "reset": True, # Only use paramters defined in this zone
# "photon_noise": 10, # Only works in av1an
# "min_scene_len": 15, # Set if you change `min_scene_len` in scene detection
# "extra_splits_len": 240, # Set if you change `max_scene_len` in scene detection
}
],
)
Now we’ve just done scene detection, and added zones, we can save them with SceneDetect.save.
Saving Scenes¶
Saving scenes example
sd = SceneDetect(video_path=Path("video.mkv"))
sd.scene_detect()
# zones are optional
sd.add_zones(
encode_params="--preset 10 --crf 30",
zones=[
{
"start_frame": 0, # Must match the start and end frame of a scene.
"end_frame": 100,
"params": "--preset 2 --crf 20",
"encoder": Encoder.svt_av1, # Required even if you don't intend to change the encoder.
# "reset": True, # Only use paramters defined in this zone
# "photon_noise": 10, # Only works in av1an
# "min_scene_len": 15, # Set if you change `min_scene_len` in scene detection
# "extra_splits_len": 240, # Set if you change `max_scene_len` in scene detection
}
],
)
sd.save(Path("scenes.json"))
Av1an compatibility
Scenes saved before, and after finalising will work with Av1an. So you can use scene_detect.SceneDetect to perform scene detection for av1an and potentially achieve better accuracy.
Loading Scenes¶
You can load scenes with SceneDetect.load, this supports scene.json files generated from Av1an.Loading scenes example
sd = SceneDetect(video_path=Path("video.mkv"))
sd.load(Path("scenes.json"))