Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Forked from tatsuyasusukida/.gitignore
Created June 21, 2023 09:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anhtuank7c/ccdfbf4f73a19715304c10d0ab88cd7d to your computer and use it in GitHub Desktop.
Node.js Docker Image that can uses FFmpeg
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" ]
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)
}
}
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