Refactor Analyze Videos tab - #3268
Merged
Merged
Conversation
Introduce optional safeties and helpers to VideoSelectionWidget: add constructor flags sync_videotype_with_selection and strict_videotype_filter (defaults preserve existing behavior). New methods: selected_suffixes, get_effective_videotype, get_files_grouped_by_suffix, _set_videotype_silently and _build_video_filter. update_videos now uses the built filter and can silently infer/update the videotype dropdown when a single-suffix selection is added, logging the inference or warning on mixed suffixes. These changes enable stricter file-dialog filtering and optional automatic videotype synchronization without clearing the current selection.
Introduce AnalyzeVideosOptions dataclass and refactor AnalyzeVideos flow to separate option collection, batching and execution. Collect GUI state in _collect_options, group selected videos by extension via _get_video_batches, and run per-extension processing in _run_pipeline with post-processing in _run_postprocessing_for_group. Preserve multianimal behavior (calibration, tracking, CSV conversion) and sync default_track_method to config before launching the worker. Also add improved logging/error handling, handle dynamic/cropping flags more robustly, and adjust VideoSelectionWidget construction to hide and sync videotype selection.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the DeepLabCut GUI “Analyze Videos” tab to make video-type handling more robust by inferring/grouping selected videos by file extension, and to streamline how analysis/post-processing options are collected and executed.
Changes:
- Added an immutable(ish)
AnalyzeVideosOptionsdataclass and moved GUI option gathering into_collect_options(). - Updated the analysis workflow to batch videos by suffix and run analysis + post-processing per extension group.
- Extended
VideoSelectionWidgetwith optional behaviors to sync the videotype dropdown with selected files and to (optionally) restrict the file dialog filter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
deeplabcut/gui/tabs/analyze_videos.py |
Introduces options dataclass, batches analysis by suffix, and runs post-processing per batch in the worker thread. |
deeplabcut/gui/components.py |
Adds videotype inference/grouping helpers and optional UI safeties (sync dropdown, strict dialog filtering). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add validation to VideoSelectionWidget.set_root_videotype: normalize the provided videotype and check it against the QComboBox items. If the videotype is empty or not present in the combo box, keep the current selection and emit a warning instead of changing state. Only update the widget and root.video_type when the value is valid. This prevents silently setting unsupported or empty videotypes and preserves the existing selection.
Normalize and centralize videotype handling and improve video-selection UX. - Add _normalize_videotype to enforce lowercase, dot-less videotype values and use it across the widget (initial dropdown, silent set, update_videotype, get_effective_videotype). - Add typing hints and small docstring fixes for properties and methods. - Improve file dialog filtering: introduce _all_supported_video_patterns and a refactored _build_video_filter that respects strict_videotype_filter and falls back to showing all supported types when appropriate. - Enhance selected-videos display to show suffix summaries and batch info when multiple suffixes are selected. - Add helper get_files_grouped_by_suffix typing and minor logging/message formatting improvements. These changes make videotype state consistent, avoid accidental leading dots/case issues, produce clearer UI feedback, and build more predictable file-dialog filters.
Tighten and clarify type annotations in AnalyzeVideosOptions: change displayed_bodyparts from list[str] to tuple[str, ...]; specify cropping as tuple[int, int, int, int] | None; and set dynamic_cropping_params to tuple[bool, float, int]. These updates improve static type checking and express intended immutability/structure of these fields.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Convert displayed_bodyparts to a tuple (or empty tuple) when plotting trajectories to ensure an immutable/consistent type is passed downstream. When an exception occurs while analyzing a group of videos, build a single message string, log it with exc_info, and re-raise a RuntimeError (chaining the original exception) so the failure is propagated for higher-level handling.
Add logic to deduplicate video parent directories and convert H5 outputs to CSV once per unique folder. Imports pathlib.Path and adds _get_unique_video_parent_folders to collect resolved parent folders, plus _convert_outputs_to_csv_once_per_folder which logs and calls deeplabcut.analyze_videos_converth5_to_csv(folder, listofvideos=False). The conversion is now invoked from _run_pipeline when options.auto_track and options.save_as_csv to avoid repeated per-video/batch conversions.
MMathisLab
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
This helps in setting up a robust foundation for future changes related to video selection and type inference.
Tested successfully on a mix of mp4/avi videos, analysis runs as expected and results are correct.
Goals
Streamline UX for analyzing videos, making it simpler to run on mixed videos.
Intended to help close #3260, further fixes may be made accordingly
Backward compatibility note
Automated summary
This pull request introduces significant improvements to the video analysis workflow in the DeepLabCut GUI, focusing on more robust handling of video file types, improved batch processing, and cleaner separation of options and logic. Key changes include enhanced video type inference and filtering, a new options dataclass, and a refactored analysis pipeline that processes videos in groups by file extension.
Video selection and file type handling:
VideoSelectionWidgetnow supports optional behaviors for syncing the videotype dropdown with selected files and for stricter filtering of selectable video types. It also provides utilities to infer video types from selected files and to group files by their suffixes.Analysis workflow refactor:
_collect_optionsmethod, which returns an immutableAnalyzeVideosOptionsdataclass.Post-processing improvements: