diff --git a/peertube-plugin-transcoding-profile-debug/README.md b/peertube-plugin-transcoding-profile-debug/README.md new file mode 100644 index 0000000..28201c6 --- /dev/null +++ b/peertube-plugin-transcoding-profile-debug/README.md @@ -0,0 +1,96 @@ +# Debug PeerTube transcoding profiles + +Allow admins to create custom transcoding profiles using the plugin settings. + +## Settings format + +### Profiles + +**Don't forget the double quotes for fields and values** + +``` +{ + "vod": [ + { + "encoderName": string, + "profileName": string, + "outputOptions": string[] + } + ] + + "live": [ + { + "encoderName": string, + "profileName": string, + "outputOptions": string[] + } + ] +} +``` + +For example: + +``` +{ + "vod": [ + { + "encoderName": "libopus", + "profileName": "test", + "outputOptions": [] + }, + { + "encoderName": "libvpx-vp9", + "profileName": "test", + "outputOptions": [] + } + ], + + "live": [] +} +``` + + +### Encoders priorities + +**Don't forget the double quotes for fields and values** + +``` +{ + "vod": [ + { + "encoderName": string, + "streamType": 'audio' | 'video', + "priority": number + } + ] + + "live": [ + { + "encoderName": string, + "streamType": 'audio' | 'video', + "priority": number + } + ] +} +``` + +For example: + +``` +{ + "vod": [ + { + "encoderName": "libopus", + "streamType": "audio", + "priority": 1000 + }, + { + "encoderName": "libvpx-vp9", + "streamType": "video", + "priority": 1000 + } + ], + + "live": [ ] +} +``` diff --git a/peertube-plugin-transcoding-profile-debug/main.js b/peertube-plugin-transcoding-profile-debug/main.js new file mode 100644 index 0000000..ed28707 --- /dev/null +++ b/peertube-plugin-transcoding-profile-debug/main.js @@ -0,0 +1,93 @@ +async function register ({ + registerSetting, + settingsManager, + transcodingManager, + peertubeHelpers +}) { + registerSetting({ + name: 'transcoding-profiles', + label: 'Transcoding profiles', + type: 'input-textarea', + private: true, + descriptionHTML: 'JSON describing the profiles. See plugin README for the format' + }) + + registerSetting({ + name: 'encoders-priorities', + label: 'Encoders priorities', + type: 'input-textarea', + private: true, + descriptionHTML: 'JSON describing the encoders priorities. See plugin README for the format' + }) + + settingsManager.onSettingsChange(() => update(peertubeHelpers, transcodingManager, settingsManager)) + + update(peertubeHelpers, transcodingManager, settingsManager) +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ############################################################################ + +async function update (peertubeHelpers, transcodingManager, settingsManager) { + removePrevious(transcodingManager) + + const profilesString = await settingsManager.getSetting('transcoding-profiles') + const prioritiesString = await settingsManager.getSetting('encoders-priorities') + + if (profilesString) { + console.log(profilesString.replace(/\n/g, '')) + try { + const profiles = JSON.parse(profilesString) + + for (const profile of profiles.vod) { + const builder = () => { + return { + outputOptions: profile.outputOptions + } + } + + transcodingManager.addVODProfile(profile.encoderName, profile.profileName, builder) + } + + for (const profile of profiles.live) { + const builder = () => { + return { + outputOptions: profile.outputOptions + } + } + + transcodingManager.addVODProfile(profile.encoderName, profile.profileName, builder) + } + } catch (err) { + peertubeHelpers.logger.error('Cannot add profile settings.', { err, profilesString }) + } + } + + if (prioritiesString) { + try { + const priorities = JSON.parse(prioritiesString) + + for (const priority of priorities.vod) { + transcodingManager.addVODEncoderPriority(priority.streamType, priority.encoderName, priority.priority) + } + + for (const priority of priorities.live) { + transcodingManager.addLiveEncoderPriority(priority.streamType, priority.encoderName, priority.priority) + } + } catch (err) { + peertubeHelpers.logger.error('Cannot add priorities settings.', { err, profilesString }) + } + } +} + +async function removePrevious (transcodingManager) { + transcodingManager.removeAllProfilesAndEncoderPriorities() +} diff --git a/peertube-plugin-transcoding-profile-debug/package.json b/peertube-plugin-transcoding-profile-debug/package.json new file mode 100644 index 0000000..6b5b172 --- /dev/null +++ b/peertube-plugin-transcoding-profile-debug/package.json @@ -0,0 +1,20 @@ +{ + "name": "peertube-plugin-transcoding-profile-debug", + "version": "0.0.1", + "description": "Plugin to help developers to debug transcoding profiles", + "engine": { + "peertube": ">=3.1.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-transcoding-profile-debug", + "author": "Chocobozzz", + "bugs": "https://framagit.org/framasoft/peertube/official-plugins/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {} +}