Skip to content

Refactor Analyze Videos tab - #3268

Merged
MMathisLab merged 8 commits into
mainfrom
cy/refactor-analysis-tab
Apr 6, 2026
Merged

Refactor Analyze Videos tab#3268
MMathisLab merged 8 commits into
mainfrom
cy/refactor-analysis-tab

Conversation

@C-Achard

@C-Achard C-Achard commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Scope

  • Adds optional, backward-compatible options to the VideoSelectionWidget to automatically synchronize the file extension dropdown with selected video's filetype
  • Reworks the GUI's workflow to be more robust, fail early on mismatches, make it clearer which options are being used and be robust to multiple video types being selected at once

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

  • VideoSelectionWidget is fully backwards compatible
  • The Analyze videos tab no longer has a filetype dropdown, and its under-the-hood logic has been significantly reworked.
    • Usage is the same, video selection is simplified
    • Actual underlying function calls have not changed, nor has the threading infrastructure

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:

  • The VideoSelectionWidget now 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.
  • The video file dialog can now be restricted to show only files matching the currently selected videotype, improving user safety and reducing accidental selection of unsupported files.

Analysis workflow refactor:

  • Video analysis is now performed in batches grouped by file extension, with each group processed separately. This allows for more accurate handling of different video types and simplifies downstream processing.
  • The logic for collecting analysis options has been moved into a new _collect_options method, which returns an immutable AnalyzeVideosOptions dataclass.

Post-processing improvements:

  • Post-processing steps such as creating detection videos, filtering predictions, and plotting trajectories are now handled per group of videos, ensuring correct application of options and reducing the risk of errors.

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.
@C-Achard
C-Achard requested a review from Copilot March 31, 2026 15:20
@C-Achard C-Achard self-assigned this Mar 31, 2026
@C-Achard C-Achard added enhancement New feature or request GUI issues relating to GUI labels Mar 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) AnalyzeVideosOptions dataclass 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 VideoSelectionWidget with 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.

Comment thread deeplabcut/gui/components.py Outdated
Comment thread deeplabcut/gui/components.py
Comment thread deeplabcut/gui/tabs/analyze_videos.py
Comment thread deeplabcut/gui/tabs/analyze_videos.py
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deeplabcut/gui/tabs/analyze_videos.py Outdated
Comment thread deeplabcut/gui/tabs/analyze_videos.py Outdated
Comment thread deeplabcut/gui/tabs/analyze_videos.py Outdated
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.
@C-Achard
C-Achard marked this pull request as ready for review April 2, 2026 14:33
@C-Achard
C-Achard requested a review from deruyter92 April 2, 2026 14:33
@MMathisLab
MMathisLab merged commit 93e944c into main Apr 6, 2026
18 checks passed
@MMathisLab
MMathisLab deleted the cy/refactor-analysis-tab branch April 6, 2026 16:00
@deruyter92 deruyter92 mentioned this pull request May 21, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request GUI issues relating to GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project trains, evaluates but does not create .h5 file or analyze videos

3 participants