11import contextlib
2- from asyncio import create_subprocess_exec , gather , wait_for
2+ from asyncio import create_subprocess_exec , gather , sleep , wait_for
33from asyncio .subprocess import PIPE
44from os import path as ospath
55from re import escape
1111from aioshutil import rmtree
1212from PIL import Image
1313
14- from bot import DOWNLOAD_DIR , LOGGER , cpu_no
14+ from bot import DOWNLOAD_DIR , LOGGER , cpu_no , threads , cores
1515
1616from .bot_utils import cmd_exec , sync_to_async
1717from .files_utils import get_mime_type , is_archive , is_archive_split
@@ -131,8 +131,8 @@ async def take_ss(video_file, ss_nb) -> bool:
131131 output = f"{ dirpath } /SS.{ name } _{ i :02} .png"
132132 cmd = [
133133 "taskset" ,
134- "-c" ,
135- f"{ cores } " ,
134+ "-c" ,
135+ f"{ cores } " ,
136136 "xtra" ,
137137 "-hide_banner" ,
138138 "-loglevel" ,
@@ -146,7 +146,7 @@ async def take_ss(video_file, ss_nb) -> bool:
146146 "-frames:v" ,
147147 "1" ,
148148 "-threads" ,
149- f"{ max ( 1 , cpu_no // 2 ) } " ,
149+ f"{ threads } " ,
150150 output ,
151151 ]
152152 cap_time += interval
@@ -176,8 +176,8 @@ async def get_audio_thumbnail(audio_file):
176176 output = ospath .join (output_dir , f"{ time ()} .jpg" )
177177 cmd = [
178178 "taskset" ,
179- "-c" ,
180- f"{ cores } " ,
179+ "-c" ,
180+ f"{ cores } " ,
181181 "xtra" ,
182182 "-hide_banner" ,
183183 "-loglevel" ,
@@ -188,7 +188,7 @@ async def get_audio_thumbnail(audio_file):
188188 "-vcodec" ,
189189 "copy" ,
190190 "-threads" ,
191- f"{ max ( 1 , cpu_no // 2 ) } " ,
191+ f"{ threads } " ,
192192 output ,
193193 ]
194194 try :
@@ -218,8 +218,8 @@ async def get_video_thumbnail(video_file, duration):
218218 duration = duration // 2
219219 cmd = [
220220 "taskset" ,
221- "-c" ,
222- f"{ cores } " ,
221+ "-c" ,
222+ f"{ cores } " ,
223223 "xtra" ,
224224 "-hide_banner" ,
225225 "-loglevel" ,
@@ -264,8 +264,8 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
264264 output = ospath .join (output_dir , f"{ time ()} .jpg" )
265265 cmd = [
266266 "taskset" ,
267- "-c" ,
268- f"{ cores } " ,
267+ "-c" ,
268+ f"{ cores } " ,
269269 "xtra" ,
270270 "-hide_banner" ,
271271 "-loglevel" ,
@@ -283,7 +283,7 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
283283 "-f" ,
284284 "mjpeg" ,
285285 "-threads" ,
286- f"{ max ( 1 , cpu_no // 2 ) } " ,
286+ f"{ threads } " ,
287287 output ,
288288 ]
289289 try :
@@ -388,6 +388,7 @@ async def _ffmpeg_progress(self):
388388 except Exception :
389389 self ._progress_raw = 0
390390 self ._eta_raw = 0
391+
391392
392393 async def ffmpeg_cmds (self , ffmpeg , f_path ):
393394 self .clear ()
@@ -483,8 +484,8 @@ async def convert_video(self, video_file, ext, retry=False):
483484 if retry :
484485 cmd = [
485486 "taskset" ,
486- "-c" ,
487- f"{ cores } " ,
487+ "-c" ,
488+ f"{ cores } " ,
488489 "xtra" ,
489490 "-hide_banner" ,
490491 "-loglevel" ,
@@ -500,7 +501,7 @@ async def convert_video(self, video_file, ext, retry=False):
500501 "-c:a" ,
501502 "aac" ,
502503 "-threads" ,
503- f"{ max ( 1 , cpu_no // 2 ) } " ,
504+ f"{ threads } " ,
504505 output ,
505506 ]
506507 if ext == "mp4" :
@@ -512,8 +513,8 @@ async def convert_video(self, video_file, ext, retry=False):
512513 else :
513514 cmd = [
514515 "taskset" ,
515- "-c" ,
516- f"{ cores } " ,
516+ "-c" ,
517+ f"{ cores } " ,
517518 "xtra" ,
518519 "-hide_banner" ,
519520 "-loglevel" ,
@@ -527,7 +528,7 @@ async def convert_video(self, video_file, ext, retry=False):
527528 "-c" ,
528529 "copy" ,
529530 "-threads" ,
530- f"{ max ( 1 , cpu_no // 2 ) } " ,
531+ f"{ threads } " ,
531532 output ,
532533 ]
533534 if self ._listener .is_cancelled :
@@ -567,8 +568,8 @@ async def convert_audio(self, audio_file, ext):
567568 output = f"{ base_name } .{ ext } "
568569 cmd = [
569570 "taskset" ,
570- "-c" ,
571- f"{ cores } " ,
571+ "-c" ,
572+ f"{ cores } " ,
572573 "xtra" ,
573574 "-hide_banner" ,
574575 "-loglevel" ,
@@ -578,7 +579,7 @@ async def convert_audio(self, audio_file, ext):
578579 "-i" ,
579580 audio_file ,
580581 "-threads" ,
581- f"{ max ( 1 , cpu_no // 2 ) } " ,
582+ f"{ threads } " ,
582583 output ,
583584 ]
584585 if self ._listener .is_cancelled :
@@ -641,8 +642,8 @@ async def sample_video(self, video_file, sample_duration, part_duration):
641642
642643 cmd = [
643644 "taskset" ,
644- "-c" ,
645- f"{ cores } " ,
645+ "-c" ,
646+ f"{ cores } " ,
646647 "xtra" ,
647648 "-hide_banner" ,
648649 "-loglevel" ,
@@ -662,7 +663,7 @@ async def sample_video(self, video_file, sample_duration, part_duration):
662663 "-c:a" ,
663664 "aac" ,
664665 "-threads" ,
665- f"{ max ( 1 , cpu_no // 2 ) } " ,
666+ f"{ threads } " ,
666667 output_file ,
667668 ]
668669
@@ -706,8 +707,8 @@ async def split(self, f_path, file_, parts, split_size):
706707 out_path = f_path .replace (file_ , f"{ base_name } .part{ i :03} { extension } " )
707708 cmd = [
708709 "taskset" ,
709- "-c" ,
710- f"{ cores } " ,
710+ "-c" ,
711+ f"{ cores } " ,
711712 "xtra" ,
712713 "-hide_banner" ,
713714 "-loglevel" ,
@@ -731,7 +732,7 @@ async def split(self, f_path, file_, parts, split_size):
731732 "-c" ,
732733 "copy" ,
733734 "-threads" ,
734- f"{ max ( 1 , cpu_no // 2 ) } " ,
735+ f"{ threads } " ,
735736 out_path ,
736737 ]
737738 if not multi_streams :
0 commit comments