Skip to content

Commit 74fe820

Browse files
committed
another fix for media convert
Signed-off-by: anasty17 <[email protected]>
1 parent b5f6f3f commit 74fe820

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bot/helper/ext_utils/media_utils.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ async def convert_video(listener, video_file, ext, retry=False):
2020
"ffmpeg",
2121
"-i",
2222
video_file,
23-
"-preset",
24-
"ultrafast",
2523
"-c:v",
2624
"libx264",
2725
"-c:a",
@@ -32,6 +30,10 @@ async def convert_video(listener, video_file, ext, retry=False):
3230
f"{cpu_count() // 2}",
3331
output,
3432
]
33+
if ext == "mp4":
34+
cmd[7:7] = ["-c:s", "mov_text"]
35+
elif ext == "mkv":
36+
cmd[7:7] = ["-c:s", "ass"]
3537
else:
3638
cmd = ["ffmpeg", "-i", video_file, "-map", "0", "-c", "copy", output]
3739
if listener.cancelled:
@@ -52,6 +54,8 @@ async def convert_video(listener, video_file, ext, retry=False):
5254
f"{stderr}. Something went wrong while converting video, mostly file is corrupted. Path: {video_file}"
5355
)
5456
if not retry:
57+
if await aiopath.exists(output):
58+
await remove(output)
5559
return await convert_video(listener, video_file, ext, True)
5660
return False
5761

@@ -63,8 +67,6 @@ async def convert_audio(listener, audio_file, ext):
6367
"ffmpeg",
6468
"-i",
6569
audio_file,
66-
"-preset",
67-
"ultrafast",
6870
"-map",
6971
"0",
7072
"-threads",
@@ -88,6 +90,8 @@ async def convert_audio(listener, audio_file, ext):
8890
LOGGER.error(
8991
f"{stderr}. Something went wrong while converting audio, mostly file is corrupted. Path: {audio_file}"
9092
)
93+
if await aiopath.exists(output):
94+
await remove(output)
9195
return False
9296

9397

@@ -512,8 +516,6 @@ async def createSampleVideo(listener, video_file, sample_duration, part_duration
512516
"ffmpeg",
513517
"-i",
514518
video_file,
515-
"-preset",
516-
"ultrafast",
517519
"-filter_complex",
518520
filter_complex,
519521
"-map",
@@ -546,4 +548,6 @@ async def createSampleVideo(listener, video_file, sample_duration, part_duration
546548
LOGGER.error(
547549
f"{stderr}. Something went wrong while creating sample video, mostly file is corrupted. Path: {video_file}"
548550
)
551+
if await aiopath.exists(output_file):
552+
await remove(output_file)
549553
return False

0 commit comments

Comments
 (0)