Skip to content

Commit

Permalink
Add width and height option when create GIF
Browse files Browse the repository at this point in the history
  • Loading branch information
swimmingkiim committed Feb 9, 2023
1 parent 548bf8d commit 746e40c
Show file tree
Hide file tree
Showing 18 changed files with 1,090 additions and 286 deletions.
18 changes: 16 additions & 2 deletions assets/web/js/get_gif.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// ==================== ffmpeg.wasm version ====================

async function getGifFromVideo(path, frameRate, onEnd) {
async function getGifFromVideo(
path,
frameRate,
width,
height,
forceOriginalAspectRatio,
onEnd,
) {
const { createFFmpeg, fetchFile } = FFmpeg;
const ffmpeg = createFFmpeg({
log: true,
Expand All @@ -13,6 +20,8 @@ async function getGifFromVideo(path, frameRate, onEnd) {
await ffmpeg.run(
"-i",
`${currentTime}.avi`,
"-vf",
`scale=w=${width}:h=${height}${forceOriginalAspectRatio ? ':force_original_aspect_ratio=decrease' : ''}`,
"-r",
`${frameRate}`,
"-loop",
Expand All @@ -26,7 +35,10 @@ async function getGifFromVideo(path, frameRate, onEnd) {
async function getGifFromImages(
imagePaths,
frameRate,
onEnd
width,
height,
forceOriginalAspectRatio,
onEnd,
) {
const { createFFmpeg, fetchFile } = FFmpeg;
const currentTime = Date.now();
Expand Down Expand Up @@ -55,6 +67,8 @@ async function getGifFromImages(
await ffmpeg.run(
"-i",
`${currentTime}-${i}.${fileType}`,
"-vf",
`scale=w=${width}:h=${height}${forceOriginalAspectRatio ? ':force_original_aspect_ratio=decrease' : ''}`,
`${currentTime}-${i}.png`
);
const temp = ffmpeg.FS("readFile", `${currentTime}-${i}.png`);
Expand Down
Loading

0 comments on commit 746e40c

Please sign in to comment.