12
12
from .pathtools import ensure_tree
13
13
from .pathtools import extract_name
14
14
from .pathtools import metadata_path
15
+ from .progress import Progress
15
16
16
17
17
18
def register_thumbnail (typename ):
@@ -45,7 +46,9 @@ def __init__(self, video, base, skip, output):
45
46
self .thumbnail_dir = self .calc_thumbnail_dir ()
46
47
self .metadata_path = self ._get_metadata_path ()
47
48
self ._perform_skip ()
48
- self .extract_frames ()
49
+
50
+ with Progress ("Extracting frames ..." , "Frames have been extracted" ):
51
+ self .extract_frames ()
49
52
50
53
def _get_metadata_path (self ):
51
54
"""Initiates the name of the thumbnail metadata file."""
@@ -100,12 +103,15 @@ def prepare_frames(self):
100
103
master = Image .new (mode = "RGBA" , size = next (thumbnails ))
101
104
master_path = os .path .join (self .thumbnail_dir , extract_name (self .filepath ) + ".png" )
102
105
103
- for frame , * _ , x , y in thumbnails :
104
- with Image .open (frame ) as image :
105
- image = image .resize ((self .width , self .height ), Image .ANTIALIAS )
106
- master .paste (image , (x , y ))
106
+ with Progress ("Processing frames ..." , "Frames have been merged into one" ) as progress :
107
+ for frame , * _ , x , y in thumbnails :
108
+ progress .update ("Processing '%s'" % frame )
109
+ with Image .open (frame ) as image :
110
+ image = image .resize ((self .width , self .height ), Image .ANTIALIAS )
111
+ master .paste (image , (x , y ))
107
112
108
- master .save (master_path )
113
+ progress .update ("Saving the result '%s'" % master_path )
114
+ master .save (master_path )
109
115
110
116
def generate (self ):
111
117
def format_time (secs ):
@@ -117,12 +123,14 @@ def format_time(secs):
117
123
route = os .path .join (prefix , extract_name (self .filepath ) + ".png" )
118
124
route = pathlib .Path (route ).as_posix ()
119
125
120
- for _ , start , end , x , y in self .thumbnails ():
121
- thumbnail_data = "%s --> %s\n %s#xywh=%d,%d,%d,%d\n \n " % (
122
- format_time (start ), format_time (end ),
123
- route , x , y , self .width , self .height ,
124
- )
125
- metadata .append (thumbnail_data )
126
+ with Progress ("Generating thumbnail metadata ..." , "Thumbnail metadata has been generated" ) as progress :
127
+ for _ , start , end , x , y in self .thumbnails ():
128
+ progress .update ("Generating metadata for '%s'" % route )
129
+ thumbnail_data = "%s --> %s\n %s#xywh=%d,%d,%d,%d\n \n " % (
130
+ format_time (start ), format_time (end ),
131
+ route , x , y , self .width , self .height ,
132
+ )
133
+ metadata .append (thumbnail_data )
126
134
127
135
with open (self .metadata_path , "w" ) as fp :
128
136
fp .writelines (metadata )
0 commit comments