Add transcoding profile debug plugin
This commit is contained in:
		
							
								
								
									
										96
									
								
								peertube-plugin-transcoding-profile-debug/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								peertube-plugin-transcoding-profile-debug/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -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": [ ] | ||||
| } | ||||
| ``` | ||||
							
								
								
									
										93
									
								
								peertube-plugin-transcoding-profile-debug/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								peertube-plugin-transcoding-profile-debug/main.js
									
									
									
									
									
										Normal file
									
								
							| @ -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() | ||||
| } | ||||
							
								
								
									
										20
									
								
								peertube-plugin-transcoding-profile-debug/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								peertube-plugin-transcoding-profile-debug/package.json
									
									
									
									
									
										Normal file
									
								
							| @ -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": {} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user