• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EsupPortail / Esup-Pod / 5976101876

25 Aug 2023 12:51PM UTC coverage: 70.8%. First build
5976101876

Pull #900

github

web-flow
add check configuration to show filter in filter asde template (#917)
Pull Request #900: [WIP] develop #3.4.0

633 of 633 new or added lines in 26 files covered. (100.0%)

9056 of 12791 relevant lines covered (70.8%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/pod/video_encode_transcript/encode.py
1
"""This module handles video encoding with CPU."""
2

3
from django.conf import settings
1✔
4
from pod.video.models import Video
1✔
5
from .Encoding_video_model import Encoding_video_model
1✔
6
from .encoding_studio import encode_video_studio
1✔
7

8
from pod.cut.models import CutVideo
1✔
9
from pod.main.tasks import task_start_encode, task_start_encode_studio
1✔
10
from .utils import (
1✔
11
    change_encoding_step,
12
    check_file,
13
    add_encoding_log,
14
    send_email,
15
    send_email_encoding,
16
    time_to_seconds,
17
)
18
import logging
1✔
19
import time
1✔
20
import threading
1✔
21

22
__license__ = "LGPL v3"
1✔
23
log = logging.getLogger(__name__)
1✔
24

25
USE_TRANSCRIPTION = getattr(settings, "USE_TRANSCRIPTION", False)
1✔
26

27
if USE_TRANSCRIPTION:
1✔
28
    from . import transcript
×
29

30
    TRANSCRIPT_VIDEO = getattr(settings, "TRANSCRIPT_VIDEO", "start_transcript")
×
31

32
CELERY_TO_ENCODE = getattr(settings, "CELERY_TO_ENCODE", False)
1✔
33
EMAIL_ON_ENCODING_COMPLETION = getattr(settings, "EMAIL_ON_ENCODING_COMPLETION", True)
1✔
34

35
USE_DISTANT_ENCODING_TRANSCODING = getattr(
1✔
36
    settings, "USE_DISTANT_ENCODING_TRANSCODING", False
37
)
38
if USE_DISTANT_ENCODING_TRANSCODING:
1✔
39
    from .encoding_tasks import start_encoding_task
×
40

41
# ##########################################################################
42
# ENCODE VIDEO: THREAD TO LAUNCH ENCODE
43
# ##########################################################################
44

45
# Disable for the moment, will be reactivated in future version
46
"""
47
def start_remote_encode(video_id):
48
    # load module here to prevent circular import
49
    from .remote_encode import remote_encode_video
50

51
    log.info("START ENCODE VIDEO ID %s" % video_id)
52
    t = threading.Thread(target=remote_encode_video, args=[video_id])
53
    t.setDaemon(True)
54
    t.start()
55
"""
56

57

58
def start_encode(video_id, threaded=True):
1✔
59
    """Start local encoding."""
60
    if threaded:
1✔
61
        if CELERY_TO_ENCODE:
1✔
62
            task_start_encode.delay(video_id)
×
63
        else:
64
            log.info("START ENCODE VIDEO ID %s" % video_id)
1✔
65
            t = threading.Thread(target=encode_video, args=[video_id])
1✔
66
            t.setDaemon(True)
1✔
67
            t.start()
1✔
68
    else:
69
        encode_video(video_id)
×
70

71

72
def start_encode_studio(recording_id, video_output, videos, subtime, presenter):
1✔
73
    """Start local encoding."""
74
    if CELERY_TO_ENCODE:
×
75
        task_start_encode_studio.delay(
×
76
            recording_id, video_output, videos, subtime, presenter
77
        )
78
    else:
79
        log.info("START ENCODE VIDEO ID %s" % recording_id)
×
80
        t = threading.Thread(
×
81
            target=encode_video_studio,
82
            args=[recording_id, video_output, videos, subtime, presenter],
83
        )
84
        t.setDaemon(True)
×
85
        t.start()
×
86

87

88
"""
89
def start_studio_remote_encode(recording_id, video_output, videos, subtime, presenter):
90
    # load module here to prevent circular import
91
    from .remote_encode import remote_encode_studio
92

93
    log.info("START ENCODE RECORDING ID %s" % recording_id)
94
    t = threading.Thread(
95
        target=remote_encode_studio,
96
        args=[recording_id, video_output, videos, subtime, presenter],
97
    )
98
    t.setDaemon(True)
99
    t.start()
100
"""
101

102

103
def encode_video(video_id):
1✔
104
    """ENCODE VIDEO: MAIN FUNCTION."""
105
    start = "Start at: %s" % time.ctime()
1✔
106

107
    video_to_encode = Video.objects.get(id=video_id)
1✔
108
    video_to_encode.encoding_in_progress = True
1✔
109
    video_to_encode.save()
1✔
110

111
    if not check_file(video_to_encode.video.path):
1✔
112
        msg = "Wrong file or path:" + "\n%s" % video_to_encode.video.path
1✔
113
        add_encoding_log(video_id, msg)
1✔
114
        change_encoding_step(video_id, -1, msg)
1✔
115
        send_email(msg, video_id)
1✔
116
        return
1✔
117

118
    change_encoding_step(video_id, 0, "start")
1✔
119
    # start and stop cut ?
120
    encoding_video = get_encoding_video(video_to_encode)
1✔
121
    encoding_video.add_encoding_log("start_time", "", True, start)
1✔
122
    change_encoding_step(video_id, 1, "remove old data")
1✔
123
    encoding_video.remove_old_data()
1✔
124

125
    change_encoding_step(video_id, 2, "start encoding")
1✔
126
    if USE_DISTANT_ENCODING_TRANSCODING:
1✔
127
        start_encoding_task.delay(
×
128
            encoding_video.id,
129
            encoding_video.video_file,
130
            encoding_video.cutting_start,
131
            encoding_video.cutting_stop,
132
        )
133
    else:
134
        encoding_video.start_encode()
1✔
135
        final_video = store_encoding_info(video_id, encoding_video)
1✔
136
        end_of_encoding(final_video)
1✔
137

138

139
def store_encoding_info(video_id, encoding_video):
1✔
140
    """Store all encoding file and informations from encoding tasks."""
141
    change_encoding_step(video_id, 3, "store encoding info")
1✔
142
    final_video = encoding_video.store_json_info()
1✔
143
    final_video.is_video = final_video.get_video_m4a() is None
1✔
144
    final_video.encoding_in_progress = False
1✔
145
    final_video.save()
1✔
146
    return final_video
1✔
147

148

149
def get_encoding_video(video_to_encode):
1✔
150
    """Get the encoding video object from video."""
151
    if CutVideo.objects.filter(video=video_to_encode).exists():
1✔
152
        cut = CutVideo.objects.get(video=video_to_encode)
×
153
        cut_start = time_to_seconds(cut.start)
×
154
        cut_end = time_to_seconds(cut.end)
×
155
        encoding_video = Encoding_video_model(
×
156
            video_to_encode.id, video_to_encode.video.path, cut_start, cut_end
157
        )
158
        return encoding_video
×
159
    return Encoding_video_model(video_to_encode.id, video_to_encode.video.path)
1✔
160

161

162
def end_of_encoding(video):
1✔
163
    """Send mail at the end of encoding, call transcription."""
164
    if EMAIL_ON_ENCODING_COMPLETION:
1✔
165
        send_email_encoding(video)
1✔
166

167
    transcript_video(video.id)
1✔
168
    change_encoding_step(video.id, 0, "end of encoding")
1✔
169

170

171
def transcript_video(video_id):
1✔
172
    """Transcript video audio to text."""
173
    video = Video.objects.get(id=video_id)
1✔
174
    if USE_TRANSCRIPTION and video.transcript not in ["", "0", "1"]:
1✔
175
        change_encoding_step(video_id, 4, "transcript video")
×
176
        start_transcript_video = getattr(transcript, TRANSCRIPT_VIDEO)
×
177
        start_transcript_video(video_id, False)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc