deeplabcut.utils.auxfun_videos
DeepLabCut2.0 Toolbox (deeplabcut.org) © A. & M. Mathis Labs https://github.com/DeepLabCut/DeepLabCut Please see AUTHORS for contributors.
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS Licensed under GNU Lesser General Public License v3.0
Classes:
| Name | Description |
|---|---|
VideoWriter |
|
Functions:
| Name | Description |
|---|---|
CropVideo |
Auxiliary function to crop a video and output it to the same folder with |
DownSampleVideo |
Auxiliary function to downsample a video and output it to the same folder with |
ShortenVideo |
Auxiliary function to shorten video and output with outsuffix appended. to the |
collect_video_paths |
Collects video paths from a given set of data paths: directories, files, or a mix |
imread |
Read image either with skimage or cv2. |
rotate_video |
Auxiliary function to rotate a video and output it to the same folder with |
VideoWriter
Bases: VideoReader
Methods:
| Name | Description |
|---|---|
shorten |
Shorten the video from start to end. |
split |
Split a video into several shorter ones of equal duration. |
Source code in deeplabcut/utils/auxfun_videos.py
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 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 291 292 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 | |
shorten
Shorten the video from start to end.
Parameter
start: str Time formatted in hours:minutes:seconds, where shortened video shall start.
str
Time formatted in hours:minutes:seconds, where shortened video shall end.
str, optional
String added to the name of the shortened video ('short' by default).
str, optional
Folder the video is saved into (by default, same as the original video)
Returns
str Full path to the shortened video
Source code in deeplabcut/utils/auxfun_videos.py
split
Split a video into several shorter ones of equal duration.
Parameters
n_splits : int Number of shorter videos to produce
str, optional
String added to the name of the splits ('short' by default).
str, optional
Folder the video splits are saved into (by default, same as the original video)
Returns
list Paths of the video splits
Source code in deeplabcut/utils/auxfun_videos.py
CropVideo
CropVideo(vname, width=256, height=256, origin_x=0, origin_y=0, outsuffix='cropped', outpath=None, useGUI=False)
Auxiliary function to crop a video and output it to the same folder with "outsuffix" appended in its name. Width and height will control the new dimensions.
Returns the full path to the downsampled video!
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
Parameter
vname : string A string containing the full path of the video.
int
width of output video
int
height of output video.
origin_x, origin_y: int x- and y- axis origin of bounding box for cropping.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the video)
Examples
Linux/MacOs
deeplabcut.CropVideo('/data/videos/mouse1.avi')
Crops the video using default values and saves it in /data/videos as mouse1cropped.avi
Windows:
=deeplabcut.CropVideo('C:\yourusername\rig-95\Videos\reachingvideo1.avi', ... width=220,height=320,outsuffix='cropped')
Crops the video to a width of 220 and height of 320 starting at the origin (top left) and saves it in C:\yourusername\rig-95\Videos as reachingvideo1cropped.avi
Source code in deeplabcut/utils/auxfun_videos.py
DownSampleVideo
DownSampleVideo(vname, width=-1, height=200, outsuffix='downsampled', outpath=None, rotatecw='No', angle=0.0)
Auxiliary function to downsample a video and output it to the same folder with "outsuffix" appended in its name. Width and height will control the new dimensions. You can also pass only height or width and set the other one to -1, this will keep the aspect ratio identical.
Returns the full path to the downsampled video!
Parameter
vname : string A string containing the full path of the video.
int
width of output video
int
height of output video.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the video)
str
Default "No", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle.
float
Angle to rotate by in degrees, default 0.0. Negative values rotate counter-clockwise
Examples
Linux/MacOs
deeplabcut.DownSampleVideo('/data/videos/mouse1.avi')
Downsamples the video using default values and saves it in /data/videos as mouse1cropped.avi
Windows:
shortenedvideoname=deeplabcut.DownSampleVideo('C:\yourusername\rig-95\Videos\reachingvideo1.avi', ... width=220,height=320,outsuffix='cropped')
Downsamples the video to a width of 220 and height of 320 and saves it in C:\yourusername\rig-95\Videos as reachingvideo1cropped.avi
Source code in deeplabcut/utils/auxfun_videos.py
ShortenVideo
Auxiliary function to shorten video and output with outsuffix appended. to the same folder from start (hours:minutes:seconds) to stop (hours:minutes:seconds).
Returns the full path to the shortened video!
Parameter
videos : string A string containing the full paths of the video.
hours:minutes:seconds
Time formatted in hours:minutes:seconds, where shortened video shall start.
hours:minutes:seconds
Time formatted in hours:minutes:seconds, where shortened video shall end.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the video)
Examples
Linux/MacOs
deeplabcut.ShortenVideo('/data/videos/mouse1.avi')
Extracts (sub)video from 1st second to 1st minutes (default values) and saves it in /data/videos as mouse1short.avi
Windows:
deeplabcut.ShortenVideo('C:\yourusername\rig-95\Videos\reachingvideo1.avi', ... start='00:17:00',stop='00:22:00',outsuffix='brief')
Extracts (sub)video from minute 17 to 22 and and saves it in C:\yourusername\rig-95\Videos as reachingvideo1brief.avi
Source code in deeplabcut/utils/auxfun_videos.py
collect_video_paths
collect_video_paths(
data_path: str | Path | list[str | Path],
extensions: str | Sequence[str] | None = None,
shuffle: bool = False,
exclude_patterns: Sequence[str] = DEFAULT_EXCLUDE_PATTERNS,
) -> list[Path]
Collects video paths from a given set of data paths: directories, files, or a mix of both. Directories are scanned one level deep (non-recursively).
Files and directories are treated differently with respect to extension filtering:
- File paths are accepted as-is when extensions is None; only filtered when
extensions is explicitly set.
- Directory contents are always filtered by extension: by SUPPORTED_VIDEOS when
extensions is None, or by the given value(s) otherwise.
- exclude_patterns are always applied to both files and directory contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | list[str | Path]
|
Path or list of paths to folders containing videos, or individual video files. Can be a mix of directories and files. |
required |
|
str | Sequence[str] | None
|
Controls extension filtering for collected video files.
- |
None
|
|
bool
|
Whether to shuffle the order of videos. If |
False
|
|
Sequence[str]
|
Patterns to exclude from the collection. Defaults to
|
DEFAULT_EXCLUDE_PATTERNS
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The paths of videos to analyze. Duplicate paths are removed. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If any path in |
ValueError
|
If |
Source code in deeplabcut/utils/auxfun_videos.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
imread
Read image either with skimage or cv2.
Returns frame in uint with 3 color channels.
Source code in deeplabcut/utils/auxfun_videos.py
rotate_video
Auxiliary function to rotate a video and output it to the same folder with "outsuffix" appended in its name. Angle is in degrees.
Returns the full path to the rotated video!
Parameter
vname : string A string containing the full path of the video.
float
Angle to rotate by in degrees. Negative values rotate counter-clockwise.
str
Default "Arbitrary", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the video)
Examples
Linux/MacOs
deeplabcut.rotate_video('/data/videos/mouse1.avi',angle=90)
Rotates the video by 90 degrees and saves it in /data/videos as mouse1rotated.avi
Windows:
shortenedvideoname=deeplabcut.rotate_video('C:\yourusername\rig-95\Videos\reachingvideo1.avi', ... angle=180,rotatecw='Yes')
Rotates the video by 180 degrees and saves it in C:\yourusername\rig-95\Videos as reachingvideo1rotated.avi