mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Removed offset math for now
This commit is contained in:
@@ -5,9 +5,6 @@ import sys
|
|||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option('-t','--timecode', dest='convert_times', default=False, action='store_true',
|
parser.add_option('-t','--timecode', dest='convert_times', default=False, action='store_true',
|
||||||
help="Include timecode converted to seconds in output.")
|
help="Include timecode converted to seconds in output.")
|
||||||
parser.add_option('-z','--offset', dest='apply_start_offset', default=False, action='store_true',
|
|
||||||
help='Apply session start offset to converted start and finish timecodes on '
|
|
||||||
'clips and markers. Implies -t.')
|
|
||||||
parser.usage = "ptulsconv [-tz] TEXT_EXPORT.txt"
|
parser.usage = "ptulsconv [-tz] TEXT_EXPORT.txt"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -18,6 +15,4 @@ if __name__ == "__main__":
|
|||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
convert(input_file=args[1],
|
convert(input_file=args[1],
|
||||||
convert_times=(options.convert_times or options.apply_start_offset),
|
convert_times=options.convert_times, output=sys.stdout)
|
||||||
apply_session_start=options.apply_start_offset,
|
|
||||||
output=sys.stdout)
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import ptulsconv
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def convert(input_file, convert_times, apply_session_start, output=sys.stdout):
|
def convert(input_file, convert_times, output=sys.stdout):
|
||||||
parsed = dict()
|
parsed = dict()
|
||||||
with open(input_file, 'r') as file:
|
with open(input_file, 'r') as file:
|
||||||
ast = ptulsconv.protools_text_export_grammar.parse(file.read())
|
ast = ptulsconv.protools_text_export_grammar.parse(file.read())
|
||||||
@@ -11,7 +11,6 @@ def convert(input_file, convert_times, apply_session_start, output=sys.stdout):
|
|||||||
|
|
||||||
if convert_times:
|
if convert_times:
|
||||||
xform = ptulsconv.transformations.TimecodeInterpreter()
|
xform = ptulsconv.transformations.TimecodeInterpreter()
|
||||||
xform.apply_session_start = apply_session_start
|
|
||||||
parsed = xform.transform(parsed)
|
parsed = xform.transform(parsed)
|
||||||
|
|
||||||
json.dump(parsed, output)
|
json.dump(parsed, output)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from timecode import Timecode, TimecodeError
|
from . import broadcast_timecode
|
||||||
|
import math
|
||||||
|
|
||||||
class Transformation:
|
class Transformation:
|
||||||
def transform(self, input_dict) -> dict:
|
def transform(self, input_dict) -> dict:
|
||||||
@@ -13,54 +14,44 @@ class TimecodeInterpreter(Transformation):
|
|||||||
def transform(self, input_dict: dict) -> dict:
|
def transform(self, input_dict: dict) -> dict:
|
||||||
retval = super().transform(input_dict)
|
retval = super().transform(input_dict)
|
||||||
rate = input_dict['header']['timecode_format']
|
rate = input_dict['header']['timecode_format']
|
||||||
start_tc = self.convert_time(input_dict['header']['start_timecode'],
|
start_tc = self.convert_time(input_dict['header']['start_timecode'], rate,
|
||||||
rate, offset=None)
|
drop_frame=input_dict['header']['timecode_drop_frame'])
|
||||||
|
|
||||||
retval['header']['start_timecode_decoded'] = start_tc
|
retval['header']['start_timecode_decoded'] = start_tc
|
||||||
convert_start_tc = None
|
|
||||||
if self.apply_session_start is True:
|
|
||||||
convert_start_tc = Timecode(framerate=input_dict['header']['timecode_format'],
|
|
||||||
start_timecode=input_dict['header']['start_timecode'])
|
|
||||||
|
|
||||||
retval['tracks'] = self.convert_tracks(input_dict['tracks'], timecode_rate=rate,
|
retval['tracks'] = self.convert_tracks(input_dict['tracks'], timecode_rate=rate,
|
||||||
session_start=convert_start_tc)
|
drop_frame=retval['header']['timecode_drop_frame'])
|
||||||
|
|
||||||
|
|
||||||
for marker in retval['markers']:
|
for marker in retval['markers']:
|
||||||
marker['location_decoded'] = self.convert_time(marker['location'], rate,
|
marker['location_decoded'] = self.convert_time(marker['location'], rate,
|
||||||
convert_start_tc)
|
drop_frame=retval['header']['timecode_drop_frame'])
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
def convert_tracks(self, tracks, timecode_rate, session_start):
|
def convert_tracks(self, tracks, timecode_rate, drop_frame):
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
new_clips = []
|
new_clips = []
|
||||||
for clip in track['clips']:
|
for clip in track['clips']:
|
||||||
new_clips.append( self.convert_clip( clip ,
|
new_clips.append( self.convert_clip(clip, drop_frame=drop_frame, timecode_rate= timecode_rate) )
|
||||||
timecode_rate= timecode_rate,
|
|
||||||
session_start=session_start ))
|
|
||||||
|
|
||||||
track['clips'] = new_clips
|
track['clips'] = new_clips
|
||||||
|
|
||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
def convert_clip(self, clip, timecode_rate, session_start):
|
def convert_clip(self, clip, timecode_rate, drop_frame):
|
||||||
time_fields = ['start_time', 'end_time', 'duration', 'timestamp']
|
time_fields = ['start_time', 'end_time', 'duration', 'timestamp']
|
||||||
|
|
||||||
for time_field in time_fields:
|
for time_field in time_fields:
|
||||||
if clip[time_field] is not None:
|
if clip[time_field] is not None:
|
||||||
if time_field == 'duration':
|
clip[time_field + "_decoded"] = self.convert_time(clip[time_field], drop_frame=drop_frame,
|
||||||
clip[time_field + "_decoded"] = self.convert_time(clip[time_field],
|
frame_rate=timecode_rate)
|
||||||
framerate=timecode_rate, offset=None)
|
|
||||||
else:
|
|
||||||
clip[time_field + "_decoded"] = self.convert_time(clip[time_field],
|
|
||||||
framerate=timecode_rate, offset=session_start)
|
|
||||||
|
|
||||||
return clip
|
return clip
|
||||||
|
|
||||||
def convert_time(self, time_string, framerate, offset= None):
|
def convert_time(self, time_string, frame_rate, drop_frame=False):
|
||||||
tc = Timecode(framerate=framerate, start_timecode=time_string)
|
lfps = math.ceil(frame_rate)
|
||||||
if offset is not None:
|
|
||||||
tc = tc - offset
|
|
||||||
|
|
||||||
return dict(frames=tc.frames, framrate= framerate, seconds= (float(tc.frames) / float(tc.framerate)))
|
frame_count = broadcast_timecode.smpte_to_frame_count(time_string, lfps, drop_frame_hint=drop_frame)
|
||||||
|
|
||||||
|
return dict(frame_count=frame_count, logical_fps=lfps, drop_frame=drop_frame)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user