Bases: Extractor
Extractor for track item's tumbnails
Source code in client/ayon_hiero/plugins/publish/extract_thumbnail.py
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 | class ExtractThumbnail(publish.Extractor):
"""
Extractor for track item's tumbnails
"""
label = "Extract Thumbnail"
order = pyblish.api.ExtractorOrder
families = ["plate", "take"]
hosts = ["hiero"]
def process(self, instance):
# create representation data
if "representations" not in instance.data:
instance.data["representations"] = []
staging_dir = self.staging_dir(instance)
self.create_thumbnail(staging_dir, instance)
def create_thumbnail(self, staging_dir, instance):
track_item = instance.data["trackItem"]
track_item_name = track_item.name()
# frames
duration = track_item.sourceDuration()
frame_start = track_item.sourceIn()
self.log.debug(
"__ frame_start: `{}`, duration: `{}`".format(
frame_start, duration))
# get thumbnail frame from the middle
thumb_frame = int(frame_start + (duration / 2))
thumb_file = "{}thumbnail{}{}".format(
track_item_name, thumb_frame, ".png")
thumb_path = os.path.join(staging_dir, thumb_file)
thumbnail = track_item.thumbnail(thumb_frame, "colour").save(
thumb_path,
format='png'
)
self.log.debug(
"__ thumb_path: `{}`, frame: `{}`".format(thumbnail, thumb_frame))
self.log.info("Thumbnail was generated to: {}".format(thumb_path))
thumb_representation = {
'files': thumb_file,
'stagingDir': staging_dir,
'name': "thumbnail",
'thumbnail': True,
'ext': "png"
}
instance.data["representations"].append(
thumb_representation)
|