Compare commits

...

2 commits

Author SHA1 Message Date
j
9bd5d12874 fragment stats 2026-01-30 18:45:26 +01:00
j
3c4119fc77 fix scale to fill 2026-01-30 18:45:12 +01:00
2 changed files with 84 additions and 15 deletions

View file

@ -1147,3 +1147,52 @@ def unused_tags():
for tag in sorted(unused_tags):
count = unused_items.filter(data__tags__contains=tag).count()
fd.write("%s (%d unused video clips)\n" % (tag, count))
def fragment_statistics():
import itemlist.models
import item.models
stats = {}
for l in itemlist.models.List.objects.filter(status='featured').order_by('name'):
if l.name.split(' ')[0].isdigit():
fragment_id = l.name.split(' ')[0]
fragment = {
'id': fragment_id,
'name': l.name,
'tags': [],
'anti-tags': [],
'description': l.description
}
for con in l.query['conditions']:
if "conditions" in con:
for sub in con["conditions"]:
if sub['key'] == "tags" and sub['operator'] == '==':
fragment['tags'].append(sub['value'].lower().strip())
elif sub['key'] == "tags" and sub['operator'] == '!=':
fragment['tags'].append(sub['value'].lower().strip())
elif sub['key'] == 'type' and sub['value'] in ('source', ''):
pass
else:
print(l.name, 'unknown sub condition', sub)
elif con.get('key') == "tags" and con['operator'] == '==':
fragment['tags'].append(con['value'].lower().strip())
elif con.get('key') == "tags" and con['operator'] == '!=':
fragment['anti-tags'].append(con['value'].lower().strip())
if fragment_id not in stats:
stats[fragment_id] = {}
for tag in fragment['tags']:
stats[fragment_id][tag] = 0
for item in l.get_items(l.user).all():
item_tags = [t.lower().strip() for t in item.get('tags')]
if set(item_tags) & set(fragment['anti-tags']):
continue
for tag in set(fragment['tags']):
if tag in item_tags:
stats[fragment_id][tag] += 1
with open("/srv/pandora/static/power/fragments.txt", "w") as fd:
for fragment, data in stats.items():
fd.write("%s\n" % fragment)
for tag in sorted(data):
fd.write(" %s: %s\n" % (tag, data[tag]))
return stats

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)