peertube-theme-nctv-dark/peertube-plugin-transcoding-profile-debug/main.js

95 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-01-29 12:57:32 +00:00
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) {
2021-12-14 08:33:44 +00:00
const builder = () => buildResult(profile)
2021-01-29 12:57:32 +00:00
transcodingManager.addVODProfile(profile.encoderName, profile.profileName, builder)
}
for (const profile of profiles.live) {
2021-12-14 08:33:44 +00:00
const builder = () => buildResult(profile)
2021-01-29 12:57:32 +00:00
2021-04-20 06:37:26 +00:00
transcodingManager.addLiveProfile(profile.encoderName, profile.profileName, builder)
2021-01-29 12:57:32 +00:00
}
} 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()
}
2021-12-14 08:33:44 +00:00
function buildResult (profile) {
return {
2021-12-14 09:50:23 +00:00
copy: profile.copy,
2021-12-14 08:33:44 +00:00
outputOptions: profile.outputOptions,
inputOptions: profile.inputOptions,
scaleFilter: profile.scaleFilter
}
}