fix scale to fill

This commit is contained in:
j 2026-01-30 18:43:22 +01:00
commit 3c4119fc77

View file

@ -65,7 +65,8 @@ class KDEnliveProject:
self, root,
width="1920", height="1080",
display_aspect_num="16", display_aspect_den="9",
frame_rate_num="24", frame_rate_den="1"
frame_rate_num="24", frame_rate_den="1",
scale_to_fill=True
):
self._duration = defaultdict(int)
self._counters = defaultdict(int)
@ -74,6 +75,7 @@ class KDEnliveProject:
self._height = int(height)
self._fps = int(frame_rate_num) / int(frame_rate_den)
self.profile = 'atsc_1080p_24'
self.scale_to_fill = scale_to_fill
self._tree = self.get_element("mlt", attrib={
"LC_NUMERIC": "C",
@ -627,20 +629,38 @@ class KDEnliveProject:
idx = self._tree.index(track) - 1
self._tree.insert(idx, chain)
filters_ = []
if track_id == 'V':
filters_.append({
self.get_element("filter", [
["mlt_service", "qtblend"],
["kdenlive_id", "qtblend"],
["rotate_center", "1"],
["rect", "00:00:00.000=0 0 %s %s 1.000000" % (self._width, self.height)],
["rotation", "00:00:00.000=0"],
["compositing", "0"],
["distort", "0"],
["kdenlive:collapsed", "0"],
["disable", "0"],
])
})
if track_id[0] == 'V':
if self.scale_to_fill:
width = self._width
height = self._height
x = 0
y = 0
codec_width = chain.xpath('property[@name="meta.media.0.codec.width"]')
if codec_width:
codec_height = chain.xpath('property[@name="meta.media.0.codec.height"]')
clip_width = int(codec_width[0].text)
clip_height = int(codec_height[0].text)
if clip_width == width and clip_height > height:
y = int((height - clip_height) / 2)
elif clip_width/clip_height < width/height:
target_height = int(clip_height/clip_width * width)
y = int((height - target_height) / 2)
height = target_height
print("scale to fill %s %sx%s" % (path, width, height))
rect = "00:00:00.000=%s %s %s %s 1.000000" % (x, y, width, height)
filters_.append(
self.get_element("filter", [
["mlt_service", "qtblend"],
["kdenlive_id", "qtblend"],
["rotate_center", "1"],
["rect", rect],
["rotation", "00:00:00.000=0"],
["compositing", "0"],
["distort", "0"],
["kdenlive:collapsed", "0"],
["disable", "0"],
])
)
for ft in filters.items():
filters_ += self.get_filter(*ft)