From 6f01b590e17fad857e6b536d3f018f322c596311 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Jul 2021 10:23:21 +0200 Subject: [PATCH] Add transcoding custom quality plugin --- .../README.md | 3 + .../main.js | 72 +++++++++++++++++++ .../package.json | 20 ++++++ 3 files changed, 95 insertions(+) create mode 100644 peertube-plugin-transcoding-custom-quality/README.md create mode 100644 peertube-plugin-transcoding-custom-quality/main.js create mode 100644 peertube-plugin-transcoding-custom-quality/package.json diff --git a/peertube-plugin-transcoding-custom-quality/README.md b/peertube-plugin-transcoding-custom-quality/README.md new file mode 100644 index 0000000..e949881 --- /dev/null +++ b/peertube-plugin-transcoding-custom-quality/README.md @@ -0,0 +1,3 @@ +# PeerTube transcoding custom quality + +This plugin creates a transcoding profile in which admins can decide the quality of the transcoding process. diff --git a/peertube-plugin-transcoding-custom-quality/main.js b/peertube-plugin-transcoding-custom-quality/main.js new file mode 100644 index 0000000..9626ded --- /dev/null +++ b/peertube-plugin-transcoding-custom-quality/main.js @@ -0,0 +1,72 @@ +async function register ({ + registerSetting, + settingsManager, + transcodingManager +}) { + const defaultCRF = 20 + + const store = { + crf: await settingsManager.getSetting('crf') || defaultCRF + } + + settingsManager.onSettingsChange(settings => { + store.crf = settings['crf'] + }) + + const builderVOD = (options) => { + return { + outputOptions: [ + `-r ${options.fps}`, + `-crf ${store.crf}` + ] + } + } + + const buildLive = (options) => { + return { + outputOptions: [ + `${buildStreamSuffix('-r:v', options.streamNum)} ${fps}`, + `-crf ${store.crf}` + ] + } + } + + registerSetting({ + name: 'crf', + label: 'Quality', + type: 'select', + options: [ + { label: 'Default', value: 23 }, + { label: 'Good', value: 20 }, + { label: 'Very good', value: 18 } + ], + private: true, + default: defaultCRF + }) + + const encoder = 'libx264' + const profileName = 'custom-quality' + + transcodingManager.addVODProfile(encoder, profileName, builderVOD) + transcodingManager.addLiveProfile(encoder, profileName, buildLive) +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + + +// --------------------------------------------------------------------------- + +function buildStreamSuffix (base, streamNum) { + if (streamNum !== undefined) { + return `${base}:${streamNum}` + } + + return base +} diff --git a/peertube-plugin-transcoding-custom-quality/package.json b/peertube-plugin-transcoding-custom-quality/package.json new file mode 100644 index 0000000..c72926e --- /dev/null +++ b/peertube-plugin-transcoding-custom-quality/package.json @@ -0,0 +1,20 @@ +{ + "name": "peertube-plugin-transcoding-custom-quality", + "version": "0.0.1", + "description": "Set a custom quality for transcoding", + "engine": { + "peertube": ">=3.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-transcoding-custom-quality", + "author": "Chocobozzz", + "bugs": "https://framagit.org/framasoft/peertube/official-plugins/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [ ], + "clientScripts": [], + "translations": {} +}