Skip to content

Design and Implement Rotate, Flip, FlipH, and FlipV Interfaces #8

@Pedrexus

Description

@Pedrexus

Description:

For improved user experience and functionality in our video editing library, we aim to provide users the ability to rotate, flip, and specifically flip their videos horizontally or vertically. This will involve creating a generic flip interface, as well as more intuitive fliph and flipv methods.

Proposed Interfaces:

1. Rotate Method:

def rotate(self, angle, center=None, mode='bilinear', padding_mode='zeros', align_corners=True) -> Video:
    """
    Rotate the tensor anti-clockwise about the center.

    Args:
        angle: The angle through which to rotate. The tensor
          must have a shape of (B), where B is batch size.
        center: The center through which to rotate. The tensor
          must have a shape of (B, 2), where B is batch size and last
          dimension contains cx and cy.
        mode: interpolation mode to calculate output values
          ``'bilinear'`` | ``'nearest'``.
        padding_mode: padding mode for outside grid values
          ``'zeros'`` | ``'border'`` | ``'reflection'``.
        align_corners: interpolation flag.

    Returns:
        The rotated tensor with shape as input.

    Example:
        >>> video = pyclip.Video()
        >>> video.rotate(45)
        pyclip.Video(...)

    Returns:
    - Video: A new video object with the rotated frames.
    """

2. Flip Method:

def flip(self, horizontal: bool = False, vertical: bool = False) -> Video:
    """
    Flip the video tensor based on the specified dimensions.

    Args:
        horizontal: Flag to determine if the video should be flipped horizontally.
        vertical: Flag to determine if the video should be flipped vertically.

    Returns:
        Video: A new video object with the flipped frames.

    Example:
        >>> video = pyclip.Video()
        >>> flipped_horizontally = video.flip(horizontal=True)
        >>> flipped_vertically = video.flip(vertical=True)
        >>> flipped_both = video.flip(horizontal=True, vertical=True)

    Note:
        If both horizontal and vertical flags are set to True, the video will be flipped
        both horizontally and vertically. If both are set to False, the original video 
        is returned.

    Raises:
        ValueError: If both horizontal and vertical flags are not provided or if any other 
                    unexpected arguments are passed.
    """

3. FlipH Method:

def fliph(self) -> Video:
    """
    Flip the video horizontally.

    Returns:
    - Video: A new video object with the horizontally flipped frames.
    """
    return self.flip(horizontal=True)

Usage Example:

flipped_video = video_instance.fliph()  # Flips the video horizontally

4. FlipV Method:

def flipv(self) -> Video:
    """
    Flip the video vertically.

    Returns:
    - Video: A new video object with the vertically flipped frames.
    """
    return self.flip(vertical=True)

Usage Example:

flipped_video = video_instance.flipv()  # Flips the video vertically

Expected Outcome:

  • Users should be able to intuitively flip their videos horizontally with the fliph method and vertically with the flipv method.
  • All rotation and flipping operations should maintain audio synchronization.
  • The generic flip method remains available for users familiar with its interface.

Additional Notes:

  • It's essential to maintain consistency across all flipping operations.
  • Consider optimizations to ensure that flipping operations are efficient and timely.
  • Error handling should be robust, especially if there are dependencies between the different methods.
  • As always, a preview feature can enhance the user experience, letting them visualize changes before finalizing operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions