Files
WerkoutAPI/video/tasks.py
2024-08-28 12:43:40 -05:00

26 lines
964 B
Python

from celery import shared_task
import os
from django.conf import settings
import ffmpeg_streaming
from ffmpeg_streaming import Formats, Bitrate, Representation, Size, FFProbe
from django.core.files.storage import default_storage
@shared_task()
def create_hls_tasks(filename):
end_location = str(settings.MEDIA_ROOT) + "/" + str(filename) +'.m3u8'
if not default_storage.exists(end_location):
media_location = str(settings.MEDIA_ROOT) + "/" + str(filename)
video = ffmpeg_streaming.input(media_location)
hls = video.hls(Formats.h264())
# 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)