From b11c2f6d31bd3c75154bc003565d7c0186df04a7 Mon Sep 17 00:00:00 2001 From: steev Date: Sat, 14 Oct 2023 22:41:00 +0200 Subject: [PATCH] initial commit --- auflösungen.txt | 10 +++++----- functions/video.js | 12 ++++++++++++ index.js | 8 ++++++++ package-lock.json | 45 +++++++++++++++------------------------------ package.json | 2 +- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/auflösungen.txt b/auflösungen.txt index a109512..56a0ed1 100644 --- a/auflösungen.txt +++ b/auflösungen.txt @@ -1,9 +1,9 @@ -LOW 480 X 270 400kbps -Medium 640 X 360 800kbps -High 960 X 540 1200kbps -HD 1280 x 720 1500kbps +LOW 480 X 270 400kbps +Medium 640 X 360 800kbps +High 960 X 540 1200kbps +HD 1280 x 720 1500kbps FullHD 1920 x 1080 4000kbps -4K 3840 X 2160 8000kbps +4K 3840 X 2160 8000kbps .\ffmpeg.exe -i .\uploads\test.mp4 -vf scale=480:270 -fpsmax 30 -pass 1 -f mp4 -vcodec h264 -b:v 400000 .\proccessed\test\test-270.mp4 .\ffmpeg.exe -i .\uploads\test.mp4 -vf scale=640:360 -fpsmax 30 -pass 1 -f mp4 -vcodec h264 -b:v 800000 .\proccessed\test\test-360.mp4 diff --git a/functions/video.js b/functions/video.js index 9e6a8fb..5b07501 100644 --- a/functions/video.js +++ b/functions/video.js @@ -28,6 +28,18 @@ module.exports = { }); }); }, + 'scaleVideo': (options) => { + ffmpeg(options.inputPath) + .size(`${options.width}x${options.height}`) + .videoBitrate(options.bitrate) + .save(options.outputPath) + .on('end', () => { + console.log('Video resolution and file size have been changed successfully!'); + }) + .on('error', (err) => { + console.log('Error: ' + err.message); + }); + }, /** * encodes video with given parameters * @param {object} options JSON Object passed as settings diff --git a/index.js b/index.js index d58767b..12497d3 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,14 @@ async function performTest(){ video.getVideoInfo("./uploads/test.mp4").then(video => { console.log("Video Size:", video.size, "- duration:", video.durationInSeconds); }); + + video.scaleVideo({ + inputPath: "./uploads/test.mp4", + outputPath: "./proccessed/test-480.mp4", + bitrate: "800k", + width: 640, + height: 480 + }) } performTest(); diff --git a/package-lock.json b/package-lock.json index 163ce1b..7eccb3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "name": "video-encoder", "version": "1.0.0", - "lockfileVersion": 2, + "lockfileVersion": 3, "requires": true, "packages": { "": { @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "ffmpeg": "^0.0.4", "fluent-ffmpeg": "^2.1.2" } }, @@ -17,6 +18,14 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" }, + "node_modules/ffmpeg": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/ffmpeg/-/ffmpeg-0.0.4.tgz", + "integrity": "sha512-3TgWUJJlZGQn+crJFyhsO/oNeRRnGTy6GhgS98oUCIfZrOW5haPPV7DUfOm3xJcHr5q3TJpjk2GudPutrNisRA==", + "dependencies": { + "when": ">= 0.0.1" + } + }, "node_modules/fluent-ffmpeg": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz", @@ -34,6 +43,11 @@ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, + "node_modules/when": { + "version": "3.7.8", + "resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz", + "integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw==" + }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -45,34 +59,5 @@ "which": "bin/which" } } - }, - "dependencies": { - "async": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", - "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" - }, - "fluent-ffmpeg": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz", - "integrity": "sha512-IZTB4kq5GK0DPp7sGQ0q/BWurGHffRtQQwVkiqDgeO6wYJLLV5ZhgNOQ65loZxxuPMKZKZcICCUnaGtlxBiR0Q==", - "requires": { - "async": ">=0.2.9", - "which": "^1.1.1" - } - }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" - }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "requires": { - "isexe": "^2.0.0" - } - } } } diff --git a/package.json b/package.json index 701a463..e25ac35 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "dependencies": { - "fluent-ffmpeg": "^2.1.2" + "ffmpeg": "^0.0.4" } }