Describe the bug
I am using the custom service configuration with minIO, at the end of the conversion I see the error of
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python3.8/shutil.py", line 788, in move
os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ffmpeg_streaming_tslt6ddb' -> ''
my code
from SARyS.Apps.Streaming.convert2 import CustomCloud
from ffmpeg_streaming import Formats, Bitrate, Representation, Size, CloudManager
import ffmpeg_streaming
custom = CustomCloud()
video = ffmpeg_streaming.input(
custom,
bucket_name="django-backend-dev-private",
key="23037532_179905455894717_507699614384652288_n.mp4",
)
hls = video.hls(Formats.h264())
_144p = Representation(Size(256, 144), Bitrate(95 * 1024, 64 * 1024))
_240p = Representation(Size(426, 240), Bitrate(150 * 1024, 94 * 1024))
_360p = Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
_480p = Representation(Size(854, 480), Bitrate(750 * 1024, 192 * 1024))
_720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024))
_1080p = Representation(Size(1920, 1080), Bitrate(4096 * 1024, 320 * 1024))
_2k = Representation(Size(2560, 1440), Bitrate(6144 * 1024, 320 * 1024))
_4k = Representation(Size(3840, 2160), Bitrate(17408 * 1024, 320 * 1024))
hls.representations(_360p, _720p)
save_to_custom = CloudManager().add(
custom,
bucket_name="django-backend-dev-private",
)
hls.output(
'playlist.m3u8',
clouds=save_to_custom,
)
CustomCloud
from django.core.files.uploadedfile import InMemoryUploadedFile
from ffmpeg_streaming import Clouds
import tempfile
from django_minio_backend import MinioBackend
from os.path import isfile, join, basename
import logging
import sys
import datetime
from os import listdir
import io
import os
class CustomCloud(Clouds):
def upload_directory(self, directory, **options):
bucket_name = options.pop('bucket_name', None)
if bucket_name is None:
raise ValueError('You should pass a bucket name')
files = [f for f in listdir(directory) if isfile(join(directory, f))]
storage = MinioBackend(bucket_name=bucket_name)
content_type = None
contentType = {
'm3u8': 'application/x-mpegURL',
'ts': 'video/MP2T',
'mp4': 'video/mp4',
}
try:
for file in files:
try:
if file.split('.')[1] == 'ts':
content_type = contentType['ts']
elif file.split('.')[1] == 'm3u8':
content_type = contentType['m3u8']
f = io.BytesIO(b'')
with open(os.path.join(directory, file), 'rb') as zip_file:
flength = f.write(zip_file.read())
metrics = InMemoryUploadedFile(
f, None, file, content_type, flength, None
)
metrics.seek(0)
storage._save(file_path_name=join(
'streaming', file), content=metrics)
except Exception as e:
logging.error('file '+e)
raise RuntimeError('file', e)
except Exception as e:
logging.error('files '+e)
raise RuntimeError('files', e)
def download(self, filename=None, **options):
bucket_name = options.pop('bucket_name', None)
key = options.pop('key', None)
if bucket_name is None or key is None:
raise ValueError('You should pass a bucket and key name')
if filename is None:
filename = tempfile.NamedTemporaryFile(
prefix=basename(key), delete=False)
else:
filename = open(filename, 'wb')
try:
with filename as f:
storage = MinioBackend(bucket_name=bucket_name)
file = storage._open(object_name=key)
for chunk in file.chunks():
f.write(chunk)
logging.info("The " + filename.name + " file was downloaded")
except Exception as e:
logging.error(e)
raise RuntimeError(e)
return filename.name
OS Lubuntu 20.10
ffmpeg version 4.3.1-4ubuntu1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10 (Ubuntu 10.2.0-9ubuntu2)