]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Merge branch 'release/2.3.0' into develop
authorChocobozzz <me@florianbigard.com>
Fri, 10 Jul 2020 13:23:31 +0000 (15:23 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 10 Jul 2020 13:23:31 +0000 (15:23 +0200)
server/helpers/ffmpeg-utils.ts
server/helpers/image-utils.ts
server/tests/api/videos/video-imports.ts

index 557fb5e3aaf036c0547355aef3c8cc9d1a79876d..0cfc517751a66d94173d92ba8228004769912f7d 100644 (file)
@@ -338,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,
index b1c7d3d476c549c395dbb8ff8207fc469f21d52b..f2f6a004f7ede83514013810f956ab1b73830c7c 100644 (file)
@@ -1,6 +1,7 @@
-import 'multer'
-import { readFile, remove } from 'fs-extra'
+import { remove, rename } from 'fs-extra'
+import { convertWebPToJPG } from './ffmpeg-utils'
 import { logger } from './logger'
+
 const Jimp = require('jimp')
 
 async function processImage (
@@ -15,9 +16,19 @@ async function processImage (
 
   logger.debug('Processing image %s to %s.', path, destination)
 
-  // Avoid sharp cache
-  const buf = await readFile(path)
-  const jimpInstance = await Jimp.read(buf)
+  let jimpInstance: any
+
+  try {
+    jimpInstance = await Jimp.read(path)
+  } catch (err) {
+    logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', { err })
+
+    const newName = path + '.jpg'
+    await convertWebPToJPG(path, newName)
+    await rename(newName, path)
+
+    jimpInstance = await Jimp.read(path)
+  }
 
   await remove(destination)
 
index 335b04b51a74c820d45852e931b9cf47c4c5e84c..05ee36b276982bb4a2df11b0087f0a41291f9488 100644 (file)
@@ -35,7 +35,7 @@ describe('Test video imports', function () {
     expect(videoHttp.name).to.equal('small video - youtube')
     // FIXME: youtube-dl seems broken
     // expect(videoHttp.category.label).to.equal('News & Politics')
-    expect(videoHttp.licence.label).to.equal('Attribution')
+    // expect(videoHttp.licence.label).to.equal('Attribution')
     expect(videoHttp.language.label).to.equal('Unknown')
     expect(videoHttp.nsfw).to.be.false
     expect(videoHttp.description).to.equal('this is a super description')