video_section module
class VideoSection(object): ''' This class depicts a short named segment of video which can have a number of properties. ''' # Properties are key-value pairs. Using properties instead of normal fields # allows adding new properties without altering the class. # STANDARD PROPERTY NAMES VOLUME = "Volume" GRAYSCALE = "Grayscale" DEFAULT_VOLUME = "100" # STANDARD PROPERTY VALUES TRUE = "True" FALSE = "False" # -------- Constructors -------- def __init__(self, section_title, start, end, copy=None): ''' Internal constructor for creating sections produced by split operations. @param section_title: title of this section. @param start: timecode for the first frame of the section. @param end: timecode for the last frame of the section. @param copy: a preset properties object for this section. ''' self.start = start # starting frame timecode self.end = end # ending frame timecode self.section_title = section_title # The title for this section self.track = None if copy == None: self.properties = {} self.properties[VideoSection.VOLUME] = VideoSection.DEFAULT_VOLUME else: self.properties = copy.copy() # -------- Accessors for the VideoSection -------- def set_track(self, track): ''' Sets the video track this section is currently assigned to. @param track: the VideoTrack this section is assigned to. ''' self.track = track # The Track this section belongs to def get_track(self): ''' Gets the video track this section is currently assigned to. @return: the VideoTrack this section is assigned to. ''' return self.track def get_start(self): ''' Returns the TimeCode of the first frame of this VideoSection. @return: timecode of the first frame. ''' return self.start def get_end(self): ''' Returns the TimeCode of the last frame of this VideoSection. @return: timecode of the last frame. ''' return self.end # -------- Methods for altering properties of the VideoSection -------- def set_property(self, property_name, value): ''' Sets the value of a given property. @param property_name: The name of the property to set. @param value: New value for the property. ''' self.properties[property_name] = value def get_property(self, property_name): ''' Gets the value of a given property. @param property_name: Name of the property to be returned. @return: the value of the property. ''' return self.properties.get(property_name, '') def remove_property(self, property_name): ''' Removes a given property completely. @param property_name: Name of the property to remove. ''' if property_name in self.properties: del self.properties[property_name] # -------- Methods for altering the VideoSection -------- def transpose(self, new_start): ''' Changes the starting time of this section. @param new_start: New starting timecode for this section. ''' self.end = self.end.transpose_frames(self.start.calculate_frame_distance(new_start)) self.start = new_start def split(self, when): ''' Splits the section into two parts at the given time. This section becomes the first part of the section. The second part is given as a return value. NOTE: The first part replaces the original section on the video track, and the last part is "taken out". If you want to have it on the track, it has to be separately inserted. NOTE: Splitting affects the sectionName of the split sections. @param when: the beginning of the second part of the split section. @return: the second part of the split section. ''' # check that the splitting point is within this section. if self.start <= when <= self.end: # Split sections get the text split as part of their section title # unless this is a re-split title_end = " (split)" if self.section_title.endswith("(split)"): title_end = "" # Create the end section with the same properties as this one. end_section = VideoSection(self.section_title + title_end, when, self.end, self.properties.copy()) # Set this section to end one frame before the latter section # begins. self.end = when.previous_frame() self.section_title = self.section_title + title_end return end_section else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for splitting a video section out of bounds") def join(self, end_part, name): ''' Joins two sections together to form a new bigger section. The sections must be located back-to-back for the operation to succeed. @param end_part: The section after this section to be joined into this section. @param name: Name for the new "joined" section. ''' # Check that the sections are back-to-back if end_part.start.previous_frame() == self.end: self.end = end_part.end self.section_title = name else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for joining two sections which are not back to back.") def __str__(self): ''' Returns a String representation for this section. The representation contains the name of the section, properties for this section and the timecodes for the first and last frames. @return: a string representation of this section. ''' return "Section : " + self.section_title + "(" + str(self.properties.items())\ + ")\n" + "\t" + str(self.start) + " - " + str(self.end) def get_name(self): ''' Returns the title of this section. @return: the name of the section ''' return self.section_title def equals(self, other): '''Tests if the objects are equal. For legacy support, consider using == instead!!!''' return self == other def __eq__(self, other): ''' Tests if the two objects are equal. Using __eq__ allows us to override the ==-operator. @param other: the object to compare with. @return: True if and only if the items were equal. ''' if isinstance(other, VideoSection): return self.start == other.start\ and self.end == other.end\ and self.section_title == other.section_title\ and self.properties == other.properties return False def __ne__(self, other): return not self == other
Classes
class VideoSection
This class depicts a short named segment of video which can have a number of properties.
class VideoSection(object): ''' This class depicts a short named segment of video which can have a number of properties. ''' # Properties are key-value pairs. Using properties instead of normal fields # allows adding new properties without altering the class. # STANDARD PROPERTY NAMES VOLUME = "Volume" GRAYSCALE = "Grayscale" DEFAULT_VOLUME = "100" # STANDARD PROPERTY VALUES TRUE = "True" FALSE = "False" # -------- Constructors -------- def __init__(self, section_title, start, end, copy=None): ''' Internal constructor for creating sections produced by split operations. @param section_title: title of this section. @param start: timecode for the first frame of the section. @param end: timecode for the last frame of the section. @param copy: a preset properties object for this section. ''' self.start = start # starting frame timecode self.end = end # ending frame timecode self.section_title = section_title # The title for this section self.track = None if copy == None: self.properties = {} self.properties[VideoSection.VOLUME] = VideoSection.DEFAULT_VOLUME else: self.properties = copy.copy() # -------- Accessors for the VideoSection -------- def set_track(self, track): ''' Sets the video track this section is currently assigned to. @param track: the VideoTrack this section is assigned to. ''' self.track = track # The Track this section belongs to def get_track(self): ''' Gets the video track this section is currently assigned to. @return: the VideoTrack this section is assigned to. ''' return self.track def get_start(self): ''' Returns the TimeCode of the first frame of this VideoSection. @return: timecode of the first frame. ''' return self.start def get_end(self): ''' Returns the TimeCode of the last frame of this VideoSection. @return: timecode of the last frame. ''' return self.end # -------- Methods for altering properties of the VideoSection -------- def set_property(self, property_name, value): ''' Sets the value of a given property. @param property_name: The name of the property to set. @param value: New value for the property. ''' self.properties[property_name] = value def get_property(self, property_name): ''' Gets the value of a given property. @param property_name: Name of the property to be returned. @return: the value of the property. ''' return self.properties.get(property_name, '') def remove_property(self, property_name): ''' Removes a given property completely. @param property_name: Name of the property to remove. ''' if property_name in self.properties: del self.properties[property_name] # -------- Methods for altering the VideoSection -------- def transpose(self, new_start): ''' Changes the starting time of this section. @param new_start: New starting timecode for this section. ''' self.end = self.end.transpose_frames(self.start.calculate_frame_distance(new_start)) self.start = new_start def split(self, when): ''' Splits the section into two parts at the given time. This section becomes the first part of the section. The second part is given as a return value. NOTE: The first part replaces the original section on the video track, and the last part is "taken out". If you want to have it on the track, it has to be separately inserted. NOTE: Splitting affects the sectionName of the split sections. @param when: the beginning of the second part of the split section. @return: the second part of the split section. ''' # check that the splitting point is within this section. if self.start <= when <= self.end: # Split sections get the text split as part of their section title # unless this is a re-split title_end = " (split)" if self.section_title.endswith("(split)"): title_end = "" # Create the end section with the same properties as this one. end_section = VideoSection(self.section_title + title_end, when, self.end, self.properties.copy()) # Set this section to end one frame before the latter section # begins. self.end = when.previous_frame() self.section_title = self.section_title + title_end return end_section else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for splitting a video section out of bounds") def join(self, end_part, name): ''' Joins two sections together to form a new bigger section. The sections must be located back-to-back for the operation to succeed. @param end_part: The section after this section to be joined into this section. @param name: Name for the new "joined" section. ''' # Check that the sections are back-to-back if end_part.start.previous_frame() == self.end: self.end = end_part.end self.section_title = name else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for joining two sections which are not back to back.") def __str__(self): ''' Returns a String representation for this section. The representation contains the name of the section, properties for this section and the timecodes for the first and last frames. @return: a string representation of this section. ''' return "Section : " + self.section_title + "(" + str(self.properties.items())\ + ")\n" + "\t" + str(self.start) + " - " + str(self.end) def get_name(self): ''' Returns the title of this section. @return: the name of the section ''' return self.section_title def equals(self, other): '''Tests if the objects are equal. For legacy support, consider using == instead!!!''' return self == other def __eq__(self, other): ''' Tests if the two objects are equal. Using __eq__ allows us to override the ==-operator. @param other: the object to compare with. @return: True if and only if the items were equal. ''' if isinstance(other, VideoSection): return self.start == other.start\ and self.end == other.end\ and self.section_title == other.section_title\ and self.properties == other.properties return False def __ne__(self, other): return not self == other
Ancestors (in MRO)
- VideoSection
- __builtin__.object
Class variables
var DEFAULT_VOLUME
var FALSE
var GRAYSCALE
var TRUE
var VOLUME
Instance variables
var end
var section_title
var start
var track
Methods
def __init__(
self, section_title, start, end, copy=None)
Internal constructor for creating sections produced by split operations.
@param section_title: title of this section.
@param start: timecode for the first frame of the section.
@param end: timecode for the last frame of the section.
@param copy: a preset properties object for this section.
def __init__(self, section_title, start, end, copy=None): ''' Internal constructor for creating sections produced by split operations. @param section_title: title of this section. @param start: timecode for the first frame of the section. @param end: timecode for the last frame of the section. @param copy: a preset properties object for this section. ''' self.start = start # starting frame timecode self.end = end # ending frame timecode self.section_title = section_title # The title for this section self.track = None if copy == None: self.properties = {} self.properties[VideoSection.VOLUME] = VideoSection.DEFAULT_VOLUME else: self.properties = copy.copy()
def equals(
self, other)
Tests if the objects are equal. For legacy support, consider using == instead!!!
def equals(self, other): '''Tests if the objects are equal. For legacy support, consider using == instead!!!''' return self == other
def get_end(
self)
Returns the TimeCode of the last frame of this VideoSection.
@return: timecode of the last frame.
def get_end(self): ''' Returns the TimeCode of the last frame of this VideoSection. @return: timecode of the last frame. ''' return self.end
def get_name(
self)
Returns the title of this section.
@return: the name of the section
def get_name(self): ''' Returns the title of this section. @return: the name of the section ''' return self.section_title
def get_property(
self, property_name)
Gets the value of a given property.
@param property_name: Name of the property to be returned.
@return: the value of the property.
def get_property(self, property_name): ''' Gets the value of a given property. @param property_name: Name of the property to be returned. @return: the value of the property. ''' return self.properties.get(property_name, '')
def get_start(
self)
Returns the TimeCode of the first frame of this VideoSection.
@return: timecode of the first frame.
def get_start(self): ''' Returns the TimeCode of the first frame of this VideoSection. @return: timecode of the first frame. ''' return self.start
def get_track(
self)
Gets the video track this section is currently assigned to.
@return: the VideoTrack this section is assigned to.
def get_track(self): ''' Gets the video track this section is currently assigned to. @return: the VideoTrack this section is assigned to. ''' return self.track
def join(
self, end_part, name)
Joins two sections together to form a new bigger section. The sections must be located back-to-back for the operation to succeed.
@param end_part: The section after this section to be joined into this section.
@param name: Name for the new "joined" section.
def join(self, end_part, name): ''' Joins two sections together to form a new bigger section. The sections must be located back-to-back for the operation to succeed. @param end_part: The section after this section to be joined into this section. @param name: Name for the new "joined" section. ''' # Check that the sections are back-to-back if end_part.start.previous_frame() == self.end: self.end = end_part.end self.section_title = name else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for joining two sections which are not back to back.")
def remove_property(
self, property_name)
Removes a given property completely.
@param property_name: Name of the property to remove.
def remove_property(self, property_name): ''' Removes a given property completely. @param property_name: Name of the property to remove. ''' if property_name in self.properties: del self.properties[property_name]
def set_property(
self, property_name, value)
Sets the value of a given property.
@param property_name: The name of the property to set.
@param value: New value for the property.
def set_property(self, property_name, value): ''' Sets the value of a given property. @param property_name: The name of the property to set. @param value: New value for the property. ''' self.properties[property_name] = value
def set_track(
self, track)
Sets the video track this section is currently assigned to.
@param track: the VideoTrack this section is assigned to.
def set_track(self, track): ''' Sets the video track this section is currently assigned to. @param track: the VideoTrack this section is assigned to. ''' self.track = track # The Track this section belongs to
def split(
self, when)
Splits the section into two parts at the given time. This section becomes the first part of the section. The second part is given as a return value.
NOTE: The first part replaces the original section on the video track, and the last part is "taken out". If you want to have it on the track, it has to be separately inserted.
NOTE: Splitting affects the sectionName of the split sections.
@param when: the beginning of the second part of the split section.
@return: the second part of the split section.
def split(self, when): ''' Splits the section into two parts at the given time. This section becomes the first part of the section. The second part is given as a return value. NOTE: The first part replaces the original section on the video track, and the last part is "taken out". If you want to have it on the track, it has to be separately inserted. NOTE: Splitting affects the sectionName of the split sections. @param when: the beginning of the second part of the split section. @return: the second part of the split section. ''' # check that the splitting point is within this section. if self.start <= when <= self.end: # Split sections get the text split as part of their section title # unless this is a re-split title_end = " (split)" if self.section_title.endswith("(split)"): title_end = "" # Create the end section with the same properties as this one. end_section = VideoSection(self.section_title + title_end, when, self.end, self.properties.copy()) # Set this section to end one frame before the latter section # begins. self.end = when.previous_frame() self.section_title = self.section_title + title_end return end_section else: raise ValueError( "Illegal parameter supplied by an internal method call. Request for splitting a video section out of bounds")
def transpose(
self, new_start)
Changes the starting time of this section.
@param new_start: New starting timecode for this section.
def transpose(self, new_start): ''' Changes the starting time of this section. @param new_start: New starting timecode for this section. ''' self.end = self.end.transpose_frames(self.start.calculate_frame_distance(new_start)) self.start = new_start