Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- fps = avsp.GetVideoFramerate(index=None)
- filename = avsp.GetFilename(title='Open OGG Chapters',filefilter='Chapter Files (*.txt)|*.txt')
- #avsp.MsgBox("fps: %s\nfilename: %s" % (fps,filename), title='debug')
- def parseOgg(file):
- chapre = re.compile("CHAPTER\d+=(\S+)",re.I)
- timeStrings = []
- chapFile = open(file)
- for line in chapFile:
- timeString = chapre.match(line)
- if timeString != None:
- timeStrings.append(timeString.group(1))
- chapFile.close()
- return timeStrings
- def time2ms(ts):
- t = ts.split(':')
- h = int(t[0]) * 3600000
- m = h + int(t[1]) * 60000
- ms = round(m + float(t[2]) * 1000)
- return ms
- # def ms2frame(ms,fps):
- # rat = re.compile('(\d+)(?:/|:)(\d+)')
- # s = ms / 1000
- # fps = rat.search(fps).groups() if rat.search(fps) else \
- # [re.search('(\d+)',fps).group(0),'1']
- # frame = round((int(fps[0])/int(fps[1])) * s)
- # return frame
- def ms2frame(ms,fps):
- s = ms /1000
- frame = int(round(fps * s))
- return frame
- if filename != '':
- timeStrings=parseOgg(filename)
- #avsp.MsgBox("timeStrings: %s" % ';'.join(timeStrings), title='debug')
- timeCodes = [time2ms(timeString) for timeString in timeStrings]
- #avsp.MsgBox("timeCodes: %s" % ';'.join([str(i) for i in timeCodes]), title='debug')
- frameNumbers = [ms2frame(timeCode,fps) for timeCode in timeCodes]
- for frame in frameNumbers:
- avsp.SetBookmark(frame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement