This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Automatically find scene cuts, transitions, and fades in video files.
Problem
You have video files and need to identify scene boundaries for:
Solution
What’s in this recipe:
Detect hard cuts with scene_detect_content()
Find fade transitions with scene_detect_threshold()
Use adaptive detection with scene_detect_adaptive()
Three built-in detection methods handle different transition types using
PySceneDetect.
import pixeltable as pxt# Create a fresh directorypxt.drop_dir('scene_demo', force=True)pxt.create_dir('scene_demo')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘scene_demo’.
<pixeltable.catalog.dir.Dir at 0x13f816bd0>
Load sample videos
# Create a video tablevideos = pxt.create_table( 'scene_demo/videos', {'video': pxt.Video, 'title': pxt.String})# Insert sample videos from S3videos.insert( [ { 'video': 's3://multimedia-commons/data/videos/mp4/ffe/ffb/ffeffbef41bbc269810b2a1a888de.mp4', 'title': 'Sample video 1', } ])
Created table ‘videos’.
Inserting rows into `videos`: 1 rows [00:00, 200.53 rows/s]
Inserted 1 row with 0 errors.
1 row inserted, 3 values computed.
Detect scenes with content-based detection
# Detect scenes using content-based detection (best for hard cuts)videos.add_computed_column( scenes_content=videos.video.scene_detect_content( threshold=27.0, # Lower = more sensitive min_scene_len=15, # Minimum frames between cuts ))# View detected scenesvideos.select(videos.title, videos.scenes_content).collect()