Skip to content

Commit

Permalink
Disable encoding and show only original file (#829)
Browse files Browse the repository at this point in the history
Disable encoding and show only original file #829
  • Loading branch information
mgogoulos authored Nov 10, 2023
1 parent 15d2174 commit e8d3ff2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli-tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@

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")
Expand All @@ -486,4 +486,7 @@
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'
11 changes: 10 additions & 1 deletion docs/admins_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions files/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,13 @@ def media_init(self):
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
Expand Down Expand Up @@ -667,6 +672,13 @@ def encodings_info(self, full=False):
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
Expand Down

0 comments on commit e8d3ff2

Please sign in to comment.