This commit is contained in:
Markos Gogoulos 2025-05-21 16:11:47 +03:00
parent 9b8c860b46
commit cb6004ce15
2 changed files with 8 additions and 4 deletions

View File

@ -420,6 +420,8 @@ def kill_ffmpeg_process(filepath):
Returns: Returns:
subprocess.CompletedProcess: Result of the kill command subprocess.CompletedProcess: Result of the kill command
""" """
if not filepath:
return False
cmd = "ps aux|grep 'ffmpeg'|grep %s|grep -v grep |awk '{print $2}'" % filepath cmd = "ps aux|grep 'ffmpeg'|grep %s|grep -v grep |awk '{print $2}'" % filepath
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True) result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True)
pid = result.stdout.decode("utf-8").strip() pid = result.stdout.decode("utf-8").strip()

View File

@ -183,6 +183,7 @@ class EncodingTask(Task):
self.encoding.status = "fail" self.encoding.status = "fail"
self.encoding.save(update_fields=["status"]) self.encoding.save(update_fields=["status"])
kill_ffmpeg_process(self.encoding.temp_file) kill_ffmpeg_process(self.encoding.temp_file)
kill_ffmpeg_process(self.encoding.chunk_file_path)
if hasattr(self.encoding, "media"): if hasattr(self.encoding, "media"):
self.encoding.media.post_encode_actions() self.encoding.media.post_encode_actions()
except BaseException: except BaseException:
@ -367,6 +368,7 @@ def encode_media(
except AttributeError: except AttributeError:
output = "" output = ""
kill_ffmpeg_process(encoding.temp_file) kill_ffmpeg_process(encoding.temp_file)
kill_ffmpeg_process(encoding.chunk_file_path)
encoding.logs = output encoding.logs = output
encoding.status = "fail" encoding.status = "fail"
encoding.save(update_fields=["status", "logs"]) encoding.save(update_fields=["status", "logs"])
@ -966,7 +968,7 @@ def video_trim_task(self, trim_request_id):
# give the chance to run encodings for encodings that didnt make it # give the chance to run encodings for encodings that didnt make it
target_media.encode(force=False) target_media.encode(force=False)
# TODO: find way to call post_trim_action only after this has finished... # TODO: find way to call post_trim_action only after this has finished...
else:
post_trim_action.delay(target_media.friendly_token) post_trim_action.delay(target_media.friendly_token)
trim_request.status = "success" trim_request.status = "success"
@ -993,7 +995,7 @@ def video_trim_task(self, trim_request_id):
# give the chance to run encodings for encodings that didnt make it # give the chance to run encodings for encodings that didnt make it
target_media.encode(force=False) target_media.encode(force=False)
# TODO: find way to call post_trim_action only after this has finished... # TODO: find way to call post_trim_action only after this has finished...
else:
post_trim_action.delay(target_media.friendly_token) post_trim_action.delay(target_media.friendly_token)
trim_request.status = "success" trim_request.status = "success"