# syntax=docker/dockerfile:1 # # A small FFmpeg for johnmcm.com's /dav-to-mp4 and /dss-to-mp3, compiled to # WebAssembly: FFmpeg 5.1.6 with only the readers, decoders, encoders and # writers those pages use, plus LAME 3.100 for MP3. Everything here is LGPL # (no --enable-gpl, no GPL libraries). The ffmpeg command-line tool itself is # linked as the program the page runs, one run per conversion, in a worker. # The tarballs built from are published with these files at /source/ffmpeg/. # # ./build.ps1 (or) docker build --target export --output type=local,dest=dist . ARG EMSDK_IMAGE=emscripten/emsdk:6.0.10@sha256:e077d54e2b8970575ebc4f185ac1de0b95c05f2b266134d4ba27449af7aebf65 FROM ${EMSDK_IMAGE} AS build ARG FFMPEG_SHA256=f4fa066278f7a47feab316fef905f4db0d5e9b589451949740f83972b30901bd ARG LAME_SHA256=ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e COPY source/ffmpeg-5.1.6.tar.xz source/lame-3.100.tar.gz /src/ RUN cd /src \ && echo "${FFMPEG_SHA256} ffmpeg-5.1.6.tar.xz" | sha256sum -c - \ && echo "${LAME_SHA256} lame-3.100.tar.gz" | sha256sum -c - \ && tar xf ffmpeg-5.1.6.tar.xz && tar xf lame-3.100.tar.gz # LAME: the library only (no frontend, no decoder). RUN cd /src/lame-3.100 \ && emconfigure ./configure --host=i686-pc-linux-gnu --prefix=/opt --disable-shared --enable-static \ --disable-frontend --disable-gtktest --disable-decoder --disable-analyzer-hooks CFLAGS="-O3" \ && emmake make -j"$(nproc)" \ && emmake make install # FFmpeg: everything off, then the pieces the two pages need. RUN cd /src/ffmpeg-5.1.6 \ && emconfigure ./configure \ --target-os=none --arch=x86_32 --enable-cross-compile \ --cc=emcc --cxx=em++ --ar=emar --ranlib=emranlib --nm=emnm --objcc=emcc --dep-cc=emcc \ --extra-cflags="-O3 -I/opt/include" --extra-ldflags="-L/opt/lib" \ --disable-asm --disable-x86asm --disable-inline-asm --disable-stripping --disable-runtime-cpudetect \ --disable-autodetect --disable-network --disable-doc --disable-debug \ --disable-pthreads --disable-w32threads --disable-os2threads \ --disable-programs --enable-ffmpeg \ --disable-everything --disable-avdevice --disable-postproc --disable-swscale \ --enable-small \ --enable-protocol=file \ --enable-demuxer=dhav,h264,hevc,mpegps,mpegts,mpegvideo,avi,mov,dss,wav,mp3,aac,g726,g726le \ --enable-parser=h264,hevc,aac,mpegaudio,mpeg4video,g723_1 \ --enable-bsf=aac_adtstoasc,extract_extradata,h264_mp4toannexb,hevc_mp4toannexb,null \ --enable-decoder=h264,hevc,pcm_alaw,pcm_mulaw,pcm_s8,pcm_u8,pcm_s16le,pcm_s16be,adpcm_ms,adpcm_g726,adpcm_g726le,adpcm_ima_wav,aac,mp1,mp2,mp3,dss_sp,g723_1,g729,g722 \ --enable-encoder=aac,libmp3lame,pcm_s16le \ --enable-muxer=mp4,mov,ipod,mp3,wav \ --enable-filter=abuffer,abuffersink,buffer,buffersink,aresample,aformat,anull,null,format,volume,afifo,fifo \ --enable-swresample \ --enable-libmp3lame \ && emmake make -j"$(nproc)" \ fftools/ffmpeg.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/ffmpeg_mux.o fftools/ffmpeg_opt.o fftools/cmdutils.o fftools/opt_common.o \ libavfilter/libavfilter.a libavformat/libavformat.a libavcodec/libavcodec.a libswresample/libswresample.a libavutil/libavutil.a # (The H.264 and HEVC decoders are there so FFmpeg can read a stream's picture size and frame # rate from raw .264/.265 and program streams; the video itself is copied, never decoded.) # The ffmpeg program as an ES module: each conversion makes a fresh instance and calls main(). RUN mkdir -p /out && cd /src/ffmpeg-5.1.6 \ && emcc -O3 fftools/ffmpeg.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/ffmpeg_mux.o fftools/ffmpeg_opt.o fftools/cmdutils.o fftools/opt_common.o \ libavfilter/libavfilter.a libavformat/libavformat.a libavcodec/libavcodec.a libswresample/libswresample.a libavutil/libavutil.a \ /opt/lib/libmp3lame.a -lm -lworkerfs.js \ -o /out/ffmpeg.mjs \ -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=createFFmpeg \ -sENVIRONMENT=worker,node \ -sINVOKE_RUN=0 -sEXIT_RUNTIME=1 \ -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=33554432 -sMAXIMUM_MEMORY=4294967296 -sSTACK_SIZE=2097152 \ -sDYNAMIC_EXECUTION=0 -sFORCE_FILESYSTEM=1 \ -sINCOMING_MODULE_JS_API=print,printErr,locateFile,onExit,preRun,wasmBinary,instantiateWasm \ -sEXPORTED_RUNTIME_METHODS=callMain,FS \ && cp COPYING.LGPLv2.1 /out/COPYING.LGPLv2.1 FROM scratch AS export COPY --from=build /out/ /