Skip to content

Commit

Permalink
Merge pull request #480 from EsupPortail/dev
Browse files Browse the repository at this point in the history
Dev 2.8.1
  • Loading branch information
ptitloup authored Apr 29, 2021
2 parents ebe2e30 + 5ed6921 commit 87d9204
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 131 deletions.
3 changes: 2 additions & 1 deletion pod/main/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
POD_ARCHIVE_AFFILIATION = ['faculty']
WARN_DEADLINES = [60, 30, 7]
USE_BBB = True
USE_VIDEO_RECORD = True
USE_VIDEO_RECORD = True

3 changes: 3 additions & 0 deletions pod/recorder/plugins/type_audiovideocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def save_video(recording, video_data, video_src):
video.is_360 = recorder.is_360
# Désactiver les commentaires
video.disable_comment = recorder.disable_comment
# add sites
video.sites.add(*recorder.sites.all())

video.save()
encode_video = getattr(encode, ENCODE_VIDEO)
encode_video(video.id)
Expand Down
2 changes: 2 additions & 0 deletions pod/recorder/plugins/type_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def encode_recording(recording):
video.is_360 = recorder.is_360
# Désactiver les commentaires
video.disable_comment = recorder.disable_comment
# add sites
video.sites.add(*recorder.sites.all())
video.save()

encode_video = getattr(encode, ENCODE_VIDEO)
Expand Down
2 changes: 1 addition & 1 deletion pod/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##
# Version of the project
#
VERSION = '2.8'
VERSION = '2.8.1'

##
# Installed applications list
Expand Down
20 changes: 16 additions & 4 deletions pod/video/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from .utils import change_encoding_step, add_encoding_log, check_file
from .utils import create_outputdir, send_email, send_email_encoding
from .utils import get_duration_from_mp4
from .utils import fix_video_duration
# from pod.main.context_processors import TEMPLATE_VISIBLE_SETTINGS
from pod.main.tasks import task_start_encode

Expand Down Expand Up @@ -331,14 +333,17 @@ def encode_video(video_id):
video_id, 4,
"encoding video file: 7/11 remove_previous_overview")
remove_previous_overview(overviewfilename, overviewimagefilename)
video_duration = video_data["duration"] if (
video_data["duration"] > 0) else get_duration_from_mp4(
video_mp4.source_file.path, output_dir)
nb_img = 99 if (
video_data["duration"] > 99) else video_data["duration"]
video_duration > 99) else video_duration
change_encoding_step(
video_id, 4,
"encoding video file: 8/11 create_overview_image")
msg = create_overview_image(
video_id,
video_mp4.video.video.path, video_data["duration"],
video_mp4.source_file.path, video_duration,
nb_img, image_width, overviewimagefilename, overviewfilename)
add_encoding_log(
video_id,
Expand All @@ -348,7 +353,7 @@ def encode_video(video_id):
video_id, 4,
"encoding video file: 11/11 create_and_save_thumbnails")
msg = create_and_save_thumbnails(
video_mp4.video.video.path, video_mp4.width, video_id)
video_mp4.source_file.path, video_mp4.width, video_id)
add_encoding_log(
video_id,
"create_and_save_thumbnails: %s" % msg)
Expand All @@ -369,6 +374,8 @@ def encode_video(video_id):
video_to_encode.encoding_in_progress = False
video_to_encode.save()

fix_video_duration(video_id, output_dir)

# End
add_encoding_log(video_id, "End: %s" % time.ctime())
with open(output_dir + "/encoding.log", "a") as f:
Expand Down Expand Up @@ -429,7 +436,12 @@ def get_video_data(video_id, output_dir):
duration = 0
key_frames_interval = 0
if len(info["streams"]) > 0:
is_video = True
codec = info["streams"][0].get("codec_name", "unknown")
image_codec = ["jpeg", "gif", "png", "bmp", "jpg"]
is_stream_thumbnail = any(ext in codec.lower()
for ext in image_codec)
if not is_stream_thumbnail:
is_video = True
if info["streams"][0].get('height'):
in_height = info["streams"][0]['height']
"""
Expand Down
13 changes: 7 additions & 6 deletions pod/video/encode_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def encode_with_gpu(format, codec, height, file):
msg += "Encode CPU %s ok \n" % format
return_value = True
if return_value is False:
msg += 20 * "////" + "\n"
msg += 20*"////" + "\n"
msg += 'ERROR ENCODING %s FOR FILE %s \n' % (format, file)
encode_log(msg)
return return_value
Expand Down Expand Up @@ -510,8 +510,6 @@ def get_info_video(file):
msg = "--> get_info_video" + "\n"
probe_cmd = 'ffprobe -v quiet -show_format -show_streams \
-print_format json -i {}/{}'.format(VIDEOS_DIR, file)
if DEBUG:
print(probe_cmd)
msg += probe_cmd + "\n"
has_stream_video = False
has_stream_thumbnail = False
Expand All @@ -523,7 +521,10 @@ def get_info_video(file):
msg += json.dumps(info, indent=2)
msg += " \n"
msg += return_msg + "\n"
duration = int(float("%s" % info["format"]['duration']))
try:
duration = int(float("%s" % info["format"]['duration']))
except (RuntimeError, KeyError, AttributeError, ValueError) as err:
msg += "\nUnexpected error: {0}".format(err)
streams = info.get("streams", [])
for stream in streams:
msg += stream.get("codec_type", "unknown")
Expand All @@ -538,9 +539,7 @@ def get_info_video(file):
height = stream.get("height", 0)
if stream.get("codec_type", "unknown") == "audio":
has_stream_audio = True

encode_log(msg)

return {
"has_stream_video": has_stream_video,
"has_stream_thumbnail": has_stream_thumbnail,
Expand Down Expand Up @@ -706,6 +705,8 @@ def add_info_video(key, value, append=False):
info_video = {}

info_video = get_info_video(filename)
if not DEBUG and info_video["duration"] > 0:
SUBTIME = ' -ss 0 -to %s ' % info_video["duration"]
msg += " \n"
msg += json.dumps(info_video, indent=2)
msg += " \n"
Expand Down
2 changes: 1 addition & 1 deletion pod/video/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def set_queryset(self):
user_channels = Channel.objects.all() if self.is_superuser else (
self.current_user.owners_channels.all(
) | self.current_user.users_channels.all(
) | Channel.objects.filter(allow_to_groups=users_groups)
) | Channel.objects.filter(allow_to_groups__in=users_groups)
).distinct()
user_channels.filter(sites=get_current_site(None))
if user_channels:
Expand Down
40 changes: 31 additions & 9 deletions pod/video/remote_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from .utils import change_encoding_step, add_encoding_log, check_file
from .utils import create_outputdir, send_email, send_email_encoding
from .utils import fix_video_duration, get_duration_from_mp4

if getattr(settings, 'USE_PODFILE', False):
FILEPICKER = True
Expand Down Expand Up @@ -54,12 +55,21 @@
settings, 'SSH_REMOTE_KEY', "")
SSH_REMOTE_CMD = getattr(
settings, 'SSH_REMOTE_CMD', "")

ENCODING_CHOICES = getattr(
settings, 'ENCODING_CHOICES', (
("audio", "audio"),
("360p", "360p"),
("480p", "480p"),
("720p", "720p"),
("1080p", "1080p"),
("playlist", "playlist")
))

# ##########################################################################
# REMOTE ENCODE VIDEO : THREAD TO LAUNCH ENCODE
# ##########################################################################


def start_store_remote_encoding_video(video_id):
log.info("START STORE ENCODED FILES FOR VIDEO ID %s" % video_id)
t = threading.Thread(target=store_remote_encoding_video,
Expand Down Expand Up @@ -195,6 +205,8 @@ def store_remote_encoding_video(video_id):
video_encoding.encoding_in_progress = False
video_encoding.save()

fix_video_duration(video_encoding.id, output_dir)

# End
add_encoding_log(video_id, "End : %s" % time.ctime())
with open(output_dir + "/encoding.log", "a") as f:
Expand Down Expand Up @@ -271,20 +283,23 @@ def remote_video_part(video_to_encode, info_video, output_dir):
image_width = video_mp4.width / 4 # width of generate image file
change_encoding_step(
video_id, 4,
"encoding video file : 7/11 remove_previous_overview")
"encoding video file: 7/11 remove_previous_overview")
remove_previous_overview(overviewfilename, overviewimagefilename)
video_duration = info_video["duration"] if (
info_video["duration"] > 0) else get_duration_from_mp4(
video_mp4.source_file.path, output_dir)
nb_img = 99 if (
info_video["duration"] > 99) else info_video["duration"]
video_duration > 99) else video_duration
change_encoding_step(
video_id, 4,
"encoding video file : 8/11 create_overview_image")
"encoding video file: 8/11 create_overview_image")
msg_overview = create_overview_image(
video_id,
video_mp4.video.video.path, info_video["duration"],
video_mp4.source_file.path, video_duration,
nb_img, image_width, overviewimagefilename, overviewfilename)
add_encoding_log(
video_id,
"create_overview_image : %s" % msg_overview)
"create_overview_image: %s" % msg_overview)
# create thumbnail
if (
info_video["has_stream_thumbnail"]
Expand Down Expand Up @@ -463,7 +478,7 @@ def import_mp4(encod_video, output_dir, video_to_encode):
rendition = VideoRendition.objects.get(
resolution=encod_video["rendition"])
encoding, created = EncodingVideo.objects.get_or_create(
name=filename,
name=get_encoding_choice_from_filename(filename),
video=video_to_encode,
rendition=rendition,
encoding_format="video/mp4")
Expand Down Expand Up @@ -503,7 +518,7 @@ def import_m3u8(encod_video, output_dir, video_to_encode):
):

encoding, created = EncodingVideo.objects.get_or_create(
name=filename,
name=get_encoding_choice_from_filename(filename),
video=video_to_encode,
rendition=rendition,
encoding_format="video/mp2t")
Expand All @@ -512,7 +527,7 @@ def import_m3u8(encod_video, output_dir, video_to_encode):
encoding.save()

playlist, created = PlaylistVideo.objects.get_or_create(
name=filename,
name=get_encoding_choice_from_filename(filename),
video=video_to_encode,
encoding_format="application/x-mpegURL")
playlist.source_file = videofilenameM3u8.replace(
Expand All @@ -532,3 +547,10 @@ def import_m3u8(encod_video, output_dir, video_to_encode):
send_email(msg, video_to_encode.id)

return msg, master_playlist


def get_encoding_choice_from_filename(filename):
choices = {}
for choice in ENCODING_CHOICES:
choices[choice[0][:3]] = choice[0]
return choices.get(filename[:3], "360p")
Loading

0 comments on commit 87d9204

Please sign in to comment.