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
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 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 | |
shorten
Shorten the video from start to end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall start. |
required |
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall end. |
required |
|
str
|
String added to the name of the shortened video. Defaults to 'short'. |
'short'
|
|
str
|
Folder the video is saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Number of shorter videos to produce. |
required |
|
str
|
String added to the name of the splits. Defaults to 'split'. |
'split'
|
|
str
|
Folder the video splits are saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
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.
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
int
|
Width of output video. |
256
|
|
int
|
Height of output video. |
256
|
|
int
|
X-axis origin of bounding box for cropping. |
0
|
|
int
|
Y-axis origin of bounding box for cropping. |
0
|
|
str
|
Suffix for output videoname (see example). |
'cropped'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the cropped 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
int
|
Width of output video. |
-1
|
|
int
|
Height of output video. |
200
|
|
str
|
Suffix for output videoname (see example). |
'downsampled'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
|
str
|
Default "No", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle. |
'No'
|
|
float
|
Angle to rotate by in degrees, default 0.0. Negative values rotate counter-clockwise. |
0.0
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the downsampled video. |
Examples:
Linux/MacOs:
deeplabcut.DownSampleVideo("/data/videos/mouse1.avi")
Downsamples the video using default values and saves it in /data/videos as mouse1downsampled.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).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall start. |
'00:00:01'
|
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall end. |
'00:01:00'
|
|
str
|
Suffix for output videoname (see example). |
'short'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the shortened 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 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
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 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 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
float
|
Angle to rotate by in degrees. Negative values rotate counter-clockwise. |
required |
|
str
|
Default "Arbitrary", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle. |
'Arbitrary'
|
|
str
|
Suffix for output videoname (see example). |
'rotated'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the rotated 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