|
20 | 20 | from scenedetect.backends.opencv import VideoStreamCv2 |
21 | 21 | from scenedetect.common import FrameTimecode |
22 | 22 | from scenedetect.detectors import AdaptiveDetector, ContentDetector |
23 | | -from scenedetect.scene_manager import SceneManager |
| 23 | +from scenedetect.scene_manager import SceneManager, expand_scenes_to_bounds |
24 | 24 |
|
25 | 25 | TEST_VIDEO_START_FRAMES_ACTUAL = [150, 180, 394] |
26 | 26 |
|
@@ -210,3 +210,54 @@ def test_crop_invalid(): |
210 | 210 | sm.crop = (1, 1, 1) # type: ignore[assignment] |
211 | 211 | with pytest.raises(ValueError): |
212 | 212 | sm.crop = (1, 1, 1, -1) |
| 213 | + |
| 214 | + |
| 215 | +def test_expand_scenes_to_bounds_two_scenes(): |
| 216 | + """Scenes detected inside a sub-window should be extended outward.""" |
| 217 | + fps = 10.0 |
| 218 | + t0 = FrameTimecode(0, fps) |
| 219 | + t130 = FrameTimecode(130, fps) |
| 220 | + t150 = FrameTimecode(150, fps) |
| 221 | + t170 = FrameTimecode(170, fps) |
| 222 | + t300 = FrameTimecode(300, fps) |
| 223 | + |
| 224 | + scenes = [(t130, t150), (t150, t170)] |
| 225 | + expanded = expand_scenes_to_bounds(scenes, start=t0, end=t300) |
| 226 | + |
| 227 | + assert expanded == [(t0, t150), (t150, t300)] |
| 228 | + |
| 229 | + |
| 230 | +def test_expand_scenes_to_bounds_empty(): |
| 231 | + """Empty scene lists pass through unchanged.""" |
| 232 | + fps = 10.0 |
| 233 | + assert expand_scenes_to_bounds([], FrameTimecode(0, fps), FrameTimecode(100, fps)) == [] |
| 234 | + |
| 235 | + |
| 236 | +def test_expand_scenes_to_bounds_single_scene(): |
| 237 | + """A single scene gets both endpoints extended.""" |
| 238 | + fps = 10.0 |
| 239 | + t0 = FrameTimecode(0, fps) |
| 240 | + t130 = FrameTimecode(130, fps) |
| 241 | + t170 = FrameTimecode(170, fps) |
| 242 | + t300 = FrameTimecode(300, fps) |
| 243 | + |
| 244 | + scenes = [(t130, t170)] |
| 245 | + expanded = expand_scenes_to_bounds(scenes, start=t0, end=t300) |
| 246 | + |
| 247 | + assert expanded == [(t0, t300)] |
| 248 | + |
| 249 | + |
| 250 | +def test_expand_scenes_to_bounds_does_not_mutate_input(): |
| 251 | + """The input scene list must not be modified in place.""" |
| 252 | + fps = 10.0 |
| 253 | + t0 = FrameTimecode(0, fps) |
| 254 | + t130 = FrameTimecode(130, fps) |
| 255 | + t150 = FrameTimecode(150, fps) |
| 256 | + t170 = FrameTimecode(170, fps) |
| 257 | + t300 = FrameTimecode(300, fps) |
| 258 | + |
| 259 | + scenes = [(t130, t150), (t150, t170)] |
| 260 | + original = list(scenes) |
| 261 | + expand_scenes_to_bounds(scenes, start=t0, end=t300) |
| 262 | + |
| 263 | + assert scenes == original |
0 commit comments