1212from .pathtools import ensure_tree
1313from .pathtools import extract_name
1414from .pathtools import metadata_path
15+ from .progress import Progress
1516
1617
1718def register_thumbnail (typename ):
@@ -45,7 +46,9 @@ def __init__(self, video, base, skip, output):
4546 self .thumbnail_dir = self .calc_thumbnail_dir ()
4647 self .metadata_path = self ._get_metadata_path ()
4748 self ._perform_skip ()
48- self .extract_frames ()
49+
50+ with Progress ("Extracting the frames by the given interval" ):
51+ self .extract_frames ()
4952
5053 def _get_metadata_path (self ):
5154 """Initiates the name of the thumbnail metadata file."""
@@ -100,12 +103,16 @@ def prepare_frames(self):
100103 master = Image .new (mode = "RGBA" , size = next (thumbnails ))
101104 master_path = os .path .join (self .thumbnail_dir , extract_name (self .filepath ) + ".png" )
102105
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 ))
107113
108- master .save (master_path )
114+ with Progress ("Saving the result at '%s'" % master_path ):
115+ master .save (master_path )
109116
110117 def generate (self ):
111118 def format_time (secs ):
@@ -117,12 +124,14 @@ def format_time(secs):
117124 route = os .path .join (prefix , extract_name (self .filepath ) + ".png" )
118125 route = pathlib .Path (route ).as_posix ()
119126
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 )
126135
127136 with open (self .metadata_path , "w" ) as fp :
128137 fp .writelines (metadata )
0 commit comments