]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/ffmpeg-utils.ts
Update my-account sub-menus icons (#2977)
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg-utils.ts
index e0e408ea025436f2deab558977a8d2354b452954..0cfc517751a66d94173d92ba8228004769912f7d 100644 (file)
@@ -125,7 +125,8 @@ async function getVideoStreamCodec (path: string) {
     baseProfile = baseProfileMatrix['High'] // Fallback
   }
 
-  const level = videoStream.level.toString(16)
+  let level = videoStream.level.toString(16)
+  if (level.length === 1) level = `0${level}`
 
   return `${videoCodec}.${baseProfile}${level}`
 }
@@ -337,11 +338,29 @@ function getClosestFramerateStandard (fps: number, type: 'HD_STANDARD' | 'STANDA
                                     .sort((a, b) => fps % a - fps % b)[0]
 }
 
+function convertWebPToJPG (path: string, destination: string): Promise<void> {
+  return new Promise<void>(async (res, rej) => {
+    try {
+      const command = ffmpeg(path).output(destination)
+
+      command.on('error', (err, stdout, stderr) => {
+        logger.error('Error in ffmpeg webp convert process.', { stdout, stderr })
+        return rej(err)
+      })
+      .on('end', () => res())
+      .run()
+    } catch (err) {
+      return rej(err)
+    }
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   getVideoStreamCodec,
   getAudioStreamCodec,
+  convertWebPToJPG,
   getVideoStreamSize,
   getVideoFileResolution,
   getMetadataFromFile,
@@ -422,6 +441,7 @@ async function buildHLSCommand (command: ffmpeg.FfmpegCommand, options: HLSTrans
   const videoPath = getHLSVideoPath(options)
 
   if (options.copyCodecs) command = presetCopy(command)
+  else if (options.resolution === VideoResolution.H_NOVIDEO) command = presetOnlyAudio(command)
   else command = await buildx264Command(command, options)
 
   command = command.outputOption('-hls_time 4')