tune fcp2srt

This commit is contained in:
j 2021-11-05 09:29:12 +00:00
parent d1c5f301b0
commit 500de3286c

View file

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/python3
from __future__ import division
import lxml import lxml
import lxml.etree import lxml.etree
@ -13,31 +12,42 @@ target = '%s.srt' % os.path.splitext(source)[0]
fps = 25 fps = 25
data = [] data = []
tree = lxml.etree.parse(source) tree = lxml.etree.parse(source)
'''
for g in tree.xpath('//clipitem//effect'):
if g.findall('effectid')[0].text == "GraphicAndType":
print (g.findall('name')[0].text)
'''
for g in tree.xpath('//generatoritem'): for g in tree.xpath('//clipitem'):
if g.findall('name')[0].text != 'Graphic':
continue
#start/end = relative position of the clip in the parent sequence. #start/end = relative position of the clip in the parent sequence.
#in/out indicate the portion of the source media file to reference. #in/out indicate the portion of the source media file to reference.
_in = int(g.findall('in')[0].text) _in = int(g.findall('in')[0].text)
_out = int(g.findall('out')[0].text) _out = int(g.findall('out')[0].text)
_start = int(g.findall('start')[0].text) _start = int(g.findall('start')[0].text)
_end = int(g.findall('end')[0].text) _end = int(g.findall('end')[0].text)
effect = g.findall('effect')
assert len(effect) == 1
for parameter in effect[0].findall('parameter'):
if parameter.findall('parameterid')[0].text == 'str':
value = parameter.findall('value')[0].text
for efilter in g.findall('filter'):
value = None
for effect in efilter.findall('effect'):
if effect.findall('effectid')[0].text == 'GraphicAndType':
value = effect.findall('name')[0].text
if not value:
print(lxml.etree.tostring(effect).decode())
print(value)
if _start == -1 and _end == -1: if _start == -1 and _end == -1:
_start = _in _start = _in
_end = _out _end = _out
if _start == -1: if _start == -1:
_start = 0 _start = 0
#print _in, _out, _start, _end, value if value:
print('i', _in, 'o', _out, '-> s', _start, 'e', _end, 'v', value)
value = '\n'.join([v.strip() for v in value.strip().split('\r')]) value = '\n'.join([v.strip() for v in value.strip().split('\r')])
value = value.replace('\n\n', '<br><br>\n')
data.append({ data.append({
'in': _start/fps, 'out': (_end-1)/fps, 'value': value 'in': _start/fps,
'out': (_end-1)/fps,
'value': value
}) })
with open(target, 'wb') as f:
with open(target, 'w') as f:
f.write(ox.srt.encode(data)) f.write(ox.srt.encode(data))