so good it's almost lossless™
This plugin introduces a transcoding profile with configurable settings for CRF, preset, tune, profile, and custom audio parameters. All the configurations and settings revolve around ffmpeg, providing you with a flexible means to manipulate the transcoding process.
This plugin is a derivative of the peertube-plugin-transcoding-custom-quality
project, developed by Framasoft, specifically Chocobozzz and other Individual Contributors. The original project is licensed under AGPL 3.0.
The following modifications and additions have been made to the original project:
- the default CRF values have been fine-tuned;
- a
profile
option has been added; - a
tune
option has been added; - a
preset
option has been added; - audio-related options have been integrated;
- code linting and formatting.
CRF (Constant Rate Factor) is a setting for the video encoder that balances video quality against file size. The lower the CRF value, the higher the video quality, but also the larger the file size.
In this plugin, the default CRF value is set to 20 for VOD and 21 for live streams.
For more information on CRF, refer to ffmpeg's guide on CRF in H.264.
The profile
option allows you to specify the encoding profile. Not all codecs support all profiles, and not all devices can play all profiles. Setting up the right profile ensures compatibility and efficiency.
The default profile is set to "high
" for both VOD and live streams.
For more details on profiles, refer to ffmpeg's guide on profiles in H.264 and Wikipedia's article on H.264 profiles.
The tune
option helps you optimize the settings for specific types of source material.
While the default tune for VOD is set to nothing, for live streams it is set to "zerolatency
" to reduce encoding latency.
For more information on tune settings, refer to ffmpeg's guide on tune settings in x264
.
The preset
option determines the encoding speed to compression ratio. A slower preset will provide better compression. This means that, given a certain file size or bit rate, using a slower preset will increase quality; or, given a certain quality level, will reduce the bit rate.
The default preset for VOD is "slow
", and for live streams, it's "fast
".
For further details on presets, refer to ffmpeg's guide on presets in x264
.
The plugin provides the ability to apply custom audio configurations during the encoding process. This feature is disabled by default, but can be enabled according to your needs.
The default audio configuration for VOD is "-b:a 320k -filter:a loudnorm=I=-16:TP=-1.0
" (320 kbps bitrate and loudness normalization to -16.0 LUFS and -1.0 dB true peak), and for live streams, it's "-b:a 286k
".
For more insights into audio encoding with ffmpeg, refer to ffmpeg's guide on AAC encoding and ffmpeg's aac
encoder parameters, as well as ffmpeg's guide on audio filters.
Please note that these settings directly influence the ffmpeg command used for encoding, and any changes might disrupt the encoding process, introduce vulnerabilities, or result in unexpected behavior. Therefore, it's crucial to proceed with caution, and to test the settings thoroughly before applying them to a production environment.
To fully utilize the "audio configuration" in this plugin, it might be necessary to disable PeerTube's default behavior of instructing ffmpeg to copy the audio stream, when available. The reason is that this behavior could lead to an error if you attempt to apply audio filtering.
To disable this, you will need to apply a simple patch to PeerTube's source code. The patch removes the check for availability of copying the audio stream from packages/ffmpeg/src/ffmpeg-default-transcoding-profile.ts
at lines 47-49.
Please proceed with caution when modifying the underlying behavior of PeerTube's transcoding process.