Cropvideo¶
find_motion_box_ffmpeg ¶
find_motion_box_ffmpeg(filename, motion_box_thresh=0.1, motion_box_margin=12)
Helper function to find the area of motion in a video, using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the video file. |
required |
motion_box_thresh
|
float
|
Pixel threshold to apply to the video before assessing the area of motion. Defaults to 0.1. |
0.1
|
motion_box_margin
|
int
|
Margin (in pixels) to add to the detected motion box. Defaults to 12. |
12
|
Raises:
| Type | Description |
|---|---|
KeyboardInterrupt
|
In case we stop the process manually. |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The width of the motion box. |
|
int |
The height of the motion box. |
|
int |
The X coordinate of the top left corner of the motion box. |
|
int |
The Y coordinate of the top left corner of the motion box. |
Source code in musicalgestures/_cropvideo.py
8 9 10 11 12 13 14 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 | |
crop_box_from_points ¶
crop_box_from_points(points)
Turn the two dragged corners into an ffmpeg crop box.
The corners arrive in the order they were clicked, so either may be the top-left one; the box is normalised here rather than at each call site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list
|
The two (x, y) corners of the drawn rectangle. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[int, int, int, int]
|
(w, h, x, y) — the box width, height, and top-left corner. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than two corners were recorded, i.e. no rectangle was drawn. |
Source code in musicalgestures/_cropvideo.py
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 | |
mg_cropvideo_ffmpeg ¶
mg_cropvideo_ffmpeg(filename, crop_movement='Auto', motion_box_thresh=0.1, motion_box_margin=12, target_name=None, overwrite=True)
Crops the video using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the video file. |
required |
crop_movement
|
str
|
'Auto' finds the bounding box that contains the total motion in the video. Motion threshold is given by motion_box_thresh. 'Manual' opens up a simple GUI that is used to crop the video manually by looking at the first frame. Defaults to 'Auto'. |
'Auto'
|
motion_box_thresh
|
float
|
Only meaningful if |
0.1
|
motion_box_margin
|
int
|
Only meaningful if |
12
|
target_name
|
str
|
The name of the output video. Defaults to None (which assumes that the input filename with the suffix "_crop" should be used). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the cropped video. |
Source code in musicalgestures/_cropvideo.py
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 | |
manual_text_input ¶
manual_text_input()
Helper function for mg_crop_video_ffmpeg when its crop_movement is 'manual', but the environment is in Colab. In this case we can't display the windowed cropping UI, so we ask for the values as a text input.
Returns:
| Name | Type | Description |
|---|---|---|
list |
x, y, w, h for crop_ffmpeg. |
Source code in musicalgestures/_cropvideo.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |