From e8d3ff25be8ced2811f721e696544dca067fe7bb Mon Sep 17 00:00:00 2001 From: Markos Gogoulos Date: Fri, 10 Nov 2023 14:25:10 +0200 Subject: [PATCH] Disable encoding and show only original file (#829) Disable encoding and show only original file #829 --- cli-tool/cli.py | 2 +- cms/settings.py | 5 ++++- docs/admins_docs.md | 11 ++++++++++- files/helpers.py | 4 ++-- files/models.py | 16 ++++++++++++++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cli-tool/cli.py b/cli-tool/cli.py index 42525be..6e814d2 100644 --- a/cli-tool/cli.py +++ b/cli-tool/cli.py @@ -59,7 +59,7 @@ def login(): file.writelines(f'USERNAME={json.loads(response.text)["username"]}\n') print(f"Welcome to MediaCMS [bold blue]{username}[/bold blue]. Your auth creds have been suceesfully stored in the .env file", ":v:") else: - print(f'Error: {"non_field_errors":["User not found."]}') + print(f'Error: {"non_field_errors": ["User not found."]}') @apis.command() diff --git a/cms/settings.py b/cms/settings.py index 7945215..32060cc 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -467,7 +467,7 @@ except ImportError: if "http" not in FRONTEND_HOST: # FRONTEND_HOST needs a http:// preffix - FRONTEND_HOST = f"http://{FRONTEND_HOST}" + FRONTEND_HOST = f"http://{FRONTEND_HOST}" # noqa if LOCAL_INSTALL: SSL_FRONTEND_HOST = FRONTEND_HOST.replace("http", "https") @@ -486,4 +486,7 @@ if GLOBAL_LOGIN_REQUIRED: r'/api/v[0-9]+/', ] +# if True, only show original, don't perform any action on videos +DO_NOT_TRANSCODE_VIDEO = False + DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' diff --git a/docs/admins_docs.md b/docs/admins_docs.md index a44c571..3c39965 100644 --- a/docs/admins_docs.md +++ b/docs/admins_docs.md @@ -18,7 +18,7 @@ - [15. Debugging email issues](#15-debugging-email-issues) - [16. Frequently Asked Questions](#16-frequently-asked-questions) - [17. Cookie consent code](#17-cookie-consent-code) - +- [18. Disable encoding and show only original file](#18-disable-encoding-and-show-only-original-file) ## 1. Welcome This page is created for MediaCMS administrators that are responsible for setting up the software, maintaining it and making modifications. @@ -762,3 +762,12 @@ this will re-create the sprites for videos that the task failed. On file `templates/components/header.html` you can find a simple cookie consent code. It is commented, so you have to remove the `{% comment %}` and `{% endcomment %}` lines in order to enable it. Or you can replace that part with your own code that handles cookie consent banners. ![Simple Cookie Consent](images/cookie_consent.png) + +## 18. Disable encoding and show only original file +When videos are uploaded, they are getting encoded to multiple resolutions, a procedure called transcoding. Sometimes this is not needed and you only need to show the original file, eg when MediaCMS is running on a low capabilities server. To achieve this, edit settings.py and set + +``` +DO_NOT_TRANSCODE_VIDEO = True +``` + +This will disable the transcoding process and only the original file will be shown. Note that this will also disable the sprites file creation, so you will not have the preview thumbnails on the video player. \ No newline at end of file diff --git a/files/helpers.py b/files/helpers.py index 948c525..5e78c59 100644 --- a/files/helpers.py +++ b/files/helpers.py @@ -538,8 +538,8 @@ def get_base_ffmpeg_command( target_width = round(target_height * 16 / 9) scale_filter_opts = [ - f"if(lt(iw\\,ih)\\,{target_height}\\,{target_width})", - f"if(lt(iw\\,ih)\\,{target_width}\\,{target_height})", + f"if(lt(iw\\,ih)\\,{target_height}\\,{target_width})", # noqa + f"if(lt(iw\\,ih)\\,{target_width}\\,{target_height})", # noqa "force_original_aspect_ratio=decrease", "force_divisible_by=2", "flags=lanczos", diff --git a/files/models.py b/files/models.py index 1d539cc..d46d094 100644 --- a/files/models.py +++ b/files/models.py @@ -430,8 +430,13 @@ class Media(models.Model): self.set_media_type() if self.media_type == "video": self.set_thumbnail(force=True) - self.produce_sprite_from_video() - self.encode() + if settings.DO_NOT_TRANSCODE_VIDEO: + self.encoding_status = "success" + self.save() + self.produce_sprite_from_video() + else: + self.produce_sprite_from_video() + self.encode() elif self.media_type == "image": self.set_thumbnail(force=True) return True @@ -667,6 +672,13 @@ class Media(models.Model): return ret for key in ENCODE_RESOLUTIONS_KEYS: ret[key] = {} + + # if this is enabled, return original file on a way + # that video.js can consume + if settings.DO_NOT_TRANSCODE_VIDEO: + ret['0-original'] = {"h264": {"url": helpers.url_from_path(self.media_file.path), "status": "success", "progress": 100}} + return ret + for encoding in self.encodings.select_related("profile").filter(chunk=False): if encoding.profile.extension == "gif": continue