360video¶
Projection ¶
Bases: Enum
same as https://ffmpeg.org/ffmpeg-filters.html#v360.
make_seam_mask ¶
make_seam_mask(width, height, feather_deg=8.0)
Column mask for feather-blending two hemispheres on an equirectangular canvas: 0 where the front lens (yaw 0) should be used, 255 for the back lens (yaw 180), with a linear ramp of ±feather_deg around the seams at longitude ±90°. Args: width (int): Mask width in pixels (full 360° canvas). height (int): Mask height in pixels. feather_deg (float): Half-width of the blend ramp in degrees. Returns: np.ndarray: uint8 mask of shape (height, width).
Source code in musicalgestures/_360video.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
calibrate_dual_fisheye_fov ¶
calibrate_dual_fisheye_fov(front_file, back_file, time_s=1.0, candidates=None, print_result=False)
Estimate the effective lens field of view of a dual-fisheye pair (e.g. the two .insv files of an Insta360 camera) by projecting one frame of each lens to equirectangular at candidate FOVs and measuring the photometric mismatch in the seam bands at longitude ±90°. Args: front_file (str): Video of the front lens. back_file (str): Video of the back lens. time_s (float): Timestamp of the probe frame. candidates (list): FOVs (degrees) to try. Default 185–205. Returns: float: The FOV with the smallest seam mismatch.
Source code in musicalgestures/_360video.py
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 | |
stitch_dual_fisheye ¶
stitch_dual_fisheye(front_file, back_file, target_name=None, fov=None, feather_deg=8.0, width=None, height=None, crf=21, preset='fast', print_cmd=False)
Stitch a dual-fisheye pair (two single-lens files, e.g. Insta360
_00_/_10_ .insv) into one equirectangular video with a feathered
seam blend. Each lens is projected to equirectangular separately
(back lens at yaw 180) and the two are merged with a soft column mask,
which avoids the hard seams of a plain v360=dfisheye conversion.
Audio is taken from the front-lens file when present.
Also fits Garmin VIRB 360 RAW-mode recordings, which store the two
~200-degree hemispheres as separate files.
Args:
front_file (str): Video of the front lens.
back_file (str): Video of the back lens.
target_name (str): Output path. Defaults to <front>_equirect.mp4.
fov (float): Lens FOV in degrees. None runs
calibrate_dual_fisheye_fov on a probe frame first.
feather_deg (float): Half-width of the seam blend in degrees.
width, height (int): Output size. Defaults to lens height × 2 by
lens height (2:1 equirectangular).
crf (int), preset (str): x264 rate control.
Returns:
str: Path of the stitched video.
Source code in musicalgestures/_360video.py
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 | |
detect_projection ¶
detect_projection(filename)
Guess the projection of a 360 video file. First looks for spherical
metadata (the Spherical Mapping side data that GoPro MAX exports,
Insta360 Studio, Garmin VIRB, and the RICOH THETA app all write to
their equirectangular files), then falls back to the frame geometry:
an exact 2:1 aspect ratio is taken as equirectangular, 1:1 as dual
fisheye stacked in one square frame is NOT assumed (too ambiguous).
Args:
filename (str): Path to the video file.
Returns:
Projection: The detected projection, or None if undetectable.
Source code in musicalgestures/_360video.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
Bases: MgVideo
Class for 360 videos.
Args:
filename (str): Path to the video file.
projection (str, Projection, optional): Projection type. Defaults
to None, which auto-detects via detect_projection (spherical
metadata, .360 extension, or 2:1 equirectangular geometry) and
raises ValueError if nothing can be inferred.
camera (str): Camera type.
Source code in musicalgestures/_360video.py
298 299 300 301 302 303 304 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 | |
anglegram ¶
anglegram(n_bins=360, latitude_weighting=True, title=None, cmap='inferno', target_name=None, overwrite=True, azimuth_convention='ambisonics')
Render the visual anglegram of an equirectangular 360 video: a time x azimuth heat map of visual motion energy, after Guo's ambiviz. Each column of the equirectangular inter-frame difference is collapsed (latitude-weighted mean over image rows) into motion energy at one azimuth, so horizontal position in the scene becomes readable as direction. The y-axis matches the audio anglegram of the sister toolbox ambiscape, making the two directly comparable side by side.
The video is streamed frame by frame (downscaled to n_bins columns
with area interpolation), so memory use is independent of duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_bins
|
int
|
Number of azimuth bins (also the horizontal downscaling target). Defaults to 360 (one-degree bins). |
360
|
latitude_weighting
|
bool
|
Weight image rows by cos(latitude) to compensate the polar oversampling of the equirectangular projection. Defaults to True. |
True
|
title
|
str
|
Optionally add a title to the figure. Defaults to None, which uses "Anglegram (visual motion)". |
None
|
cmap
|
str
|
Matplotlib colormap name. Defaults to 'inferno'. |
'inferno'
|
target_name
|
str
|
Target output name for the figure. Defaults to None (which uses the input filename with the suffix "_anglegram.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames. Defaults to True. |
True
|
azimuth_convention
|
str
|
"ambisonics" (default; +90 = left, matches ambiscape) or "image" (azimuth increases with image x). See the module docstring on why this may need verifying per rig. |
'ambisonics'
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
An MgFigure object referring to the figure and its data
( |
Source code in musicalgestures/_anglegram.py
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 | |
aem_overlay ¶
aem_overlay(aem_file, on='video', n_bins=72, strip_height=0.15, cmap='magma', alpha=0.6, time_bin=1.0, title=None, target_name=None, overwrite=True, azimuth_convention='ambisonics')
Overlay an azimuthal Audio Energy Map (AEM, after Guo's ambiviz) on the
equirectangular video or on the visual anglegram, so where the sound
energy comes from can be read against where the pixels move. The audio
side enters through a file only (see load_aem for the expected CSV/TSV
format, typically exported from ambiscape) — ambiscape is not imported.
With on='video', a translucent heat strip is rendered along the bottom
of every frame: horizontal position is azimuth (aligned with the
equirectangular longitude axis under the chosen convention), color is the
audio energy at that azimuth around that time. With on='anglegram', the
visual anglegram is drawn and the binned AEM is overlaid on the same
time/azimuth axes as translucent filled contours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aem_file
|
str
|
Path to the AEM CSV/TSV file (see |
required |
on
|
str
|
'video' or 'anglegram'. Defaults to 'video'. |
'video'
|
n_bins
|
int
|
Azimuth bins for the AEM grid. Defaults to 72 (5-degree bins — ambisonic localisation is far coarser than pixels). |
72
|
strip_height
|
float
|
Height of the heat strip as a fraction
of the frame height (only for |
0.15
|
cmap
|
str
|
Matplotlib colormap for the audio energy. Defaults to 'magma'. |
'magma'
|
alpha
|
float
|
Maximum opacity of the overlay in [0, 1]. Defaults to 0.6. |
0.6
|
time_bin
|
float
|
Width of the AEM time bins in seconds. Defaults to 1.0 (ambiscape's native rate). |
1.0
|
title
|
str
|
Figure title (only for |
None
|
target_name
|
str
|
Target output name. Defaults to None (input filename + "_aem.mp4" or "_anglegram_aem.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames. Defaults to True. |
True
|
azimuth_convention
|
str
|
"ambisonics" (default) or "image"; must match how the anglegram/video is read. See module docstring. |
'ambisonics'
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
For |
|
MgFigure |
For |
Source code in musicalgestures/_anglegram.py
293 294 295 296 297 298 299 300 301 302 303 304 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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
view ¶
view(yaw=0, pitch=0, roll=0, h_fov=90, v_fov=60, width=None, height=None, target_name=None, print_cmd=False)
Extract a flat (rectilinear/perspective) view in a chosen direction
from the 360 video, via ffmpeg's v360 filter, and return it as a
regular MgVideo — a non-destructive alternative to
convert_projection for running any standard MGT analysis
(motiongrams, optical flow, pose...) on one direction of the scene.
Args:
yaw (float): Viewing direction, degrees, as ffmpeg v360's yaw
rotation (0 = the equirectangular center). Note: v360's sign
convention is not the ambisonic azimuth convention used by
anglegram; verify direction on your own footage.
pitch (float): Vertical viewing direction in degrees.
roll (float): In-plane rotation in degrees.
h_fov, v_fov (float): Horizontal/vertical field of view of the
extracted view in degrees. Defaults to 90 x 60.
width, height (int): Output size. Defaults to source height *
(h_fov/90) by source height * (v_fov/90), rounded to even.
target_name (str): Output path. Defaults to
<input>_view_y<yaw>_p<pitch>.mp4.
print_cmd (bool): Print the ffmpeg command. Defaults to False.
Returns:
MgVideo: The extracted view.
Source code in musicalgestures/_360video.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
from_dual_fisheye
classmethod
¶
from_dual_fisheye(front_file, back_file, camera=None, **stitch_kwargs)
Stitch a dual-fisheye pair (e.g. the _00_/_10_ .insv files of an
Insta360 camera) into an equirectangular video and open it as an
Mg360Video. See stitch_dual_fisheye for the stitching options
(fov=None auto-calibrates the lens FOV on a probe frame).
Source code in musicalgestures/_360video.py
383 384 385 386 387 388 389 390 391 392 393 | |
convert_projection ¶
convert_projection(target_projection, options=None, print_cmd=False, test=False)
Convert the video to a different projection. Args: target_projection (Projection): Target projection. options (Dict[str, str], optional): Options for the conversion. Defaults to None. print_cmd (bool, optional): Print the ffmpeg command. Defaults to False.
Source code in musicalgestures/_360video.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
_parse_projection ¶
_parse_projection(projection)
Parse projection type. Args: projection (str): Projection type.
Source code in musicalgestures/_360video.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |