def validate_frames(frames: torch.Tensor | None) -> torch.Tensor | None:
        """Validate the frame indices for a batch.

        Validates that the input frame indices are non-negative integers and converts
        them to the correct shape.

        Args:
            frames (torch.Tensor | None): Input frame indices. Should be either:
                - Shape ``(N,)`` for 1D tensor
                - Shape ``(N,1)`` for 2D tensor

        Returns:
            torch.Tensor | None: Validated frame indices as 1D int64 tensor.

        Raises:
            TypeError: If ``frames`` is not a ``torch.Tensor``.
            ValueError: If frame indices are invalid.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> frame_indices = torch.tensor([[0], [1], [2], [3], [4], [5]])
            >>> validated_indices = VideoBatchValidator.validate_frames(frame_indices)
            >>> print(validated_indices)
            tensor([0, 1, 2, 3, 4, 5])
        """
        if frames is None:
            return None
        if not isinstance(frames, torch.Tensor):
            msg = f"Frames must be a torch.Tensor, got {type(frames)}."
            raise TypeError(msg)
        if frames.ndim == 2 and frames.shape[1] == 1:
            frames = frames.squeeze(1)
        if frames.ndim != 1:
            msg = f"Frames must be a 1D tensor or a 2D tensor with shape (N, 1), got shape {frames.shape}."
            raise ValueError(msg)
        if not torch.all(frames >= 0):
            msg = "All frame indices must be non-negative."
            raise ValueError(msg)
        return frames.to(torch.int64)
Validate the frame indices for a batch.

        Validates that the input frame indices are non-negative integers and converts
        them to the correct shape.

        Args:
            frames (torch.Tensor | None): Input frame indices. Should be either:
                - Shape ``(N,)`` for 1D tensor
                - Shape ``(N,1)`` for 2D tensor

        Returns:
            torch.Tensor | None: Validated frame indices as 1D int64 tensor.

        Raises:
            TypeError: If ``frames`` is not a ``torch.Tensor``.
            ValueError: If frame indices are invalid.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> frame_indices = torch.tensor([[0], [1], [2], [3], [4], [5]])
            >>> validated_indices = VideoBatchValidator.validate_frames(frame_indices)
            >>> print(validated_indices)
            tensor([0, 1, 2, 3, 4, 5])
        
src/anomalib/data/validators/torch/video.py