[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4139] trunk/py/scripts/addons/ io_sequencer_edl: split out the EDL parser into its own module.

Campbell Barton ideasman42 at gmail.com
Sat Jan 5 07:10:22 CET 2013


Revision: 4139
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4139
Author:   campbellbarton
Date:     2013-01-05 06:10:14 +0000 (Sat, 05 Jan 2013)
Log Message:
-----------
split out the EDL parser into its own module.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_sequencer_edl/import_edl.py

Added Paths:
-----------
    trunk/py/scripts/addons/io_sequencer_edl/parse_edl.py

Modified: trunk/py/scripts/addons/io_sequencer_edl/import_edl.py
===================================================================
--- trunk/py/scripts/addons/io_sequencer_edl/import_edl.py	2013-01-04 16:37:47 UTC (rev 4138)
+++ trunk/py/scripts/addons/io_sequencer_edl/import_edl.py	2013-01-05 06:10:14 UTC (rev 4139)
@@ -18,567 +18,9 @@
 
 # <pep8 compliant>
 
-
-class TimeCode:
-    """
-    Simple timecode class
-    also supports conversion from other time strings used by EDL
-    """
-    __slots__ = (
-        "fps",
-        "hours",
-        "minutes",
-        "seconds",
-        "frame",
-    )
-
-    def __init__(self, data, fps):
-        self.fps = fps
-        if type(data) == str:
-            self.fromString(data)
-            frame = self.asFrame()
-            self.fromFrame(frame)
-        else:
-            self.fromFrame(data)
-
-    def fromString(self, text):
-        # hh:mm:ss:ff
-        # No dropframe support yet
-
-        if text.lower().endswith("mps"):  # 5.2mps
-            return self.fromFrame(int(float(text[:-3]) * self.fps))
-        elif text.lower().endswith("s"):  # 5.2s
-            return self.fromFrame(int(float(text[:-1]) * self.fps))
-        elif text.isdigit():  # 1234
-            return self.fromFrame(int(text))
-        elif ":" in text:  # hh:mm:ss:ff
-            text = text.replace(";", ":").replace(",", ":").replace(".", ":")
-            text = text.split(":")
-
-            self.hours = int(text[0])
-            self.minutes = int(text[1])
-            self.seconds = int(text[2])
-            self.frame = int(text[3])
-            return self
-        else:
-            print("ERROR: could not convert this into timecode %r" % text)
-            return self
-
-    def fromFrame(self, frame):
-
-        if frame < 0:
-            frame = -frame
-            neg = True
-        else:
-            neg = False
-
-        fpm = 60 * self.fps
-        fph = 60 * fpm
-
-        if frame < fph:
-            self.hours = 0
-        else:
-            self.hours = int(frame / fph)
-            frame = frame % fph
-
-        if frame < fpm:
-            self.minutes = 0
-        else:
-            self.minutes = int(frame / fpm)
-            frame = frame % fpm
-
-        if frame < self.fps:
-            self.seconds = 0
-        else:
-            self.seconds = int(frame / self.fps)
-            frame = frame % self.fps
-
-        self.frame = frame
-
-        if neg:
-            self.frame = -self.frame
-            self.seconds = -self.seconds
-            self.minutes = -self.minutes
-            self.hours = -self.hours
-
-        return self
-
-    def asFrame(self):
-        abs_frame = self.frame
-        abs_frame += self.seconds * self.fps
-        abs_frame += self.minutes * 60 * self.fps
-        abs_frame += self.hours * 60 * 60 * self.fps
-
-        return abs_frame
-
-    def asString(self):
-        self.fromFrame(int(self))
-        return "%.2d:%.2d:%.2d:%.2d" % (self.hours, self.minutes, self.seconds, self.frame)
-
-    def __repr__(self):
-        return self.asString()
-
-    # Numeric stuff, may as well have this
-    def __neg__(self):
-        return TimeCode(-int(self), self.fps)
-
-    def __int__(self):
-        return self.asFrame()
-
-    def __sub__(self, other):
-        return TimeCode(int(self) - int(other), self.fps)
-
-    def __add__(self, other):
-        return TimeCode(int(self) + int(other), self.fps)
-
-    def __mul__(self, other):
-        return TimeCode(int(self) * int(other), self.fps)
-
-    def __div__(self, other):
-        return TimeCode(int(self) // int(other), self.fps)
-
-    def __abs__(self):
-        return TimeCode(abs(int(self)), self.fps)
-
-    def __iadd__(self, other):
-        return self.fromFrame(int(self) + int(other))
-
-    def __imul__(self, other):
-        return self.fromFrame(int(self) * int(other))
-
-    def __idiv__(self, other):
-        return self.fromFrame(int(self) // int(other))
-# end timecode
-
-
-"""Comments
-Comments can appear at the beginning of the EDL file (header) or between the edit lines in the EDL. The first block of comments in the file is defined to be the header comments and they are associated with the EDL as a whole. Subsequent comments in the EDL file are associated with the first edit line that appears after them.
-Edit Entries
-<filename|tag>  <EditMode>  <TransitionType>[num]  [duration]  [srcIn]  [srcOut]  [recIn]  [recOut]
-
-    * <filename|tag>: Filename or tag value. Filename can be for an MPEG file, Image file, or Image file template. Image file templates use the same pattern matching as for command line glob, and can be used to specify images to encode into MPEG. i.e. /usr/data/images/image*.jpg
-    * <EditMode>: 'V' | 'A' | 'VA' | 'B' | 'v' | 'a' | 'va' | 'b' which equals Video, Audio, Video_Audio edits (note B or b can be used in place of VA or va).
-    * <TransitonType>: 'C' | 'D' | 'E' | 'FI' | 'FO' | 'W' | 'c' | 'd' | 'e' | 'fi' | 'fo' | 'w'. which equals Cut, Dissolve, Effect, FadeIn, FadeOut, Wipe.
-    * [num]: if TransitionType = Wipe, then a wipe number must be given. At the moment only wipe 'W0' and 'W1' are supported.
-    * [duration]: if the TransitionType is not equal to Cut, then an effect duration must be given. Duration is in frames.
-    * [srcIn]: Src in. If no srcIn is given, then it defaults to the first frame of the video or the first frame in the image pattern. If srcIn isn't specified, then srcOut, recIn, recOut can't be specified.
-    * [srcOut]: Src out. If no srcOut is given, then it defaults to the last frame of the video - or last image in the image pattern. if srcOut isn't given, then recIn and recOut can't be specified.
-    * [recIn]: Rec in. If no recIn is given, then it is calculated based on its position in the EDL and the length of its input.
-      [recOut]: Rec out. If no recOut is given, then it is calculated based on its position in the EDL and the length of its input. first frame of the video.
-
-For srcIn, srcOut, recIn, recOut, the values can be specified as either timecode, frame number, seconds, or mps seconds. i.e.
-[tcode | fnum | sec | mps], where:
-
-    * tcode : SMPTE timecode in hh:mm:ss:ff
-    * fnum : frame number (the first decodable frame in the video is taken to be frame 0).
-    * sec : seconds with 's' suffix (e.g. 5.2s)
-    * mps : seconds with 'mps' suffix (e.g. 5.2mps). This corresponds to the 'seconds' value displayed by Windows MediaPlayer.
-
-More notes,
-Key
-
-"""
-
-enum = 0
-TRANSITION_UNKNOWN = enum
-TRANSITION_CUT = enum
-enum += 1
-TRANSITION_DISSOLVE = enum
-enum += 1
-TRANSITION_EFFECT = enum
-enum += 1
-TRANSITION_FADEIN = enum
-enum += 1
-TRANSITION_FADEOUT = enum
-enum += 1
-TRANSITION_WIPE = enum
-enum += 1
-TRANSITION_KEY = enum
-enum += 1
-
-TRANSITION_DICT = {
-    "c": TRANSITION_CUT,
-    "d": TRANSITION_DISSOLVE,
-    "e": TRANSITION_EFFECT,
-    "fi": TRANSITION_FADEIN,
-    "fo": TRANSITION_FADEOUT,
-    "w": TRANSITION_WIPE,
-    "k": TRANSITION_KEY,
-    }
-
-enum = 0
-EDIT_UNKNOWN = 1 << enum
-enum += 1
-EDIT_VIDEO = 1 << enum
-enum += 1
-EDIT_AUDIO = 1 << enum
-enum += 1
-EDIT_AUDIO_STEREO = 1 << enum
-enum += 1
-EDIT_VIDEO_AUDIO = 1 << enum
-enum += 1
-
-EDIT_DICT = {
-    "v": EDIT_VIDEO,
-    "a": EDIT_AUDIO,
-    "aa": EDIT_AUDIO_STEREO,
-    "va": EDIT_VIDEO_AUDIO,
-    "b": EDIT_VIDEO_AUDIO,
-    }
-
-
-enum = 0
-WIPE_UNKNOWN = enum
-WIPE_0 = enum
-enum += 1
-WIPE_1 = enum
-enum += 1
-
-enum = 0
-KEY_UNKNOWN = enum
-KEY_BG = enum  # K B
-enum += 1
-KEY_IN = enum  # This is assumed if no second type is set
-enum += 1
-KEY_OUT = enum  # K O
-enum += 1
-
-
-"""
-Most sytems:
-Non-dropframe: 1:00:00:00 - colon in last position
-Dropframe: 1:00:00;00 - semicolon in last position
-PAL/SECAM: 1:00:00:00 - colon in last position
-
-SONY:
-Non-dropframe: 1:00:00.00 - period in last position
-Dropframe: 1:00:00,00 - comma in last position
-PAL/SECAM: 1:00:00.00 - period in last position
-"""
-
-"""
-t = abs(timecode('-124:-12:-43:-22', 25))
-t /= 2
-print t
-"""
-
-
-def editFlagsToText(flag):
-    items = []
-    for item, val in EDIT_DICT.items():
-        if val & flag:
-            items.append(item)
-    return "/".join(items)
-
-
-class EditDecision:
-    __slots__ = (
-        "number",
-        "reel",
-        "transition_duration",
-        "edit_type",
-        "transition_type",
-        "wipe_type",
-        "key_type",
-        "key_fade",
-        "srcIn",
-        "srcOut",
-        "recIn",
-        "recOut",
-        "m2",
-        "filename",
-        "custom_data",
-    )
-
-    def __init__(self, text=None, fps=25):
-        # print text
-        self.number = -1
-        self.reel = ""  # Uniqie name for this 'file' but not filename, when BL signifies black
-        self.transition_duration = 0
-        self.edit_type = EDIT_UNKNOWN
-        self.transition_type = TRANSITION_UNKNOWN
-        self.wipe_type = WIPE_UNKNOWN
-        self.key_type = KEY_UNKNOWN
-        self.key_fade = -1  # true/false
-        self.srcIn = None   # Where on the original field recording the event begins
-        self.srcOut = None  # Where on the original field recording the event ends
-        self.recIn = None   # Beginning of the original event in the edited program
-        self.recOut = None  # End of the original event in the edited program
-        self.m2 = None      # fps set by the m2 command
-        self.filename = ""
-
-        self.custom_data = []  # use for storing any data you want (blender strip for eg)
-
-        if text is not None:
-            self.read(text, fps)
-
-    def __repr__(self):
-        txt = "num: %d, " % self.number
-        txt += "reel: %s, " % self.reel
-        txt += "edit_type: "
-        txt += editFlagsToText(self.edit_type) + ", "
-
-        txt += "trans_type: "
-        for item, val in TRANSITION_DICT.items():
-            if val == self.transition_type:
-                txt += item + ", "
-                break
-
-        txt += "m2: "
-        if self.m2:
-            txt += "%g" % float(self.m2.fps)
-            txt += "\n\t"
-            txt += self.m2.data
-        else:
-            txt += "nil"
-
-        txt += ", "
-        txt += "recIn: " + str(self.recIn) + ", "
-        txt += "recOut: " + str(self.recOut) + ", "
-        txt += "srcIn: " + str(self.srcIn) + ", "
-        txt += "srcOut: " + str(self.srcOut) + ", "
-
-        return txt
-
-    def read(self, line, fps):
-        line = line.split()
-        index = 0
-        self.number = int(line[index])

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list