Be smarter about thumbnails
This commit is contained in:
parent
1a92ded9a1
commit
9e818dab35
1 changed files with 25 additions and 19 deletions
|
@ -89,8 +89,7 @@ def generate_thumbnail_sync(file_item: FileItem):
|
|||
if not success:
|
||||
raise RuntimeError("Failed to query duration")
|
||||
|
||||
# Seek to 1/3 of duration
|
||||
seek_pos = duration // 3
|
||||
def get_sample(seek_pos: int) -> bytes:
|
||||
pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, seek_pos)
|
||||
|
||||
# Start playing to capture frame
|
||||
|
@ -110,10 +109,17 @@ def generate_thumbnail_sync(file_item: FileItem):
|
|||
raise RuntimeError("Failed to map buffer")
|
||||
|
||||
try:
|
||||
thumbnail = bytes(map_info.data)
|
||||
return bytes(map_info.data)
|
||||
finally:
|
||||
buffer.unmap(map_info)
|
||||
|
||||
candidates: list[bytes] = []
|
||||
|
||||
for i in range(3):
|
||||
candidates.append(get_sample(duration // 3 - Gst.SECOND + i * Gst.SECOND))
|
||||
|
||||
thumbnail = max(candidates, key=len)
|
||||
|
||||
def set_thumbnail():
|
||||
file_item.thumbnail.value = thumbnail
|
||||
|
||||
|
|
Loading…
Reference in a new issue