Make video thumbnail position work properly for webms, and make it configurable with new option videoThumbPercentage

merge-requests/208/head
Thomas Lynch 4 years ago
parent 4fa993adc5
commit 23b2858333
  1. 3
      configs/main.js.example
  2. 4
      helpers/files/videothumbnail.js
  3. 19
      models/forms/makepost.js

@ -118,6 +118,9 @@ module.exports = {
//max thumb dimensions (square) in px. images smaller than this are not thumbnailed //max thumb dimensions (square) in px. images smaller than this are not thumbnailed
thumbSize: 250, thumbSize: 250,
//0-100 percent through a video to try taking video thumbnails from, to remedy black first frames or fade-ins
videoThumbPercentage: 5,
/* extra mime types for files to be uploaded as attachments (no thumbnails) e.g. text files/archives /* extra mime types for files to be uploaded as attachments (no thumbnails) e.g. text files/archives
NOTE: appropriate extensions will need to be added to nginx configuration, and uncommend the provided NOTE: appropriate extensions will need to be added to nginx configuration, and uncommend the provided
"other files" section which includes an example configuration for .txt files to match this default config. "other files" section which includes an example configuration for .txt files to match this default config.

@ -2,7 +2,7 @@ const ffmpeg = require('fluent-ffmpeg')
, { thumbSize } = require(__dirname+'/../../configs/main.js') , { thumbSize } = require(__dirname+'/../../configs/main.js')
, uploadDirectory = require(__dirname+'/uploadDirectory.js'); , uploadDirectory = require(__dirname+'/uploadDirectory.js');
module.exports = (file, geometry, frames) => { module.exports = (file, geometry, timestamp) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ffmpeg(`${uploadDirectory}/file/${file.filename}`) ffmpeg(`${uploadDirectory}/file/${file.filename}`)
@ -13,7 +13,7 @@ module.exports = (file, geometry, frames) => {
return reject(err); return reject(err);
}) })
.screenshots({ .screenshots({
timestamps: [(frames === 'N/A' ? 0 : '1%')],//1% should remedy black first frames or fade-ins timestamps: [timestamp],
count: 1, count: 1,
filename: `thumb-${file.hash}${file.thumbextension}`, filename: `thumb-${file.hash}${file.thumbextension}`,
folder: `${uploadDirectory}/file/`, folder: `${uploadDirectory}/file/`,

@ -3,7 +3,7 @@
const path = require('path') const path = require('path')
, { createHash, randomBytes } = require('crypto') , { createHash, randomBytes } = require('crypto')
, randomBytesAsync = require('util').promisify(randomBytes) , randomBytesAsync = require('util').promisify(randomBytes)
, { remove, pathExists } = require('fs-extra') , { remove, pathExists, stat: fsStat } = require('fs-extra')
, uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js') , uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js')
, Mongo = require(__dirname+'/../../db/db.js') , Mongo = require(__dirname+'/../../db/db.js')
, Socketio = require(__dirname+'/../../socketio.js') , Socketio = require(__dirname+'/../../socketio.js')
@ -24,7 +24,8 @@ const path = require('path')
, timeUtils = require(__dirname+'/../../helpers/timeutils.js') , timeUtils = require(__dirname+'/../../helpers/timeutils.js')
, deletePosts = require(__dirname+'/deletepost.js') , deletePosts = require(__dirname+'/deletepost.js')
, spamCheck = require(__dirname+'/../../helpers/checks/spamcheck.js') , spamCheck = require(__dirname+'/../../helpers/checks/spamcheck.js')
, { checkRealMimeTypes, thumbSize, thumbExtension, postPasswordSecret, strictFiltering } = require(__dirname+'/../../configs/main.js') , { checkRealMimeTypes, thumbSize, thumbExtension, videoThumbPercentage,
postPasswordSecret, strictFiltering } = require(__dirname+'/../../configs/main.js')
, buildQueue = require(__dirname+'/../../queue.js') , buildQueue = require(__dirname+'/../../queue.js')
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js') , dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
, { buildThread } = require(__dirname+'/../../helpers/tasks.js'); , { buildThread } = require(__dirname+'/../../helpers/tasks.js');
@ -274,7 +275,19 @@ module.exports = async (req, res, next) => {
await moveUpload(file, processedFile.filename, 'file'); await moveUpload(file, processedFile.filename, 'file');
} }
if (!existsThumb) { if (!existsThumb) {
await videoThumbnail(processedFile, processedFile.geometry, videoData.streams[0].nb_frames); const numFrames = videoData.streams[0].nb_frames;
if (numFrames === 'N/A' && subtype === 'webm') {
await videoThumbnail(processedFile, processedFile.geometry, videoThumbPercentage+'%');
let videoThumbStat = null;
try {
videoThumbStat = await fsStat(`${uploadDirectory}/file/thumb-${processedFile.hash}${processedFile.thumbextension}`);
} catch (err) { /*ENOENT, the thumb failed to create. No need to handle this.*/ }
if (!videoThumbStat || videoThumbStat.size === 0) {
await videoThumbnail(processedFile, processedFile.geometry, 0);
}
} else {
await videoThumbnail(processedFile, processedFile.geometry, ((numFrames === 'N/A' || numFrames <= 1) ? 0 : videoThumbPercentage+'%'));
}
} }
break; break;
} }

Loading…
Cancel
Save