From b7e4f7c4dcaaac8bcd674268b1892f4e2f9e1afb Mon Sep 17 00:00:00 2001 From: Trey t Date: Wed, 28 Aug 2024 12:43:40 -0500 Subject: [PATCH] video upload aspect ratio --- video/tasks.py | 15 ++++++++++++--- video/views.py | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/video/tasks.py b/video/tasks.py index 73546e8..f9df702 100644 --- a/video/tasks.py +++ b/video/tasks.py @@ -2,7 +2,7 @@ from celery import shared_task import os from django.conf import settings import ffmpeg_streaming -from ffmpeg_streaming import Formats, Bitrate, Representation, Size +from ffmpeg_streaming import Formats, Bitrate, Representation, Size, FFProbe from django.core.files.storage import default_storage @shared_task() @@ -12,6 +12,15 @@ def create_hls_tasks(filename): media_location = str(settings.MEDIA_ROOT) + "/" + str(filename) video = ffmpeg_streaming.input(media_location) hls = video.hls(Formats.h264()) - _720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024)) - hls.representations(_720p) + + # ffprobe = FFProbe(media_location) + # first_video = ffprobe.streams().video() + + # dimensions = ( + # first_video.get('width', "Unknown"), + # first_video.get('height', "Unknown") + # ) + # print(f"Dimensions: {dimensions[0]}x{dimensions[1]}") # f-string + + hls.auto_generate_representations() hls.output(end_location) \ No newline at end of file diff --git a/video/views.py b/video/views.py index 92ecf02..130ce2e 100644 --- a/video/views.py +++ b/video/views.py @@ -60,8 +60,8 @@ def hls_videos(request): video = ffmpeg_streaming.input(media_location) hls = video.hls(Formats.h264()) - _720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024)) - hls.representations(_720p) + #_720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024)) + hls.auto_generate_representations() hls.output(end_location) # {{url}}/videos/hls_video?video_name=Spiderman_Stretch.mp4&video_type=exercise_videos # {{url}}/videos/hls_video?video_name=Recover_24.mp4&video_type=videos