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 the frames by the given interval" ):
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,16 @@ 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 ("Preprocessing the frames before merging" ) as progress :
107
+ for frame , * _ , x , y in thumbnails :
108
+ offset = extract_name (frame ).replace ("-" , ":" ).split ("." )[0 ]
109
+ progress .update ("Processing [bold]%s[/bold] frame" % offset )
110
+ with Image .open (frame ) as image :
111
+ image = image .resize ((self .width , self .height ), Image .ANTIALIAS )
112
+ master .paste (image , (x , y ))
107
113
108
- master .save (master_path )
114
+ with Progress ("Saving the result at '%s'" % master_path ):
115
+ master .save (master_path )
109
116
110
117
def generate (self ):
111
118
def format_time (secs ):
@@ -117,12 +124,14 @@ def format_time(secs):
117
124
route = os .path .join (prefix , extract_name (self .filepath ) + ".png" )
118
125
route = pathlib .Path (route ).as_posix ()
119
126
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 )
127
+ with Progress ("Saving thumbnail metadata at '%s'" % self .metadata_path ) as progress :
128
+ for _ , start , end , x , y in self .thumbnails ():
129
+ progress .update ("Generating metadata for '%s'" % route )
130
+ thumbnail_data = "%s --> %s\n %s#xywh=%d,%d,%d,%d\n \n " % (
131
+ format_time (start ), format_time (end ),
132
+ route , x , y , self .width , self .height ,
133
+ )
134
+ metadata .append (thumbnail_data )
126
135
127
136
with open (self .metadata_path , "w" ) as fp :
128
137
fp .writelines (metadata )
0 commit comments