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AKI,EAAO,EAAM,KAAK,GACd,SAAS,OACd,KAAK,MACR,GAAG,cAAc,EAAE,GAAI,GAEvB,IAAI,EAAM,mCAAmC,EAAE,2BAA2B,WAC1D,KAAK,GAMrB,OALA,SAAS,SAAS,IACjB,GAAG,IAEJ,EAAE,UAEK,CACR,CAEA,SAAS,aAAa,EAAK,GAC1B,OAAO,KAAK,MAAM,KAAK,UAAY,EAAM,EAAM,IAAM,CACtD,CAEA,SAAS,SAAS,GACjB,IAAI,EAAQ,KAAK,MAAM,EAAU,MAC7B,EAAU,KAAK,OAAO,EAAmB,KAAR,GAAiB,IAClD,EAAU,EAAmB,KAAR,EAA2B,GAAV,EAW1C,OATI,EAAQ,KACX,EAAQ,IAAM,GAEX,EAAU,KACb,EAAU,IAAM,GAEb,EAAU,KACb,EAAU,IAAM,GAEV,EAAQ,IAAM,EAAU,IAAM,CAEtC,CAlHA,OAAO,QAAQ,KAAO,KACtB,OAAO,QAAQ,MAAQ","file":"/npm/video-thumbnail@1.2.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/video-thumbnail@1.2.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var exec = require('child-process-promise').exec\nvar fs = require('fs-extra')\nvar path = require('path')\nvar mkdirp = require('mkdirp')\nvar tmp = require('tmp-promise')\n\nvar ffprobe = require('ffprobe')\nvar which = require('which')\nvar ffopt = {path: which.sync('ffprobe')}\n\nvar chalk = require('chalk')\n\nvar cleanups = [];\n\nfunction divisable(val) {\n\treturn Math.round(val / 2) * 2\n}\nfunction autoscale(w, ow, oh){\n\t// oh/ow: aspect ratio\n\tvar t = Math.round(w*oh/ow)\n\treturn t%2==0 ? t : t+1\n}\n\n//start and duration given in seconds!\nasync function clip(input, output, start, duration, options, originalDims, rotation) {\n\t//if one of options.w or options.h is omitted, autoscale that dimension\n\t//if both are omitted, set w to 300 and h to auto\n\t//if both are given, use those dimensions\n\n\tvar ah = autoscale(300, originalDims.w, originalDims.h)\n\tvar aw = autoscale(300, originalDims.h, originalDims.w)\n\n\tvar w, h\n\n\tif (typeof (options) === 'undefined') {\n\t\tw = h = false\n\t} else {\n\t\tw = typeof (options.width) !== 'undefined'\n\t\th = typeof (options.height) !== 'undefined'\n\t}\n\n\tvar d = {}\n\n\tif (w && h) {\n\t\td.w = options.width\n\t\td.h = options.height\n\t} else if (w) {\n\t\td.w = options.width\n\t\td.h = autoscale(options.width, originalDims.w, originalDims.h)\n\t} else if (h) {\n\t\td.h = autoscale(options.height, originalDims.h, originalDims.w)\n\t\td.h = options.height\n\t} else {\n\t\td.w = 300\n\t\td.h = ah\n\t}\n\t\n\t//swap height and width if video is rotated 90deg\n\tif(rotation == 90){\n\t\t[d.w, d.h] = [d.h, d.w]\n\t}\n\n\tvar cmd = `ffmpeg -y -i '${input}' -ss ${timecode(start)} -t ${timecode(duration)} -r 8 -vf \"scale=${d.w}:${d.h}\" -an -c:v libx264 '${output}'`\n\n\ttry { return exec(cmd) } catch (err) {\n\t\tconsole.log('Error occurred, run this command to debug: ' + cmd)\n\t}\n}\n\nmodule.exports.clip = clip\nmodule.exports.video = video\n\nasync function video(input, output, options) {\n\t//make 5 seconds three times, to temporary files\n\t/*\n\tinput: path,\n\toutput: path,\n\toptions: {\n\t\twidth: number,\n\t\theight: number\n\t}\n\t*/\n\n\tif (typeof (input) !== 'string')\n\t\tthrow ('Input should be a string')\n\ttry { await fs.access(input) }\n\tcatch (er) { throw ('Input file doesn\\'t exist') }\n\n\n\tif (typeof (output) !== 'string') {\n\t\t//if out not given, save under ${inputName}-preview.mp4\n\t\tvar name = path.basename(input, path.extname(input))\n\t\t//mp4 only:\n\t\toutput = path.join(path.dirname(input), name + '-preview.mp4')\n\t\tif(typeof(options.silent) !== 'undefined' && !options.silent)\n\t\tconsole.log(chalk.gray('info: Outputting to ') + chalk.dim.underline(output))\n\t}\n\n\t//make sure the directory to output exists\n\tvar dir = path.dirname(output)\n\ttry { await fs.access(dir) }\n\tcatch (er) { mkdirp.sync(dir) }\n\n\tvar probe = await ffprobe(input, ffopt)\n\tvar info = probe.streams;\n\n    var rotation = parseInt(info[0].tags.rotate)\n    var originalDims = {w: parseInt(info[0].width), h: parseInt(info[0].height)}\n\tvar seconds = parseInt(info[1].duration)\n\n\t//take one clip from the start, one from the middle and one in the end.\n\tvar p = Math.round(seconds / 3)\n\tvar timecodes = [\n\t\tgetRandomInt(0, p),\n\t\tgetRandomInt(p, p * 2),\n\t\tgetRandomInt(p * 2, seconds)\n\t]\n\n\t//holds the temporary paths generated by tmp\n\tvar paths = [];\n\n\t//make clips up to 3 seconds\n\tvar clipLength = Math.min(3, seconds)\n\t//make up to 3 clips (and at least 1)\n\tvar max = Math.min(Math.floor(seconds / clipLength) + 1, 3)\n\tvar promises = []\n\tfor (var i = 0; i < max; i++) {\n\t\tvar o = await tmp.file({\n\t\t\tprefix: 'video-thumbnail-part',\n\t\t\tpostfix: '.mp4',\n\t\t\tdiscardDescriptor: true,\n\t\t\tkeep: true\n\t\t})\n\n\t\tpaths.push(o.path)\n\t\tcleanups.push(o.cleanup)\n\n\t\t//parallelises the rendering by allowing all clips to execute at the same time, then waiting for all of them to finish.\n\t\tpromises.push(clip(input, o.path, timecodes[i], clipLength, options, originalDims, rotation))\n\t}\n\n\tawait Promise.all(promises)\n\t//concat the files into a tmp file\n\tvar o = await tmp.file({\n\t\tprefix: 'video-thumbnail-list',\n\t\tpostfix: '.txt',\n\t\tkeep: true\n\t})\n\tvar data = paths.map((e) => {\n\t\treturn `file '${e}'`\n\t}).join('\\n');\n\tfs.writeFileSync(o.fd, data);\n\n\tvar cmd = `ffmpeg -y -safe 0 -f concat -i '${o.path}' -c:v libx264 -an '${output}'`\n\tvar res = await exec(cmd)\n\tcleanups.forEach((e) => {\n\t\te();\n\t})\n\to.cleanup();\n\n\treturn output\n}\n\nfunction getRandomInt(min, max) {\n\treturn Math.floor(Math.random() * (max - min + 1)) + min;\n}\n\nfunction timecode(sec_num) {\n\tvar hours = Math.floor(sec_num / 3600);\n\tvar minutes = Math.floor((sec_num - (hours * 3600)) / 60);\n\tvar seconds = sec_num - (hours * 3600) - (minutes * 60);\n\n\tif (hours < 10) {\n\t\thours = \"0\" + hours;\n\t}\n\tif (minutes < 10) {\n\t\tminutes = \"0\" + minutes;\n\t}\n\tif (seconds < 10) {\n\t\tseconds = \"0\" + seconds;\n\t}\n\treturn hours + ':' + minutes + ':' + seconds;\n\t//from https://stackoverflow.com/questions/6312993/javascript-seconds-to-time-string-with-format-hhmmss\n}"]}