makepli.py
字号:
#Make a lavpipe pli file from a simpler input file.#Use python makePLI.py --man for detailed usage.#Assumptions:# All transitions are the same length.# All transitions have the same characteristics.# All input streams have the same characteristics.# Copyright (C) 2002, Bob Matlin <bob.kannon@excite.com>## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You probably received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.import os.pathimport sysimport stringclass Clip: #default values __offsetUnits = 's' __lengthUnits = 's' __framesPerSec = 29.97 #NTSC __lenOrStop = 'length' #determines whether or not the lenOrStop param specifies length or stop time/position def __init__(self,fileName=None, offset=None, lenOrEnd=None): """ The default constructor permits changing default values. fileName - the name of the file; may contain path information offset - the time at which to start playing expressed in specified units; unit default is seconds lenOrStop - the length or the end position of the clip expressed in specified units; unit default is seconds """ if (fileName == None): return noffset = 0 if (Clip.__offsetUnits == 's'): noffset = float(offset) elif (Clip.__offsetUnits == 'f'): noffset = int(offset) nlenOrEnd = 0 if (Clip.__lengthUnits == 's'): nlenOrEnd = float(lenOrEnd) elif (Clip.__lengthUnits == 'f'): nlenOrEnd = int(lenOrEnd) self.fileName = fileName self.offsetTime = self.__getOffsetTime(noffset) self.lengthTime = self.__getLengthTime(nlenOrEnd) framesPerSec = self.__framesPerSec self.offsetFrames = self.__getOffsetFrames(noffset) self.lengthFrames = self.__getLengthFrames(nlenOrEnd) if (self.offsetFrames > 0): self.lastFrame = self.offsetFrames -1 else: self.lastFrame = self.offsetFrames self.clipEnd = self.offsetFrames + self.lengthFrames ##print "fileName: " + self.fileName + ", clipEnd: " + str(self.clipEnd) def setOffsetUnits(self,units): """ units - one of s (seconds) or f (frames) """ Clip.__offsetUnits = units def setLengthUnits(self,units): """ units - one of s (seconds) or f (frames) """ Clip.__lengthUnits = units def setLenOrStopType(self,lenOrStop): """ lenOrStop - either 'length' or 'stop' """ if (lenOrStop != 'length' and lenOrStop != 'stop'): raise "(makePLI.py) Invalid length/stop specifier; must be one of [length,stop]." Clip.__lenOrStopType = lenOrStop def __getOffsetTime(self,offset): """ offset - the clip offset, expressed in specified class default units """ if (Clip.__offsetUnits == 's'): return(offset) elif (Clip.__offsetUnits == 'f'): return(offset/Clip.__framesPerSec) def __getOffsetFrames(self,offset): """ offset - the clip offset, expressed in specified class default units """ if (Clip.__offsetUnits == 's'): return(int(offset * Clip.__framesPerSec)) elif (Clip.__offsetUnits == 'f'): return(offset) def __getLengthTime(self,lenOrEnd): """ lenOrEnd - the length or end of clip, expressed in class default units """ if (Clip.__lengthUnits == 's'): return(lenOrEnd) elif (Clip.__lengthUnits == 'f'): return(lenOrEnd/Clip.__framesPerSec) def __getLengthFrames(self,lenOrEnd): """ lenOrEnd - the length or end of clip, expressed in class default units """ f = 0 if (Clip.__lengthUnits == 's'): f = int(lenOrEnd * Clip.__framesPerSec) elif (Clip.__lengthUnits == 'f'): f = lenOrEnd if (Clip.__lenOrStopType == 'stop'): f = f - self.offsetFrames return(f)class PPLIFile: """ A PPLIFile is the file containing the directives and file list needed to make a pli file. """ def __init__(self): self.__lineNum = 0 def handleLine(self,line): """ Takes action on a line obtained from a ppli file. return - a Clip if the line contained clip data, None otherwise """ self.__lineNum = self.__lineNum + 1 s = line.strip() if (len(s) == 0): return(None) if (s.find('#') == 0): return(None) #comment lines start with '#'; ignore them if (s.find('$') == 0): #this is a clip directive return(self.handleDirective(s)) #else this is a clip a = s.split() if (len(a) != 3): raise Exception("(makePLI.py - definition file line " + str(self.__lineNum) + "): A clip line must look like: fileName offset length.") clip = Clip(a[0],a[1],a[2]) return(clip) def handleDirective(self,line): """ Take an action on a directive line. """ s = line a = s.split() if (a[0] == '$format'): if (len(a) != 3): raise Exception("(makePLI.py - definition file line " + str(self.__lineNum) + "): a $format directive must look like: $format offset:<units> length:<units>") else: clip = Clip() #get the offset units aa = a[1].split(":") if (len(aa) != 2): raise Exception("(makePLI.py - definition file line " + str(self.__lineNum) + "): a $format directive must look like: $format offset:<units> length:<units>") clip.setOffsetUnits(aa[1]) #get the length/stop type and units aa = a[2].split(":") if (len(aa) != 2): raise Exception("(makePLI.py - defnition file line " + str(self.__lineNum) + "): a $format directive must look like: $format offset:<units> length:<units>") try: clip.setLenOrStopType(aa[0]) except: (t,v,tb) = sys.exc_info() msg = "(makePLI.py - definition file line " + str(self.__lineNum) + "): " + str(t) raise msg clip.setLengthUnits(aa[1]) return(None) else: raise Exception("(makePLI.py - definition file line " + str(self.__lineNum) + "): Invalid directive; valid directives: $format.")def getUsage(): s = "\nUsage: python makePLI.py [--help] [--man] --file fileName [--transLen length]\n" s = s + "where 'fileName' is the name of the definition file \n" s = s + "and 'length' is the number of frames in each transition.\n" s = s + "--man prints a detailed usage document;\n" s = s + "--help prints this message.\n" return(s)def getMan(): s = getUsage() s = s + "\nOverview\n\n" s = s + "This program produces an output file that uses the mjpeg tools lavpipe, \n" s = s + "lav2yuv, and transist.flt. It has been used to create the video sequence\n" s = s + "for a video montage. When the output file is processed with lavpipe, the\n" s = s + "result is an avi file containing video only; audio can be added with lavaddwav.\n\n" s = s + "Assumptions:\n" s = s + "\tall transitions are the same length;\n" s = s + "\tall transitions have the same characteristics;\n" s = s + "\tall input streams have the same characteristics.\n\n" s = s + "Process\n\n" s = s + "Given an input definition file (referred to as a ppli file - pre pli), makePLI.py\n" s = s + "will produce an output file (referred to as a pli file; see man lavpipe) suitable\n" s = s + "for submission to lavpipe. The output of lavpipe will be an mjpeg avi file with\n" s = s + "equal transitions between the given video clips.\n\n" st = 1 s = s + str(st) + " Create the definition file\n\n" s = s + "The definition file consists of: directives that control the behavior of makePLI.py;\n" s = s + "clips that specify the video clip sources and order; and comments. Directives \n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -