Last active
October 30, 2024 00:12
-
-
Save tatsuyasusukida/30ccd85375fc7b2adcb3c97e7858cadf to your computer and use it in GitHub Desktop.
Node.js Docker Image that can uses FFmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/out.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM jrottenberg/ffmpeg:4.1-alpine AS ffmpeg | |
FROM node:lts-alpine | |
# ENV LD_LIBRARY_PATH=/usr/local/lib | |
COPY --from=ffmpeg / / | |
WORKDIR /usr/src/app | |
COPY main.js ./ | |
CMD [ "node", "main.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {spawn} = require('child_process') | |
if (require.main === module) { | |
main() | |
} | |
async function main () { | |
try { | |
const code = await new Promise((resolve, reject) => { | |
const command = 'ffmpeg' | |
const args = ['-version'] | |
const ffmpeg = spawn(command, args) // <1> | |
ffmpeg.stdout.pipe(process.stdout) // <2> | |
ffmpeg.stderr.pipe(process.stderr) | |
ffmpeg.on('exit', code => { // <3> | |
resolve(code) | |
}) | |
ffmpeg.on('error', err => { // <4> | |
reject(err) | |
}) | |
}) | |
console.info(`ffmpeg exit: code = ${code}`) // <5> | |
} catch (err) { | |
console.error(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build: | |
docker image build -t ffmpeg-nodejs-docker . | |
run: | |
docker container run --rm ffmpeg-nodejs-docker | |
sh: | |
docker container run --rm -it -v `pwd`:/usr/src/app ffmpeg-nodejs-docker /bin/sh | |
encode: | |
ffmpeg -i in.mp4 -max_muxing_queue_size 1024 out.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment