Skip to content

Instantly share code, notes, and snippets.

@tatsuyasusukida
Last active October 30, 2024 00:12
Show Gist options
  • Save tatsuyasusukida/30ccd85375fc7b2adcb3c97e7858cadf to your computer and use it in GitHub Desktop.
Save tatsuyasusukida/30ccd85375fc7b2adcb3c97e7858cadf 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