Visitar URL original
update `list_videos_in_folder` by deruyter92 · Pull Request #3303 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2d41bee
Update `list_video_files_in_folder` only filter explicitly provided f…
deruyter92 May 4, 2026
96e31be
add test for list_videos_in_folder
deruyter92 May 4, 2026
3c63e90
Add deprecation utils: decorator for deprecated functions
deruyter92 May 7, 2026
b92103e
move `list_videos_in_folder` to `collect_video_paths` in auxfun_video…
deruyter92 May 7, 2026
ee4d9b1
export `deeplabcut.collect_video_paths(..)` from auxfun_videos.py
deruyter92 May 8, 2026
2014a59
update `collect_video_paths`: add exclude patterns
deruyter92 May 8, 2026
f6f1ee5
deprecate auxfun `get_list_of_videos` in favor of `collect_video_paths`
deruyter92 May 8, 2026
f6b33d2
add pytest deprecation marker `test_get_list_of_videos`
deruyter92 May 8, 2026
659bf7d
Mark `get_video_list` as deprecated (keep for now for backward compat…
deruyter92 May 8, 2026
983951d
fix test_collect_video_paths: rename keyword -> extensions
deruyter92 May 8, 2026
7d71306
Adjust `extensions` parameter: flexibly coerce str / list / tuple ->…
deruyter92 May 8, 2026
bce0ba9
Merge branch 'main' into jaap/update_list_videos_in_folder
C-Achard May 12, 2026
adadf08
`collect_video_paths`: sort videos if shuffle=False
deruyter92 May 12, 2026
ce8bcf5
update docstring non-recursive directory scanning.
deruyter92 May 12, 2026
75a4d0a
update collect_video_paths: DEFAULT_EXCLUDE_PATTERNS
deruyter92 May 12, 2026
481d3fa
update _coerce_extensions: only "" and None normalize to None
deruyter92 May 12, 2026
8ca9b49
fix instance check in _coerce_video_extensions
deruyter92 May 12, 2026
39557ec
fix pytest: assert alphabetic ordering if shuffle=False
deruyter92 May 12, 2026
39cfd94
fix empty string case in _coerce_extensions
deruyter92 May 12, 2026
77a05dc
Add structured deprecation info and warnings (#3326)
C-Achard May 12, 2026
5610a49
Merge branch 'main' into jaap/update_list_videos_in_folder
C-Achard May 13, 2026
792d35d
guarantee unchanged behavior for deprecated `get_list_of_videos` and …
deruyter92 May 13, 2026
fe38152
add warning if still unsupported extensions encountered
deruyter92 May 13, 2026
69981f1
Consequently adjust `videotype` signatures of collect_video_path callers
deruyter92 May 15, 2026
096973e
refactor collect_video_paths: add warnings, raise for empty sequence.
deruyter92 May 15, 2026
0929e7b
update tests for collect_video_paths
deruyter92 May 15, 2026
996b220
Merge branch 'main' into jaap/update_list_videos_in_folder
MMathisLab May 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deeplabcut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
DownSampleVideo,
ShortenVideo,
check_video_integrity,
collect_video_paths,
)

# -----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion deeplabcut/pose_estimation_pytorch/apis/tracking_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from deeplabcut.pose_estimation_pytorch.apis.videos import VideoIterator
from deeplabcut.pose_estimation_pytorch.task import Task
from deeplabcut.pose_tracking_pytorch import create_triplets_dataset
from deeplabcut.utils.auxfun_videos import collect_video_paths


def build_feature_extraction_runner(
Expand Down Expand Up @@ -240,7 +241,7 @@ def create_tracking_dataset(
modelprefix=modelprefix,
)

videos = utils.list_videos_in_folder(videos, videotype)
videos = collect_video_paths(videos, videotype)
for video_path in videos:
print(f"Loading {video_path}")
video = VideoIterator(video_path, cropping=cropping)
Expand Down
4 changes: 2 additions & 2 deletions deeplabcut/pose_estimation_pytorch/apis/tracklets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from deeplabcut.core.inferenceutils import Assembly
from deeplabcut.pose_estimation_pytorch.apis.utils import (
get_scorer_name,
list_videos_in_folder,
parse_snapshot_index_for_analysis,
)
from deeplabcut.pose_estimation_pytorch.data.dlcloader import DLCLoader
from deeplabcut.utils.auxfun_videos import collect_video_paths


def convert_detections2tracklets(
Expand Down Expand Up @@ -124,7 +124,7 @@ def convert_detections2tracklets(
modelprefix=modelprefix,
)

videos = list_videos_in_folder(videos, videotype)
videos = collect_video_paths(videos, videotype)
if len(videos) == 0:
print(f"No videos were found in {videos}")
return
Expand Down
49 changes: 9 additions & 40 deletions deeplabcut/pose_estimation_pytorch/apis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from __future__ import annotations

import logging
import random
from collections.abc import Callable
from pathlib import Path

Expand Down Expand Up @@ -65,7 +64,9 @@
)
from deeplabcut.pose_estimation_pytorch.task import Task
from deeplabcut.pose_estimation_pytorch.utils import resolve_device
from deeplabcut.utils import auxfun_videos, auxiliaryfunctions
from deeplabcut.utils import auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths
from deeplabcut.utils.deprecation import deprecated


def parse_snapshot_index_for_analysis(
Expand Down Expand Up @@ -293,49 +294,17 @@ def get_scorer_name(
return f"DLC_{name}_{task}{date}shuffle{shuffle}_{snapshot_uid}"


@deprecated(replacement="deeplabcut.collect_video_paths", since="3.0.0")
def list_videos_in_folder(
data_path: str | Path | list[str | Path],
video_type: str | None = None,
shuffle: bool = False,
) -> list[Path]:
"""
Args:
data_path: Path or list of paths to folders containing videos, or individual
video files. Can be a mix of directories and files.
video_type: The type of video to filter for (e.g., "mp4", ".mp4"). If None,
all supported video types are included.
shuffle: Whether to shuffle the order of videos. If False, videos are returned
in sorted order for deterministic behavior.

Returns:
The paths of videos to analyze. Duplicate paths are removed.

Raises:
FileNotFoundError: If any path in data_path does not exist.
"""
if isinstance(data_path, (str, Path)):
data_path = [data_path]

if not video_type:
video_suffixes = {f".{ext.lower()}" for ext in auxfun_videos.SUPPORTED_VIDEOS}
else:
video_suffixes = {f".{video_type.lstrip('.').lower()}"}

videos = []
for path in map(Path, data_path):
if not path.exists():
raise FileNotFoundError(f"Could not find: {path}. Check access rights.")

if path.is_dir():
videos.extend(f for f in path.iterdir() if f.is_file() and f.suffix.lower() in video_suffixes)
elif path.is_file() and path.suffix.lower() in video_suffixes:
videos.append(path)

# Resolve video paths and remove duplicates
unique_videos = list(dict.fromkeys(v.resolve() for v in videos))
if shuffle:
random.shuffle(unique_videos)
return unique_videos
return collect_video_paths(
data_path=data_path,
extensions=video_type or None,
shuffle=shuffle,
)


def ensure_multianimal_df_format(df_predictions: pd.DataFrame) -> pd.DataFrame:
Expand Down
3 changes: 2 additions & 1 deletion deeplabcut/pose_estimation_pytorch/apis/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from deeplabcut.pose_estimation_pytorch.task import Task
from deeplabcut.refine_training_dataset.stitch import stitch_tracklets
from deeplabcut.utils import VideoReader, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths


class VideoIterator(VideoReader):
Expand Down Expand Up @@ -540,7 +541,7 @@ def analyze_videos(
print(f"Using scorer: {dlc_scorer}")

# Reading video and init variables
videos = utils.list_videos_in_folder(videos, videotype, shuffle=in_random_order)
videos = collect_video_paths(videos, videotype, shuffle=in_random_order)
h5_files_created = False # Track if any .h5 files were created

for video in videos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from deeplabcut.pose_estimation_tensorflow.core import predict as single_predict
from deeplabcut.pose_estimation_tensorflow.core import predict_multianimal as predict
from deeplabcut.utils import auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import VideoWriter
from deeplabcut.utils.auxfun_videos import VideoWriter, collect_video_paths

warnings.simplefilter("ignore", category=RuntimeWarning)

Expand Down Expand Up @@ -306,7 +306,7 @@ def video_inference(

sess, inputs, outputs = single_predict.setup_pose_prediction(test_cfg, allow_growth=allow_growth)
DLCscorer = "DLC_" + Path(test_cfg["init_weights"]).stem
videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
videos = collect_video_paths(videos, videotype)

datafiles = []
for video in videos:
Expand Down
7 changes: 4 additions & 3 deletions deeplabcut/pose_estimation_tensorflow/predict_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
)
from deeplabcut.refine_training_dataset.stitch import stitch_tracklets
from deeplabcut.utils import auxfun_models, auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths

####################################################
# Loading data, and defining model folder
Expand Down Expand Up @@ -198,7 +199,7 @@ def create_tracking_dataset(
##################################################
# Looping over videos
##################################################
Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
Videos = collect_video_paths(videos, videotype)
if len(Videos) > 0:
if "multi-animal" in dlc_cfg["dataset_type"]:
for video in Videos:
Expand Down Expand Up @@ -594,7 +595,7 @@ def analyze_videos(
##################################################
# Looping over videos
##################################################
Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype, in_random_order)
Videos = collect_video_paths(videos, videotype, in_random_order)
if len(Videos) > 0:
if "multi-animal" in dlc_cfg["dataset_type"]:
from deeplabcut.pose_estimation_tensorflow.predict_multianimal import (
Expand Down Expand Up @@ -1651,7 +1652,7 @@ def convert_detections2tracklets(
##################################################
# Looping over videos
##################################################
Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
Videos = collect_video_paths(videos, videotype)
if len(Videos) > 0:
for video in Videos:
print("Processing... ", video)
Expand Down
4 changes: 2 additions & 2 deletions deeplabcut/pose_tracking_pytorch/train_dlctransreid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import numpy as np

from deeplabcut.utils import auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths

from .config import cfg
from .datasets import make_dlc_dataloader
Expand Down Expand Up @@ -79,7 +79,7 @@ def train_tracking_transformer(
destfolder=None,
):
npy_list = []
videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
videos = collect_video_paths(videos, videotype)
for video in videos:
videofolder = str(Path(video).parents[0])
if destfolder is None:
Expand Down
3 changes: 2 additions & 1 deletion deeplabcut/post_processing/analyze_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from scipy.spatial import distance

from deeplabcut.utils import auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths


# utility functions
Expand Down Expand Up @@ -261,7 +262,7 @@ def analyzeskeleton(
**kwargs,
)

Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
Videos = collect_video_paths(videos, videotype)
for video in Videos:
print(f"Processing {video}")
if destfolder is None:
Expand Down
3 changes: 2 additions & 1 deletion deeplabcut/post_processing/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from deeplabcut.refine_training_dataset.outlier_frames import FitSARIMAXModel
from deeplabcut.utils import auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths


def columnwise_spline_interp(data, max_gap=0):
Expand Down Expand Up @@ -212,7 +213,7 @@ def filterpredictions(
modelprefix=modelprefix,
**kwargs,
)
Videos = auxiliaryfunctions.get_list_of_videos(video, videotype)
Videos = collect_video_paths(video, videotype)

video_to_filtered_df = {}

Expand Down
4 changes: 2 additions & 2 deletions deeplabcut/refine_training_dataset/outlier_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
frameselectiontools,
visualization,
)
from deeplabcut.utils.auxfun_videos import VideoWriter
from deeplabcut.utils.auxfun_videos import VideoWriter, collect_video_paths


def find_outliers_in_raw_data(
Expand Down Expand Up @@ -402,7 +402,7 @@ def extract_outlier_frames(
**kwargs,
)

Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)
Videos = collect_video_paths(videos, videotype)
if len(Videos) == 0:
print("No suitable videos found in", videos)

Expand Down
4 changes: 2 additions & 2 deletions deeplabcut/refine_training_dataset/stitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
calc_iou,
)
from deeplabcut.utils import auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import VideoWriter
from deeplabcut.utils.auxfun_videos import VideoWriter, collect_video_paths


class Tracklet:
Expand Down Expand Up @@ -1076,7 +1076,7 @@ def stitch_tracklets(
-------
A TrackletStitcher object
"""
vids = deeplabcut.utils.auxiliaryfunctions.get_list_of_videos(videos, videotype)
vids = collect_video_paths(videos, videotype)
if not vids:
print("No video(s) found. Please check your path!")
return
Expand Down
89 changes: 89 additions & 0 deletions deeplabcut/utils/auxfun_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import datetime
import os
import random
import subprocess
import warnings
from collections.abc import Sequence
from pathlib import Path

import cv2
import numpy as np
Expand All @@ -32,6 +35,7 @@

# more videos are in principle covered, as OpenCV is used and allows many formats.
SUPPORTED_VIDEOS = "avi", "mp4", "mov", "mpeg", "mpg", "mpv", "mkv", "flv", "qt", "yuv"
DEFAULT_EXCLUDE_PATTERNS: tuple[str, ...] = "*_labeled.*", "*_full.*"


class VideoReader:
Expand Down Expand Up @@ -643,3 +647,88 @@ def display_help(*args):

plt.close(fig)
return bbox


def 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 mix of both. Directories are
only scanned single level, non-recursively.

Optionally filters paths by extension and excludes patterns. Files and directories are treated differently:
- Files are not filtered by extension by default. Set ``extensions`` if needed, to filter also supplied files.
- Directory contents are filtered by ``SUPPORTED_VIDEOS`` by default. Specify custom ``extensions`` if needed.
- exclude patterns are ALWAYS applied for directory contents and supplied files. Set to `[]` to exclude no patterns.

Args:
data_path: Path or list of paths to folders containing videos, or individual
video files. Can be a mix of directories and files.
extensions: The types of videos to select, by filtering the extension (e.g., ".mp4", ".avi", etc.).
- If set: select all videos with the given extensions. Both for directory contents and supplied files.
- If ``None``, provided files are not filtered, but directory contents are filtered by ``SUPPORTED_VIDEOS``.
- An empty str "" is equivalent to None (for backwards compatibility).
- An empty sequence: select only files without extension.
shuffle: Whether to shuffle the order of videos. If False, videos are returned
in sorted order for deterministic behavior.
Comment thread
deruyter92 marked this conversation as resolved.
Resolved
exclude_patterns: Patterns to exclude from the collection. Defaults to DEFAULT_EXCLUDE_PATTERNS.
Set to an empty sequence e.g. `[]` to exclude no patterns.

Returns:
The paths of videos to analyze. Duplicate paths are removed.

Raises:
FileNotFoundError: If any path in data_path does not exist.
"""
if isinstance(data_path, (str, Path)):
data_path = [data_path]

def _coerce_extensions(extensions: str | Sequence[str] | None) -> set[str] | None:
"""Flexible coercion of extensions to a set of suffixes"""
# NOTE @deruyter92: support legacy API, which mixed strings and iterables.
if isinstance(extensions, (list, tuple, set)):
explicit_suffixes = {f".{e.lstrip('.').lower()}" for e in extensions}
elif isinstance(extensions, str) and not extensions == "":
explicit_suffixes = {f".{extensions.lstrip('.').lower()}"}
else:
explicit_suffixes = None

# Normalize empty string to None
if explicit_suffixes == {""}:
explicit_suffixes = None
return explicit_suffixes

explicit_suffixes = _coerce_extensions(extensions)
implicit_suffixes = {f".{ext.lower()}" for ext in SUPPORTED_VIDEOS}

videos: list[Path] = []
for path in map(Path, data_path):
if not path.exists():
raise FileNotFoundError(f"Could not find: {path}. Check access rights.")

if path.is_dir():
# Discriminate videos from other files; skip excluded patterns (e.g. prior DLC outputs).
allowed = explicit_suffixes if explicit_suffixes else implicit_suffixes
videos.extend(
f
for f in path.iterdir()
Comment thread
deruyter92 marked this conversation as resolved.
Resolved
if f.is_file()
and f.suffix.lower() in allowed
and not any(f.match(pattern) for pattern in exclude_patterns)
)
elif path.is_file():
# Accept all caller-supplied files; ONLY filter extensions if set. ALWAYS filter exclude patterns.
if explicit_suffixes is None or path.suffix.lower() in explicit_suffixes:
if not any(path.match(pattern) for pattern in exclude_patterns):
videos.append(path)

# Resolve video paths and remove duplicates
unique_videos = list(dict.fromkeys(v.resolve() for v in videos))
if shuffle:
random.shuffle(unique_videos)
else:
unique_videos.sort()
return unique_videos
Loading
Loading