source material might not be in same fps, import with profile

This commit is contained in:
j 2026-01-26 18:34:55 +01:00
commit c47e6a5e15

View file

@ -21,7 +21,7 @@ def get_melt():
cmd = ['xvfb-run', '-a'] + cmd cmd = ['xvfb-run', '-a'] + cmd
return cmd return cmd
def melt_xml(file): def melt_xml(file, profile='atsc_1080p_24'):
out = None out = None
real_path = os.path.realpath(file) real_path = os.path.realpath(file)
if file in _CACHE and isinstance(_CACHE[file], list): if file in _CACHE and isinstance(_CACHE[file], list):
@ -29,7 +29,7 @@ def melt_xml(file):
if os.stat(real_path).st_mtime != ts: if os.stat(real_path).st_mtime != ts:
out = None out = None
if not out: if not out:
cmd = get_melt() + [file, '-consumer', 'xml'] cmd = get_melt() + [file, '-profile', profile, '-consumer', 'xml']
out = subprocess.check_output(cmd).decode() out = subprocess.check_output(cmd).decode()
_CACHE[file] = [os.stat(real_path).st_mtime, out] _CACHE[file] = [os.stat(real_path).st_mtime, out]
return out return out
@ -73,6 +73,7 @@ class KDEnliveProject:
self._width = int(width) self._width = int(width)
self._height = int(height) self._height = int(height)
self._fps = int(frame_rate_num) / int(frame_rate_den) self._fps = int(frame_rate_num) / int(frame_rate_den)
self.profile = 'atsc_1080p_24'
self._tree = self.get_element("mlt", attrib={ self._tree = self.get_element("mlt", attrib={
"LC_NUMERIC": "C", "LC_NUMERIC": "C",
@ -444,7 +445,7 @@ class KDEnliveProject:
return prefix + self.get_counter(prefix) return prefix + self.get_counter(prefix)
def get_chain(self, file, kdenlive_id=None): def get_chain(self, file, kdenlive_id=None):
out = melt_xml(file) out = melt_xml(file, self.profile)
chain = lxml.etree.fromstring(out).xpath('producer')[0] chain = lxml.etree.fromstring(out).xpath('producer')[0]
chain.tag = 'chain' chain.tag = 'chain'
chain.attrib['id'] = self.get_id('chain') chain.attrib['id'] = self.get_id('chain')
@ -597,7 +598,11 @@ class KDEnliveProject:
else: else:
print('!!', track_id) print('!!', track_id)
frames = int(self._fps * clip['duration']) frames = int(round(self._fps * clip['duration']))
if track_id[0] == "V":
if abs(self._fps * clip['duration'] - frames) > 1/48:
delta = abs(self._fps * clip['duration'] - frames) * 24
print("Track alignment issues", self._fps * clip['duration'], frames, clip.get('src', clip), delta)
self._duration[track_id] += frames self._duration[track_id] += frames
if clip.get("blank"): if clip.get("blank"):