Skip to content

Commit

Permalink
remove unused print, split encode function in sub function, call it i…
Browse files Browse the repository at this point in the history
…n importing_tasks
  • Loading branch information
ptitloup committed Jun 29, 2023
1 parent ac29930 commit 4d86dee
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pod/video_encode_transcript/Encoding_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from webvtt import WebVTT, Caption
import argparse
import unicodedata
print("NAME : %s" % __name__)

if __name__ == "__main__":
from encoding_utils import (
get_info_from_video,
Expand Down
48 changes: 27 additions & 21 deletions pod/video_encode_transcript/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,47 +112,53 @@ def encode_video(video_id):

change_encoding_step(video_id, 0, "start")
# start and stop cut ?
if CutVideo.objects.filter(video=video_id).exists():
cut = CutVideo.objects.get(video=video_id)
cut_start = time_to_seconds(cut.start)
cut_end = time_to_seconds(cut.end)
encoding_video = Encoding_video_model(
video_id, video_to_encode.video.path, cut_start, cut_end
)
else:
encoding_video = Encoding_video_model(video_id, video_to_encode.video.path)
encoding_video = get_encoding_video(video_to_encode)
encoding_video.add_encoding_log("start_time", "", True, start)
# change_encoding_step(video_id, 1, "get video data")
# encoding_video.get_video_data()
change_encoding_step(video_id, 1, "remove old data")
encoding_video.remove_old_data()
# create video dir
# change_encoding_step(video_id, 3, "create output dir")
# encoding_video.create_output_dir()

change_encoding_step(video_id, 2, "start encoding")
if USE_DISTANT_ENCODING:
start_encoding_task.delay(
encoding_video.id,
encoding_video.video_file,
encoding_video.start,
encoding_video.stop
encoding_video.cutting_start,
encoding_video.cutting_stop
)
return
encoding_video.start_encode()
else:
encoding_video.start_encode()
final_video = store_encoding_info(video_id, encoding_video)
end_of_encoding(final_video)


def store_encoding_info(video_id, encoding_video):
change_encoding_step(video_id, 3, "store encoding info")
final_video = encoding_video.store_json_info()
final_video.is_video = final_video.get_video_m4a() is None
final_video.encoding_in_progress = False
final_video.save()
return final_video


def get_encoding_video(video_to_encode):
if CutVideo.objects.filter(video=video_to_encode).exists():
cut = CutVideo.objects.get(video=video_to_encode)
cut_start = time_to_seconds(cut.start)
cut_end = time_to_seconds(cut.end)
encoding_video = Encoding_video_model(
video_to_encode.id, video_to_encode.video.path, cut_start, cut_end
)
return encoding_video
return Encoding_video_model(video_to_encode.id, video_to_encode.video.path)


def end_of_encoding(video):
# envois mail fin encodage
if EMAIL_ON_ENCODING_COMPLETION:
send_email_encoding(video_to_encode)
send_email_encoding(video)

transcript_video(video_id)
change_encoding_step(video_id, 0, "end of encoding")
transcript_video(video.id)
change_encoding_step(video.id, 0, "end of encoding")


def transcript_video(video_id):
Expand Down
10 changes: 9 additions & 1 deletion pod/video_encode_transcript/encoding_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"pod.video_encode_transcript.encoding_tasks.*": {"queue": "encoding"}
}


# celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding
@encoding_app.task
def start_encoding_task(video_id, video_path, cut_start, cut_end):
Expand All @@ -31,4 +32,11 @@ def start_encoding_task(video_id, video_path, cut_start, cut_end):
encoding_video = Encoding_video(video_id, video_path, cut_start, cut_end)
encoding_video.start_encode()
print("End of the encoding of the video")
start_importing_task.delay(video_id, video_path)
start_importing_task.delay(
encoding_video.start,
video_id,
video_path,
cut_start,
cut_end,
encoding_video.stop
)
30 changes: 9 additions & 21 deletions pod/video_encode_transcript/importing_tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from celery import Celery
from .. import settings
import logging

logger = logging.getLogger(__name__)

ENCODING_CELERY_BROKER_URL = getattr(settings, "ENCODING_CELERY_BROKER_URL", "")
Expand All @@ -14,28 +13,17 @@
"pod.video_encode_transcript.importing_tasks.*": {"queue": "importing"}
}

# celery -A pod.video_encode_transcript.importing_tasks worker -l INFO -Q importing

# celery -A pod.video_encode_transcript.importing_tasks worker -l INFO -Q importing
@importing_app.task
def start_importing_task(video_id, video_path):
def start_importing_task(start, video_id, video_path, cut_start, cut_end, stop):
"""Start the encoding of the video."""
print("Start the importing of the video ID : %s" % video_id)
from .Encoding_video_model import Encoding_video_model
from django.conf import settings
from .utils import (
change_encoding_step,
send_email_encoding,
)
from pod.video.models import Video
EMAIL_ON_ENCODING_COMPLETION = getattr(settings, "EMAIL_ON_ENCODING_COMPLETION", True)
encoding_video = Encoding_video_model(video_id, video_path)
change_encoding_step(video_id, 3, "store encoding info")
final_video = encoding_video.store_json_info()
final_video.is_video = final_video.get_video_m4a() is None
final_video.encoding_in_progress = False
final_video.save()

# envois mail fin encodage
if EMAIL_ON_ENCODING_COMPLETION:
video_to_encode = Video.objects.get(id=video_id)
send_email_encoding(video_to_encode)
from .encode import store_encoding_info, end_of_encoding
encoding_video = Encoding_video_model(video_id, video_path, cut_start, cut_end)
encoding_video.start = start
encoding_video.stop = stop

final_video = store_encoding_info(video_id, encoding_video)
end_of_encoding(final_video)

0 comments on commit 4d86dee

Please sign in to comment.