Compare commits

..

2 commits

2 changed files with 24 additions and 3 deletions

View file

@ -21,7 +21,7 @@ export default {
.setRequired(false)) .setRequired(false))
.addIntegerOption(option => .addIntegerOption(option =>
option.setName('fps') option.setName('fps')
.setDescription('Change the speed at which the gif play at. Default 20. Number between 1 and 100.') .setDescription('Change the speed at which the gif play at. Number between 1 and 100.')
.setRequired(false)) .setRequired(false))
.addBooleanOption(option => .addBooleanOption(option =>
option.setName('autocrop') option.setName('autocrop')
@ -81,13 +81,18 @@ export default {
await utils.autoCrop(oldOutput, output); await utils.autoCrop(oldOutput, output);
} }
// Get the fps of the original video
if (!args.fps) {
args.fps = getVideoFramerate(output);
}
const gifskiOutput = output.replace(path.extname(output), '.gif'); const gifskiOutput = output.replace(path.extname(output), '.gif');
const gifsicleOutput = output.replace(path.extname(output), 'gifsicle.gif'); const gifsicleOutput = output.replace(path.extname(output), 'gifsicle.gif');
// Extract every frame for gifski // Extract every frame for gifski
await utils.ffmpeg(['-i', output, `${os.tmpdir()}/frame${interaction.id}%04d.png`]); await utils.ffmpeg(['-i', output, `${os.tmpdir()}/frame${interaction.id}%04d.png`]);
// Make it look better // Make it look better
await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`, quality, args.fps); await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`, quality, await args.fps);
// Optimize it // Optimize it
await gifsicle(gifskiOutput, gifsicleOutput, args.noloop); await gifsicle(gifskiOutput, gifsicleOutput, args.noloop);
@ -143,3 +148,19 @@ async function gifsicle(input, output, loop = false) {
}); });
}); });
} }
async function getVideoFramerate(input) {
return await new Promise((resolve, reject) => {
execFile('ffprobe', ['-v', 'error', '-of', 'csv=p=0', '-select_streams', 'v:0', '-show_entries', 'stream=r_frame_rate', input], (err, stdout, stderr) => {
if (err) {
reject(stderr);
}
if (stderr) {
console.error(stderr);
}
const tempfps = stdout.trim().split('/');
const fps = tempfps[0] / tempfps[1];
return resolve(fps);
});
});
}

View file

@ -15,7 +15,7 @@ export default {
}; };
async function downloadVideo(urlArg, output, format = `bestvideo[height<=?${ytdlpMaxResolution}]+bestaudio/best`) { async function downloadVideo(urlArg, output, format = `bestvideo[height<=?${ytdlpMaxResolution}]+bestaudio/best`) {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const options = ['-f', format, urlArg, '-o', `${os.tmpdir()}/${output}.%(ext)s`, '--force-overwrites', '--no-playlist', '--remux-video=mp4/webm/mov', '--no-warnings']; const options = ['-f', format, urlArg, '-o', `${os.tmpdir()}/${output}.%(ext)s`, '--force-overwrites', '--playlist-reverse', '--no-playlist', '--remux-video=mp4/webm/mov', '--no-warnings'];
if (proxy) { if (proxy) {
options.push('--proxy'); options.push('--proxy');
options.push(proxy); options.push(proxy);