diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..5aadcd3 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +17.3.0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ac8c73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM ubuntu:18.04 + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata +RUN apt-get install build-essential wget pkg-config xvfb libxi-dev libglu1-mesa-dev libglew-dev libvips-dev -y --no-install-recommends + +# install ffmpeg +RUN wget --no-check-certificate -O /tmp/ffmpeg.tar.xz \ + "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-$(dpkg --print-architecture)-static.tar.xz" \ + && mkdir /usr/local/ffmpeg && cd /usr/local/ffmpeg && tar xvf /tmp/ffmpeg.tar.xz --strip-components=1 +ENV PATH=/usr/local/ffmpeg:$PATH + +# upgrade vips +ARG VIPS_VERSION="8.12.1" +RUN cd /tmp && wget --no-check-certificate \ + "https://github.com/libvips/libvips/releases/download/v$VIPS_VERSION/vips-$VIPS_VERSION.tar.gz" && \ + tar zxvf vips* && cd vips-$VIPS_VERSION && ./configure && make && make install && ldconfig +ENV LD_LIBRARY_PATH=/usr/local/lib +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig +ENV GI_TYPELIB_PATH=/usr/lib/$(arch)-linux-gnu/girepository-1.0:/usr/lib/girepository-1.0 + +# install nodejs +WORKDIR /app +ADD .nvmrc /app/.nvmrc +RUN wget --no-check-certificate \ + "https://nodejs.org/dist/v$(cat .nvmrc)/node-v$(cat .nvmrc)-linux-$( \ + [ $(dpkg --print-architecture) = amd64 ] && echo x64 || dpkg --print-architecture).tar.gz" \ + -O /tmp/node.tar.gz \ + && tar -xf /tmp/node.tar.gz -C /usr/local --strip-components=1 \ + && rm /tmp/node.tar.gz + +ADD package*.json /app +RUN npm install + +ADD *.js *.sh /app/ +ADD lib /app/lib +ADD media /app/media + +RUN ln -s /app/lib/cli.js /usr/local/bin/ffmpeg-concat + +ENTRYPOINT ["/app/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..d6678c3 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +CMD_PREPEND="ffmpeg-concat" +PATTERN="^\s*(npm|npx|node|ffmpeg|sh|bash).*$" +if [[ $# == 0 ]]; then + CMD_PREPEND="ffmpeg-concat --help" +elif [[ "$1" =~ $PATTERN ]]; then + CMD_PREPEND="" +fi + +echo Running: exec xvfb-run -s "-ac -screen 0 1280x1024x24" \ + $CMD_PREPEND "$@" +exec xvfb-run -s "-ac -screen 0 1280x1024x24" \ + $CMD_PREPEND "$@" \ No newline at end of file diff --git a/package.json b/package.json index fefa548..0d2dcf7 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,10 @@ "node": ">=10.13.0" }, "scripts": { - "test": "ava -v && standard" + "test": "ava -v && standard", + "docker-build": "docker build . -t ffmpeg-concat", + "docker-test": "docker build . -t ffmpeg-concat && docker run --init ffmpeg-concat npm run test", + "docker": "docker run --init -v \"${DIR:-$(pwd)}:/vids\" -w /vids ffmpeg-concat" }, "keywords": [ "ffmpeg", @@ -47,7 +50,7 @@ "p-map": "^2.0.0", "p-race": "^2.0.0", "rmfr": "^2.0.0", - "sharp": "^0.24.0", + "sharp": "^0.29.3", "tempy": "^0.2.1", "url-parse": "^1.4.4" }, diff --git a/readme.md b/readme.md index 2de6474..86e42a9 100644 --- a/readme.md +++ b/readme.md @@ -35,6 +35,30 @@ This package runs on Linux, macOS, and Windows. Node.js versions 10.13.0 and up are supported. Note (**macOS only**): due to an inadvertant low-level breaking change in libuv's process handling code, OpenGL [is not supported](https://github.com/stackgl/headless-gl#supported-platforms-and-nodejs-versions) when running Node.js version 12.13.1 through to 13.6.0 on macOS. A fix has been released in Node.js version 13.7.0. A fix for 12.x is pending. Other platforms are unaffected. +### Docker + +A multi-platform and multi-arch Docker image can be used for debugging and cross platform needs (requires [Docker](https://www.docker.com/) installed), as well as avoiding requiring `ffmpeg` and node dependencies installed locally. + +Docker image build: +```bash +npm run docker-build +``` + +After image is built, some `docker run` examples: +```bash +# run tests in docker container +npm run docker-test +# print CLI options +npm run docker +npm run docker -- --help +# run on this repo's sample files in container +npm run docker -- media/0.mp4 media/1.mp4 +# run with host machine files (make sure Docker has access / permissions) +DIR=/path/to/vids/dir npm run docker -- file1.mov file2.avi +``` + +See [package.json](./package.json), and [Dockerfile](./Dockerfile) for more details. + ## CLI ```sh