Auto-CS 2.0

https://sourceforge.net/projects/autocs/

Module CuedSpeech

Class sppasAnnsOnFrames

Description

Move points to match with the framerate of the media

Constructor

View Source
def __init__(self, fps=60.0):
    self.__fps = float(fps)

Public functions

get_fps

Return framerate (float).

View Source
def get_fps(self):
    """Return framerate (float)."""
    return self.__fps

set_fps

Set a new framerate.

Parameters
  • value: (float) A framerate.
View Source
def set_fps(self, value: float):
    """Set a new framerate.

        :param value: (float) A framerate.

        """
    try:
        value = float(value)
    except:
        raise TypeError('Expected a float.')
    if value < 0.0:
        raise ValueError('Invalid framerate. ')
    self.__fps = value

adjust_boundaries

Move boundaries to frames of a video.

Parameters
  • tier: (sppasTier) Tier to be adjusted.
View Source
def adjust_boundaries(self, tier):
    """Move boundaries to frames of a video.

        :param tier: (sppasTier) Tier to be adjusted.

        """
    for ann in tier:
        begin_point = ann.get_lowest_localization()
        end_point = ann.get_highest_localization()
        new_begin = self.adjust_point_boundary(begin_point)
        new_end = self.adjust_point_boundary(end_point)
        ann.set_best_localization(sppasInterval(new_begin, new_end))

adjust_point_boundary

Move a point to a frame of a video.

Put the midpoint either between 2 frames or at the middle of a frame. Set the radius to fully cover 0, 1 or 2 frames.

Parameters
  • tier: (sppasTier) Tier to be adjusted.
View Source
def adjust_point_boundary(self, point):
    """Move a point to a frame of a video.

        Put the midpoint either between 2 frames or at the middle of a frame.
        Set the radius to fully cover 0, 1 or 2 frames.

        :param tier: (sppasTier) Tier to be adjusted.

        """
    frame_duration = 1.0 / self.__fps
    half_frame = frame_duration / 2.0
    quart_frame = frame_duration / 4.0
    nframes = int(point.get_midpoint() / frame_duration)
    s = nframes * frame_duration
    m = s + frame_duration / 2.0
    radius = point.get_radius()
    if s <= point.get_midpoint() < s + quart_frame:
        midpoint = s
        if radius is None or (radius is not None and radius < quart_frame):
            radius = 0.0
        else:
            radius = frame_duration
    elif s + quart_frame <= point.get_midpoint() < m + quart_frame:
        midpoint = m
        if radius is None or (radius is not None and radius < frame_duration):
            radius = half_frame
        else:
            radius = 1.5 * frame_duration
    else:
        midpoint = s + frame_duration
        if radius is None or (radius is not None and radius < quart_frame):
            radius = 0.0
        else:
            radius = frame_duration
    return sppasPoint(midpoint, radius)