Skip to content

feat: Introduce new transcoding options in settings#1471

Open
mrjoshuap wants to merge 3 commits intomediacms-io:mainfrom
mrjoshuap:feat/conditional-transcoding
Open

feat: Introduce new transcoding options in settings#1471
mrjoshuap wants to merge 3 commits intomediacms-io:mainfrom
mrjoshuap:feat/conditional-transcoding

Conversation

@mrjoshuap
Copy link
Copy Markdown
Contributor

Conditional Transcoding Options

Description

Summary

This PR implements conditional video transcoding options as discussed in #1375. The feature allows administrators to configure when videos should be transcoded based on file size or format, rather than transcoding all videos or none.

Problem

Previously, MediaCMS only supported two transcoding modes:

  • DO_NOT_TRANSCODE_VIDEO = False: Transcode all videos (wastes storage on small videos that play fine)
  • DO_NOT_TRANSCODE_VIDEO = True: Transcode no videos (larger files cause playback issues)

This binary approach doesn't accommodate scenarios where:

  • Most videos are small (30-500 MB) and play fine without transcoding
  • Occasional large videos (2-3 GB) need transcoding for smooth playback

Solution

Introduces a flexible TRANSCODING_OPTIONS setting with multiple modes:

  • 'always' (default): Always transcode videos (maintains backward compatibility)
  • 'never': Never transcode videos (same as DO_NOT_TRANSCODE_VIDEO = True)
  • 'file_size_gt': Only transcode videos larger than TRANSCODING_OPTIONS_FILESIZE threshold
  • 'file_size_lt': Only transcode videos smaller than TRANSCODING_OPTIONS_FILESIZE threshold
  • 'non_mp4_only': Only transcode videos that are not in MP4 format

Changes

  • Added TRANSCODING_OPTIONS setting with default value 'always'
  • Added TRANSCODING_OPTIONS_FILESIZE setting (default: 1000 MB) for size-based conditions
  • Implemented should_transcode_video() helper function with conditional logic
  • Updated Media model to check transcoding options before processing
  • Modified video encoding status handling to allow videos without transcoded versions
  • Ensured backward compatibility with existing DO_NOT_TRANSCODE_VIDEO setting
  • Updated documentation in docs/transcoding.md

Configuration Example

# Only transcode videos larger than 1GB
TRANSCODING_OPTIONS = 'file_size_gt'
TRANSCODING_OPTIONS_FILESIZE = 1000  # MB

# Only transcode non-MP4 videos
TRANSCODING_OPTIONS = 'non_mp4_only'

# Never transcode (same as DO_NOT_TRANSCODE_VIDEO = True)
TRANSCODING_OPTIONS = 'never'

Backward Compatibility

  • Existing installations continue to work with default 'always' behavior
  • DO_NOT_TRANSCODE_VIDEO setting is still respected and takes precedence
  • No database migrations required

Testing

  • [] Videos with 'always' option are transcoded
  • [] Videos with 'never' option skip transcoding
  • [] Videos larger than threshold with 'file_size_gt' are transcoded
  • [] Videos smaller than threshold with 'file_size_gt' skip transcoding
  • [] Non-MP4 videos with 'non_mp4_only' are transcoded
  • [] MP4 videos with 'non_mp4_only' skip transcoding
  • [] Backward compatibility with DO_NOT_TRANSCODE_VIDEO maintained

- Added TRANSCODING_OPTIONS to control video transcoding behavior with options: 'always', 'never', 'file_size_gt', 'file_size_lt', and 'non_mp4_only'.
- Introduced TRANSCODING_OPTIONS_FILESIZE to set file size thresholds for transcoding.
- Updated should_transcode_video function to utilize new settings for improved transcoding logic.
- Modified Media model to check transcoding options before processing videos, ensuring backward compatibility with DO_NOT_TRANSCODE_VIDEO.
- Introduced DELETE_ORIGINAL_VIDEO_IF_TRANSCODED setting to control deletion of original video files post-transcoding.
- Updated Media model to implement logic for deleting original files based on transcoding success and completion of all encodings.
- Enhanced documentation to reflect the new setting and its implications for storage management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant