1616from .files_utils import get_mime_type , is_archive , is_archive_split
1717from .status_utils import time_to_seconds
1818
19+ threads = max (1 , cpu_no // 2 )
20+ cores = "," .join (str (i ) for i in range (threads ))
21+
1922
2023async def create_thumb (msg , _id = "" ):
2124 if not _id :
@@ -125,6 +128,9 @@ async def take_ss(video_file, ss_nb) -> bool:
125128 for i in range (ss_nb ):
126129 output = f"{ dirpath } /SS.{ name } _{ i :02} .png"
127130 cmd = [
131+ "taskset" ,
132+ "-c" ,
133+ f"{ cores } " ,
128134 "ffmpeg" ,
129135 "-hide_banner" ,
130136 "-loglevel" ,
@@ -138,7 +144,7 @@ async def take_ss(video_file, ss_nb) -> bool:
138144 "-frames:v" ,
139145 "1" ,
140146 "-threads" ,
141- f"{ max ( 1 , cpu_no // 2 ) } " ,
147+ f"{ threads } " ,
142148 output ,
143149 ]
144150 cap_time += interval
@@ -168,6 +174,9 @@ async def get_audio_thumbnail(audio_file):
168174 await makedirs (output_dir , exist_ok = True )
169175 output = ospath .join (output_dir , f"{ time ()} .jpg" )
170176 cmd = [
177+ "taskset" ,
178+ "-c" ,
179+ f"{ cores } " ,
171180 "ffmpeg" ,
172181 "-hide_banner" ,
173182 "-loglevel" ,
@@ -178,7 +187,7 @@ async def get_audio_thumbnail(audio_file):
178187 "-vcodec" ,
179188 "copy" ,
180189 "-threads" ,
181- f"{ max ( 1 , cpu_no // 2 ) } " ,
190+ f"{ threads } " ,
182191 output ,
183192 ]
184193 try :
@@ -206,6 +215,9 @@ async def get_video_thumbnail(video_file, duration):
206215 duration = 3
207216 duration = duration // 2
208217 cmd = [
218+ "taskset" ,
219+ "-c" ,
220+ f"{ cores } " ,
209221 "ffmpeg" ,
210222 "-hide_banner" ,
211223 "-loglevel" ,
@@ -221,7 +233,7 @@ async def get_video_thumbnail(video_file, duration):
221233 "-frames:v" ,
222234 "1" ,
223235 "-threads" ,
224- f"{ max ( 1 , cpu_no // 2 ) } " ,
236+ f"{ threads } " ,
225237 output ,
226238 ]
227239 try :
@@ -249,6 +261,9 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
249261 await makedirs (output_dir , exist_ok = True )
250262 output = ospath .join (output_dir , f"{ time ()} .jpg" )
251263 cmd = [
264+ "taskset" ,
265+ "-c" ,
266+ f"{ cores } " ,
252267 "ffmpeg" ,
253268 "-hide_banner" ,
254269 "-loglevel" ,
@@ -266,7 +281,7 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
266281 "-f" ,
267282 "mjpeg" ,
268283 "-threads" ,
269- f"{ max ( 1 , cpu_no // 2 ) } " ,
284+ f"{ threads } " ,
270285 output ,
271286 ]
272287 try :
@@ -445,7 +460,7 @@ async def convert_video(self, video_file, ext, retry=False):
445460 "-c:a" ,
446461 "aac" ,
447462 "-threads" ,
448- f"{ max ( 1 , cpu_no // 2 ) } " ,
463+ f"{ threads } " ,
449464 output ,
450465 ]
451466 if ext == "mp4" :
@@ -469,7 +484,7 @@ async def convert_video(self, video_file, ext, retry=False):
469484 "-c" ,
470485 "copy" ,
471486 "-threads" ,
472- f"{ max ( 1 , cpu_no // 2 ) } " ,
487+ f"{ threads } " ,
473488 output ,
474489 ]
475490 if self ._listener .is_cancelled :
@@ -516,7 +531,7 @@ async def convert_audio(self, audio_file, ext):
516531 "-i" ,
517532 audio_file ,
518533 "-threads" ,
519- f"{ max ( 1 , cpu_no // 2 ) } " ,
534+ f"{ threads } " ,
520535 output ,
521536 ]
522537 if self ._listener .is_cancelled :
@@ -596,7 +611,7 @@ async def sample_video(self, video_file, sample_duration, part_duration):
596611 "-c:a" ,
597612 "aac" ,
598613 "-threads" ,
599- f"{ max ( 1 , cpu_no // 2 ) } " ,
614+ f"{ threads } " ,
600615 output_file ,
601616 ]
602617
@@ -661,7 +676,7 @@ async def split(self, f_path, file_, parts, split_size):
661676 "-c" ,
662677 "copy" ,
663678 "-threads" ,
664- f"{ max ( 1 , cpu_no // 2 ) } " ,
679+ f"{ threads } " ,
665680 out_path ,
666681 ]
667682 if not multi_streams :
0 commit comments