Analytics & Scene Detection
Hardware-accelerated functions for analyzing video content and detecting scenes.
Video Scene Detection
Detects scene changes in a video using GPU-accelerated I/O.
This implementation replicates the exact semantics of PySceneDetect's ContentDetector (v0.6.7) to produce identical scene cuts, but leverages VPF (GPUVideoStreamer) for drastically faster frame extraction and resizing. It calculates the mean absolute difference between adjacent frames in HSV space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
Path | str
|
Path to the input video file. |
required |
threshold
|
float
|
The threshold for the frame score to trigger a scene cut. Higher values require more visual change to trigger a cut. |
27.0
|
Returns:
| Type | Description |
|---|---|
List[Tuple[_SecondsTime, _SecondsTime]]
|
A list of tuples, where each tuple represents a scene containing |
List[Tuple[_SecondsTime, _SecondsTime]]
|
the start time and end time as |
Source code in src/shorts_maker/utils/scenes.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
Action Profiling (Audio)
Computes an audio-based "action score" on the GPU using memory-efficient batching.
This function analyzes the audio track to identify high-energy moments (action). It calculates a combined score based on Root Mean Square (RMS) energy for volume/loudness and Spectral Flux for sudden changes in frequencies (roughness/impacts). Operations are vectorized and executed on the GPU via PyTorch to handle long videos efficiently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
Path
|
Path to the input video or audio file. |
required |
frame_length
|
int
|
The size of the STFT window and RMS frame (in samples). Higher values give better frequency resolution but worse time resolution. |
2048
|
hop_length
|
int
|
The number of samples between successive frames. Determines the temporal resolution of the output score. |
512
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
A tuple containing: - times (np.ndarray): Array of timestamps (in seconds) corresponding to each audio frame. - score (np.ndarray): Array of normalized, smoothed action scores combining RMS and Spectral Flux. Returns empty arrays if audio loading fails. |
Notes
- Audio is processed in 2-minute chunks to maintain a low RAM/VRAM footprint.
- The final score is a weighted combination: 0.6 * RMS + 0.4 * Spectral Flux.
- Includes GPU-accelerated 1D convolution for smoothing the final score array.
Source code in src/shorts_maker/analysis/audio.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
Action Profiling (Video)
Computes a frame-by-frame video "action score" entirely on the GPU.
Uses the GPUVideoStreamer to read frames directly into VRAM, converts them to grayscale, and calculates the mean absolute pixel difference between consecutive frames to quantify motion/action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
Path
|
Path to the input video file. |
required |
fps
|
int
|
Target framerate for subsampling (reduces computational load). |
6
|
downscale_factor
|
int
|
Factor by which to reduce frame dimensions before computing diffs. |
4
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
A tuple containing: - times (np.ndarray): Array of timestamps (in seconds) for each evaluated frame. - score (np.ndarray): Array of normalized, smoothed action scores. |
Source code in src/shorts_maker/analysis/video.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |