From: Gael Le Mignot Date: Wed, 8 Jun 2022 11:27:57 +0000 (+0200) Subject: Workaround for multiple producers issue X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=0e0d5f50b4afce9a4c7ee2d3e1e0130fac92f233;p=telemeta.git Workaround for multiple producers issue --- diff --git a/telemeta/util/kdenlive/session.py b/telemeta/util/kdenlive/session.py index a10a0f10..1b545195 100644 --- a/telemeta/util/kdenlive/session.py +++ b/telemeta/util/kdenlive/session.py @@ -36,6 +36,8 @@ import time from telemeta.util.xmltodict2 import * import json +from collections import defaultdict +import pprint def parse_timecode(value, fps): """ @@ -72,8 +74,11 @@ class KDEnLiveSession(object): def video_entries(self): entries = [] for attr in self.session['children']: - if 'playlist' in attr['name'] and 'children' in attr and not 'main' in attr['attributes']['id']: - for att in attr['children']: + if 'playlist' in attr['name'] and 'children' in attr: + plid = attr['attributes'].get('id', '') + if 'main_bin' in plid: + continue + for att in attr['children']: if 'entry' in att['name'] and att['attributes']['producer'] != 'black' \ and not 'audio' in att['attributes']['producer']: entries.append(att['attributes']) @@ -129,6 +134,30 @@ class KDEnLiveSession(object): except: return text + def get_producer_altids(self): + """ + Get the alternate ids of producers if any + """ + by_names = defaultdict(list) + for attr in self.session['children']: + if 'producer' in attr['name'] and 'children' in attr: + if "id" in attr['attributes']: + entry_id = attr['attributes']['id'] + for att in attr['children']: + name = att['attributes']['name'] + if 'resource' in name and 'cdata' in att: + by_names[att['cdata']].append(entry_id) + + alt_ids = {} + for vals in by_names.values(): + if len(vals) > 1: + vals = set(vals) + for val in vals: + alt_ids[val] = vals + + return alt_ids + + def markers(self, offset=0, from_first_marker=False): """ by default return a dict of markers with timecodes relative to an origin @@ -139,8 +168,13 @@ class KDEnLiveSession(object): """ markers = [] entries = self.entries_video_seconds() + #print("=> Video entries") + #pprint.pprint(entries) title = '' fps = self.get_fps() + alternate_ids = self.get_producer_altids() + #print("=> Alternate ids") + #pprint.pprint(alternate_ids) def add_marker(rel_time, comment): """ @@ -156,14 +190,14 @@ class KDEnLiveSession(object): marker['comment'] = comment markers.append(marker) - def get_reltime(entry_id, marker_time): + def get_reltime(entry_id, marker_time, alt_ids = []): """ Get the relative time of a marker linked to an entry """ rel_time = 0 for entry in entries: - if entry['in'] <= marker_time <= entry['out'] and entry_id == entry['id']: + if entry['in'] <= marker_time <= entry['out'] and (entry_id == entry['id'] or entry['id'] in alt_ids): rel_time = entry['t'] + (marker_time - entry['in']) + offset return rel_time @@ -183,21 +217,28 @@ class KDEnLiveSession(object): rel_time = get_reltime(entry_id, marker_time) if rel_time is not None: add_marker(rel_time, comment) - elif 'producer' in attr['name'] and 'children' in attr: + elif 'producer' in attr['name'] and 'children' in attr: # New v 6.24 file format, markers in producers if "id" in attr['attributes']: entry_id = attr['attributes']['id'] + alt_ids = alternate_ids.get(entry_id, []) for att in attr['children']: name = att['attributes']['name'] if 'markers' in name: items = json.loads(self.fix_text(att['cdata'])) + #print("=> Marker items") + #pprint.pprint(items) for marker in items: marker_time = float(marker['pos'] / fps) - rel_time = get_reltime(entry_id, marker_time) + rel_time = get_reltime(entry_id, marker_time, + alt_ids) if rel_time is not None: add_marker(rel_time, marker['comment']) + #print("=> Markers") + #pprint.pprint(markers) + if markers and from_first_marker: delta = min([ marker['time'] for marker in markers ]) for marker in markers: