# syntax=docker/dockerfile:1 # # A small FFmpeg for johnmcm.com's /dav-to-mp4, /dss-to-mp3, /cue-splitter, # /camtasia-to-mp4, the Video Converter's older formats, Video Repair and the Video Cutter's subtitles, # compiled to WebAssembly: FFmpeg 5.1.6 with only the readers, decoders, encoders and writers those # pages use, plus LAME 3.100 for MP3 and zlib 1.3.1 (for TechSmith's first screen codec, TSCC, and # compressed QuickTime headers). FFmpeg and LAME are LGPL, zlib is under the zlib licence # (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 ARG ZLIB_SHA256=9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23 COPY source/ffmpeg-5.1.6.tar.xz source/lame-3.100.tar.gz source/zlib-1.3.1.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 - \ && echo "${ZLIB_SHA256} zlib-1.3.1.tar.gz" | sha256sum -c - \ && tar xf ffmpeg-5.1.6.tar.xz && tar xf lame-3.100.tar.gz && tar xf zlib-1.3.1.tar.gz # zlib: the static library only. RUN cd /src/zlib-1.3.1 \ && CFLAGS="-O3" emconfigure ./configure --static --prefix=/opt \ && emmake make -j"$(nproc)" libz.a \ && emmake make install # 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 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 \ --enable-small \ --enable-zlib \ --enable-protocol=file \ --enable-demuxer=dhav,h264,hevc,mpegps,mpegts,mpegvideo,avi,mov,dss,wav,mp3,aac,g726,g726le,flac,ape,wv,tta,aiff,image2,image_jpeg_pipe,image_png_pipe,asf,flv,live_flv,rm,mxf,wtv,dv,matroska,ogg,amr,ac3,eac3,w64,caf,swf,nut,m4v,vc1,h263,dts,truehd,mlp,webvtt \ --enable-parser=amr,h264,hevc,aac,mpegaudio,mpeg4video,g723_1,flac,mjpeg,png,mpegvideo,vc1,h263,ac3,dca,vorbis,opus,mlp,aac_latm,dvbsub,dvd_nav,vp8,vp9,cook,sipr \ --enable-bsf=aac_adtstoasc,extract_extradata,h264_mp4toannexb,hevc_mp4toannexb,mpeg4_unpack_bframes,null \ --enable-decoder=h264,hevc,tscc,tscc2,zmbv,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,flac,ape,wavpack,tta,alac,pcm_s24le,pcm_s24be,pcm_s32le,pcm_f32le,mpeg1video,mpeg2video,mpeg4,msmpeg4v1,msmpeg4v2,msmpeg4v3,wmv1,wmv2,wmv3,vc1,flv,vp6,vp6a,vp6f,h263,h263i,h263p,rv10,rv20,rv30,rv40,mjpeg,dvvideo,cinepak,msvideo1,indeo3,indeo4,indeo5,theora,vp3,vp8,vp9,svq1,svq3,huffyuv,ffvhuff,rawvideo,prores,dnxhd,qtrle,rpza,smc,mpeg1video,wmav1,wmav2,wmapro,wmavoice,wmalossless,ac3,eac3,cook,ra_144,ra_288,sipr,atrac3,amrnb,amrwb,vorbis,opus,nellymoser,gsm,gsm_ms,qdm2,qdmc,mace3,mace6,dca,truehd,mlp,adpcm_swf,adpcm_ima_qt,adpcm_yamaha,pcm_s16be_planar,pcm_s24daud,pcm_dvd,pcm_bluray,pcm_f64le,pcm_s32be,pcm_f32be,subrip,srt,ass,ssa,webvtt,movtext,text \ --enable-encoder=aac,libmp3lame,zmbv,pcm_s16le,pcm_s24le,flac,alac,rawvideo,webvtt,movtext,srt \ --enable-muxer=mp4,mov,ipod,mp3,wav,flac,rawvideo,webvtt,matroska,webm \ --enable-filter=abuffer,abuffersink,buffer,buffersink,aresample,aformat,anull,null,format,volume,afifo,fifo,atrim,trim,asetpts,amix,alimiter,scale,fps,setsar,yadif,bwdif,pad,crop,transpose,hflip,vflip \ --enable-swscale \ --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 libswscale/libswscale.a libavutil/libavutil.a # (Text subtitles - SubRip, ASS/SSA, WebVTT, MP4 timed text - are read out of MKV and MP4 files as # WebVTT for the Video Cutter, which cuts the cues to match the parts kept; FFmpeg then copies the cut # video into a file with them added: MP4 timed text in MP4 and MOV, SubRip in Matroska, WebVTT in WebM.) # (TechSmith's screen codecs, TSCC (Camtasia 8 and earlier, in AVI) and TSC2 (Camtasia 9 and later, in .trec # MP4s), are decoded for the Camtasia to MP4 page, which hands the pictures to the browser's H.264 encoder as # the Video Converter does. A recording with keyframes far apart is first copied, in one decode, into ZMBV # (DOSBox's lossless screen codec) with a keyframe every few seconds, so the few-seconds-at-a-time passes can # seek in it cheaply. amix mixes a .trec's microphone and system sound tracks into one. # mpeg4_unpack_bframes is for Video Repair, which copies DivX/Xvid AVIs with # "packed B-frames" into MP4s, where they must be unpacked to play.) # (alimiter keeps a loud 5.1 or 7.1 track mixed down to stereo from clipping: the channels summed in # floating point can go past full scale. The amr parser cuts a bare .amr file's 1 KB reads into frames.) # (Cover pictures, JPEG or PNG, are only ever copied into the tracks, so they need readers but no decoders.) # (DAV to MP4 copies H.264 and HEVC and needs the decoders only to read picture size and frame rate. # The older video decoders - MPEG-1/2/4, WMV, VC-1, Flash, RealVideo, DV and the rest - are for the # Video Converter, which has FFmpeg decode old files to raw frames, a few seconds at a time, and the # browser's own encoder make the H.264; the deinterlacers yadif and bwdif are LGPL.) # 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 libswscale/libswscale.a libavutil/libavutil.a \ /opt/lib/libmp3lame.a /opt/lib/libz.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 \ && cp /src/zlib-1.3.1/LICENSE /out/LICENSE.zlib FROM scratch AS export COPY --from=build /out/ /