Reorg folders and use core as ffmpeg from now on
@ -10,6 +10,7 @@ module.exports = {
 | 
			
		||||
    project: [
 | 
			
		||||
      "./tsconfig.eslint.json",
 | 
			
		||||
      "./packages/*/tsconfig.json",
 | 
			
		||||
      "./packages/*/tsconfig-*.json",
 | 
			
		||||
      "./apps/*/tsconfig.json",
 | 
			
		||||
    ],
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,3 @@
 | 
			
		||||
[submodule "testdata"]
 | 
			
		||||
	path = testdata
 | 
			
		||||
	url = https://github.com/ffmpegwasm/testdata
 | 
			
		||||
							
								
								
									
										25
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						@ -1,23 +1,24 @@
 | 
			
		||||
# syntax=docker/dockerfile-upstream:master-labs
 | 
			
		||||
 | 
			
		||||
# Base emsdk image with environment variables.
 | 
			
		||||
FROM emscripten/emsdk:3.1.18 AS emsdk-base
 | 
			
		||||
ARG EXTRA_CFLAGS
 | 
			
		||||
ARG EXTRA_LDFLAGS
 | 
			
		||||
ARG FFMPEG_ST
 | 
			
		||||
ARG FFMPEG_MT
 | 
			
		||||
ENV INSTALL_DIR=/src/build
 | 
			
		||||
ENV FFMPEG_VERSION=n5.1
 | 
			
		||||
ENV X264_BRANCH=stable-wasm
 | 
			
		||||
ENV CFLAGS="$CFLAGS $EXTRA_CFLAGS"
 | 
			
		||||
ENV LDFLAGS="$LDFLAGS $CFLAGS $EXTRA_LDFLAGS"
 | 
			
		||||
ENV EM_PKG_CONFIG_PATH=$EM_PKG_CONFIG_PATH:$INSTALL_DIR/lib/pkgconfig:/emsdk/upstream/emscripten/system/lib/pkgconfig
 | 
			
		||||
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$EM_PKG_CONFIG_PATH
 | 
			
		||||
ENV FFMPEG_ST=$FFMPEG_ST
 | 
			
		||||
ENV FFMPEG_MT=$FFMPEG_MT
 | 
			
		||||
 | 
			
		||||
# Build x264
 | 
			
		||||
FROM emsdk-base AS x264-builder
 | 
			
		||||
RUN git clone \
 | 
			
		||||
      --branch stable \
 | 
			
		||||
      --depth 1 \
 | 
			
		||||
      https://github.com/ffmpegwasm/x264 \
 | 
			
		||||
      /src
 | 
			
		||||
ADD https://github.com/ffmpegwasm/x264.git#$X264_BRANCH /src
 | 
			
		||||
COPY build/x264.sh /src/build.sh
 | 
			
		||||
RUN bash /src/build.sh
 | 
			
		||||
 | 
			
		||||
@ -25,12 +26,8 @@ RUN bash /src/build.sh
 | 
			
		||||
FROM emsdk-base AS ffmpeg-base
 | 
			
		||||
RUN apt-get update && \
 | 
			
		||||
      apt-get install -y pkg-config
 | 
			
		||||
RUN embuilder build sdl2
 | 
			
		||||
RUN git clone \
 | 
			
		||||
      --branch $FFMPEG_VERSION \
 | 
			
		||||
      --depth 1 \
 | 
			
		||||
      https://github.com/FFmpeg/FFmpeg \
 | 
			
		||||
      /src
 | 
			
		||||
RUN embuilder build sdl2 sdl2-mt
 | 
			
		||||
ADD https://github.com/FFmpeg/FFmpeg.git#$FFMPEG_VERSION /src
 | 
			
		||||
COPY --from=x264-builder $INSTALL_DIR $INSTALL_DIR
 | 
			
		||||
 | 
			
		||||
# Build ffmpeg
 | 
			
		||||
@ -38,15 +35,15 @@ FROM ffmpeg-base AS ffmpeg-builder
 | 
			
		||||
COPY build/ffmpeg.sh /src/build.sh
 | 
			
		||||
RUN bash /src/build.sh
 | 
			
		||||
 | 
			
		||||
# Build ffmpeg-core.wasm
 | 
			
		||||
# Build ffmpeg.wasm
 | 
			
		||||
FROM ffmpeg-builder AS ffmpeg-wasm-builder
 | 
			
		||||
COPY src/bind /src/wasm/bind
 | 
			
		||||
COPY src/fftools /src/wasm/fftools
 | 
			
		||||
RUN mkdir -p /src/dist
 | 
			
		||||
COPY build/ffmpeg-wasm.sh build.sh
 | 
			
		||||
# FIXME: find a way to export both entry points in one command.
 | 
			
		||||
RUN bash /src/build.sh -o dist/ffmpeg-core.cjs
 | 
			
		||||
RUN bash /src/build.sh -sEXPORT_ES6 -o dist/ffmpeg-core.js
 | 
			
		||||
RUN bash /src/build.sh -o dist/ffmpeg.cjs
 | 
			
		||||
RUN bash /src/build.sh -sEXPORT_ES6 -o dist/ffmpeg.js
 | 
			
		||||
 | 
			
		||||
# Export ffmpeg-core.wasm to dist/, use `docker buildx build -o . .` to get assets
 | 
			
		||||
FROM scratch AS exportor
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										33
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						@ -1,41 +1,52 @@
 | 
			
		||||
all: dev dev-mt
 | 
			
		||||
all: dev
 | 
			
		||||
 | 
			
		||||
MT_FLAGS := -sUSE_PTHREADS -pthread
 | 
			
		||||
MT_LDFLAGS := -sPTHREAD_POOL_SIZE=8
 | 
			
		||||
 | 
			
		||||
DEV_CFLAGS := --profiling
 | 
			
		||||
DEV_MT_CFLAGS := $(DEV_CFLAGS) $(MT_FLAGS)
 | 
			
		||||
PROD_CFLAGS := -O3 -msimd128
 | 
			
		||||
PROD_MT_CFLAGS := $(PROD_CFLAGS) $(MT_FLAGS)
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -rf ./packages/core$(PKG_SUFFIX)/dist
 | 
			
		||||
	rm -rf ./packages/core$(PKG_SUFFIX)/types
 | 
			
		||||
	rm -rf ./packages/ffmpeg$(PKG_SUFFIX)/dist
 | 
			
		||||
	rm -rf ./packages/ffmpeg$(PKG_SUFFIX)/types
 | 
			
		||||
 | 
			
		||||
.PHONY: build
 | 
			
		||||
build:
 | 
			
		||||
	make clean PKG_SUFFIX="$(PKG_SUFFIX)"
 | 
			
		||||
	cp -r src/types/ffmpeg packages/ffmpeg$(PKG_SUFFIX)/types
 | 
			
		||||
	EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
 | 
			
		||||
	EXTRA_LDLAGS="$(EXTRA_LDLAGS)" \
 | 
			
		||||
	FFMPEG_ST="$(FFMPEG_ST)" \
 | 
			
		||||
	FFMPEG_MT="$(FFMPEG_MT)" \
 | 
			
		||||
		docker buildx build \
 | 
			
		||||
			--build-arg EXTRA_CFLAGS \
 | 
			
		||||
			--build-arg EXTRA_LDLAGS \
 | 
			
		||||
			--build-arg FFMPEG_MT \
 | 
			
		||||
			-o ./packages/core$(PKG_SUFFIX) \
 | 
			
		||||
			--build-arg FFMPEG_ST \
 | 
			
		||||
			-o ./packages/ffmpeg$(PKG_SUFFIX) \
 | 
			
		||||
			$(EXTRA_ARGS) \
 | 
			
		||||
			.
 | 
			
		||||
	cp -r src/types/core packages/core$(PKG_SUFFIX)/types
 | 
			
		||||
 | 
			
		||||
build-st:
 | 
			
		||||
	make build \
 | 
			
		||||
		FFMPEG_ST=yes
 | 
			
		||||
 | 
			
		||||
build-mt:
 | 
			
		||||
	make build \
 | 
			
		||||
		PKG_SUFFIX=-mt \
 | 
			
		||||
		FFMPEG_MT=yes \
 | 
			
		||||
		EXTRA_CFLAGS="-sUSE_PTHREADS -pthread" \
 | 
			
		||||
		EXTRA_LDLAGS="-sPTHREAD_POOL_SIZE=8"
 | 
			
		||||
		EXTRA_LDLAGS="$(MT_LDFLAGS)"
 | 
			
		||||
 | 
			
		||||
dev:
 | 
			
		||||
	make build
 | 
			
		||||
	make build-st EXTRA_CFLAGS="$(DEV_CFLAGS)"
 | 
			
		||||
 | 
			
		||||
dev-mt:
 | 
			
		||||
	make build-mt
 | 
			
		||||
	make build-mt EXTRA_CFLAGS="$(DEV_MT_CFLAGS)"
 | 
			
		||||
 | 
			
		||||
prd:
 | 
			
		||||
	make build EXTRA_CFLAGS="$(PROD_CFLAGS)"
 | 
			
		||||
	make build-st EXTRA_CFLAGS="$(PROD_CFLAGS)"
 | 
			
		||||
 | 
			
		||||
prd-mt:
 | 
			
		||||
	make build-mt EXTRA_CFLAGS="$(PROD_CFLAGS)"
 | 
			
		||||
	make build-mt EXTRA_CFLAGS="$(PROD_MT_CFLAGS)"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								apps/node-ts/ffmpeg/help.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,7 @@
 | 
			
		||||
import createFFmpeg from "@ffmpeg/ffmpeg";
 | 
			
		||||
 | 
			
		||||
void (async () => {
 | 
			
		||||
  const ffmpeg = await createFFmpeg();
 | 
			
		||||
  ffmpeg.setLogger(({ message }) => console.log(message));
 | 
			
		||||
  console.log("return code: ", ffmpeg.exec(["-h"]));
 | 
			
		||||
})();
 | 
			
		||||
							
								
								
									
										17
									
								
								apps/node-ts/ffmpeg/transcode-audio.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,17 @@
 | 
			
		||||
import fs from "node:fs";
 | 
			
		||||
import path from "node:path";
 | 
			
		||||
import createFFmpeg from "@ffmpeg/ffmpeg";
 | 
			
		||||
 | 
			
		||||
void (async () => {
 | 
			
		||||
  const wav = Uint8Array.from(
 | 
			
		||||
    fs.readFileSync(path.join(__dirname, "../../../testdata/audio-15s.wav"))
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const ffmpeg = await createFFmpeg();
 | 
			
		||||
  ffmpeg.setProgress((progress) =>
 | 
			
		||||
    console.log(`transcoding progress: ${progress * 100} %`)
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  ffmpeg.FS.writeFile("audio.wav", wav);
 | 
			
		||||
  console.log("return code: ", ffmpeg.exec(["-i", "audio.wav", "audio.mp4"]));
 | 
			
		||||
})();
 | 
			
		||||
							
								
								
									
										17
									
								
								apps/node-ts/ffmpeg/transcode-video.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,17 @@
 | 
			
		||||
import fs from "node:fs";
 | 
			
		||||
import path from "node:path";
 | 
			
		||||
import createFFmpeg from "@ffmpeg/ffmpeg";
 | 
			
		||||
 | 
			
		||||
void (async () => {
 | 
			
		||||
  const avi = Uint8Array.from(
 | 
			
		||||
    fs.readFileSync(path.join(__dirname, "../../../testdata/video-15s.avi"))
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const ffmpeg = await createFFmpeg();
 | 
			
		||||
  ffmpeg.setProgress((progress) =>
 | 
			
		||||
    console.log(`transcoding progress: ${progress * 100} %`)
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  ffmpeg.FS.writeFile("video.avi", avi);
 | 
			
		||||
  console.log("return code: ", ffmpeg.exec(["-i", "video.avi", "video.mp4"]));
 | 
			
		||||
})();
 | 
			
		||||
@ -1,6 +0,0 @@
 | 
			
		||||
import createFFmpegCore from "@ffmpeg/core-mt";
 | 
			
		||||
 | 
			
		||||
void (async () => {
 | 
			
		||||
  const core = await createFFmpegCore();
 | 
			
		||||
  console.log(core);
 | 
			
		||||
})();
 | 
			
		||||
@ -1,6 +0,0 @@
 | 
			
		||||
import createFFmpegCore from "@ffmpeg/core";
 | 
			
		||||
 | 
			
		||||
void (async () => {
 | 
			
		||||
  const core = await createFFmpegCore();
 | 
			
		||||
  console.log(core);
 | 
			
		||||
})();
 | 
			
		||||
@ -2,20 +2,24 @@
 | 
			
		||||
  "name": "node-ts",
 | 
			
		||||
  "version": "0.0.1",
 | 
			
		||||
  "description": "node example",
 | 
			
		||||
  "main": "index.ts",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "lint": "eslint .",
 | 
			
		||||
    "test": "echo \"Error: no test specified\" && exit 1"
 | 
			
		||||
    "help": "ts-node ffmpeg/help.ts",
 | 
			
		||||
    "transcode:video": "ts-node ffmpeg/transcode-video.ts",
 | 
			
		||||
    "transcode:audio": "ts-node ffmpeg/transcode-audio.ts"
 | 
			
		||||
  },
 | 
			
		||||
  "author": "Jerome Wu <jeromewus@gmail.com>",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@ffmpeg/core": "^0.11.0"
 | 
			
		||||
    "@ffmpeg/core": "^0.11.0",
 | 
			
		||||
    "@ffmpeg/ffmpeg": "^0.11.5",
 | 
			
		||||
    "ts-node": "^10.9.1"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^5.37.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^5.37.0",
 | 
			
		||||
    "eslint": "^8.23.1",
 | 
			
		||||
    "ts-node": "^10.9.1",
 | 
			
		||||
    "typescript": "^4.8.3"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,52 +1,50 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
# `-o <OUTPUT_FILE_NAME>` must be provided when using this build script.
 | 
			
		||||
# ex:
 | 
			
		||||
#     bash ffmpeg-wasm.sh -o ffmpeg.js
 | 
			
		||||
 | 
			
		||||
EXTRA_CONF_FLAGS=(
 | 
			
		||||
  -sINITIAL_MEMORY=32MB
 | 
			
		||||
  -sALLOW_MEMORY_GROWTH
 | 
			
		||||
EXPORT_NAME="createFFmpeg"
 | 
			
		||||
 | 
			
		||||
CONF_FLAGS=(
 | 
			
		||||
  -I. 
 | 
			
		||||
  -I./wasm/fftools 
 | 
			
		||||
  -I$INSTALL_DIR/include 
 | 
			
		||||
  -L$INSTALL_DIR/lib 
 | 
			
		||||
  -Llibavcodec 
 | 
			
		||||
  -Llibavdevice 
 | 
			
		||||
  -Llibavfilter 
 | 
			
		||||
  -Llibavformat 
 | 
			
		||||
  -Llibavutil 
 | 
			
		||||
  -Llibpostproc 
 | 
			
		||||
  -Llibswresample 
 | 
			
		||||
  -Llibswscale 
 | 
			
		||||
  -lavcodec 
 | 
			
		||||
  -lavdevice 
 | 
			
		||||
  -lavfilter 
 | 
			
		||||
  -lavformat 
 | 
			
		||||
  -lavutil 
 | 
			
		||||
  -lpostproc 
 | 
			
		||||
  -lswresample 
 | 
			
		||||
  -lswscale 
 | 
			
		||||
  -lx264 
 | 
			
		||||
  -Wno-deprecated-declarations 
 | 
			
		||||
  $LDFLAGS 
 | 
			
		||||
  -sUSE_SDL=2                              # use emscripten SDL2 lib port
 | 
			
		||||
  -sMODULARIZE                             # modularized to use as a library
 | 
			
		||||
  ${FFMPEG_MT:+ -sINITIAL_MEMORY=1024MB}   # ALLOW_MEMORY_GROWTH is not recommended when using threads, thus we use a large initial memory
 | 
			
		||||
  ${FFMPEG_ST:+ -sINITIAL_MEMORY=32MB -sALLOW_MEMORY_GROWTH} # Use just enough memory as memory usage can grow
 | 
			
		||||
  -sEXPORT_NAME="$EXPORT_NAME"             # required in browser env, so that user can access this module from window.createFFmpeg
 | 
			
		||||
  -sEXPORTED_FUNCTIONS=$(node wasm/bind/ffmpeg/export.js) # exported functions
 | 
			
		||||
  -sEXPORTED_RUNTIME_METHODS=$(node wasm/bind/ffmpeg/export-runtime.js) # exported built-in functions
 | 
			
		||||
  --pre-js wasm/bind/ffmpeg/bind.js        # extra bindings, contains most of the ffmpeg.wasm javascript code
 | 
			
		||||
  # ffmpeg source code
 | 
			
		||||
  wasm/fftools/cmdutils.c 
 | 
			
		||||
  wasm/fftools/ffmpeg.c 
 | 
			
		||||
  wasm/fftools/ffmpeg_filter.c 
 | 
			
		||||
  wasm/fftools/ffmpeg_hw.c 
 | 
			
		||||
  wasm/fftools/ffmpeg_mux.c 
 | 
			
		||||
  wasm/fftools/ffmpeg_opt.c 
 | 
			
		||||
  wasm/fftools/opt_common.c 
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if [[ ! -z "$FFMPEG_MT" ]]; then
 | 
			
		||||
  EXTRA_CONF_FLAGS=(
 | 
			
		||||
    -sINITIAL_MEMORY=1024MB
 | 
			
		||||
  )
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
emcc \
 | 
			
		||||
  -I. \
 | 
			
		||||
  -I./wasm/fftools \
 | 
			
		||||
  -I$INSTALL_DIR/include \
 | 
			
		||||
  -L$INSTALL_DIR/lib \
 | 
			
		||||
  -Llibavcodec \
 | 
			
		||||
  -Llibavdevice \
 | 
			
		||||
  -Llibavfilter \
 | 
			
		||||
  -Llibavformat \
 | 
			
		||||
  -Llibavutil \
 | 
			
		||||
  -Llibpostproc \
 | 
			
		||||
  -Llibswresample \
 | 
			
		||||
  -Llibswscale \
 | 
			
		||||
  -lavcodec \
 | 
			
		||||
  -lavdevice \
 | 
			
		||||
  -lavfilter \
 | 
			
		||||
  -lavformat \
 | 
			
		||||
  -lavutil \
 | 
			
		||||
  -lpostproc \
 | 
			
		||||
  -lswresample \
 | 
			
		||||
  -lswscale \
 | 
			
		||||
  -lx264 \
 | 
			
		||||
  -Wno-deprecated-declarations \
 | 
			
		||||
  $LDFLAGS \
 | 
			
		||||
  -sUSE_SDL=2 \
 | 
			
		||||
  -sMODULARIZE \
 | 
			
		||||
  -sEXPORT_NAME="createFFmpegCore" \
 | 
			
		||||
  -sEXPORTED_FUNCTIONS=$(node wasm/bind/export.js) \
 | 
			
		||||
  -sEXPORTED_RUNTIME_METHODS=$(node wasm/bind/export-runtime.js) \
 | 
			
		||||
  --pre-js wasm/bind/bind.js \
 | 
			
		||||
  wasm/fftools/ffmpeg.c \
 | 
			
		||||
  wasm/fftools/ffmpeg_filter.c \
 | 
			
		||||
  wasm/fftools/ffmpeg_hw.c \
 | 
			
		||||
  wasm/fftools/ffmpeg_mux.c \
 | 
			
		||||
  wasm/fftools/ffmpeg_opt.c \
 | 
			
		||||
  wasm/fftools/cmdutils.c \
 | 
			
		||||
  wasm/fftools/opt_common.c \
 | 
			
		||||
  ${EXTRA_CONF_FLAGS[@]} \
 | 
			
		||||
  $@
 | 
			
		||||
emcc "${CONF_FLAGS[@]}" $@
 | 
			
		||||
 | 
			
		||||
@ -1,37 +1,35 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
EXTRA_CONF_FLAGS=(
 | 
			
		||||
  --disable-pthreads
 | 
			
		||||
  --disable-w32threads
 | 
			
		||||
  --disable-os2threads
 | 
			
		||||
CONF_FLAGS=(
 | 
			
		||||
  --target-os=none              # disable target specific configs
 | 
			
		||||
  --arch=x86_32                 # use x86_32 arch
 | 
			
		||||
  --enable-cross-compile        # use cross compile configs
 | 
			
		||||
  --disable-asm                 # disable asm
 | 
			
		||||
  --disable-stripping           # disable stripping as it won't work
 | 
			
		||||
  --disable-programs            # disable ffmpeg, ffprobe and ffplay build
 | 
			
		||||
  --disable-doc                 # disable doc build
 | 
			
		||||
  --disable-debug               # disable debug mode
 | 
			
		||||
  --disable-runtime-cpudetect   # disable cpu detection
 | 
			
		||||
  --disable-autodetect          # disable env auto detect
 | 
			
		||||
 | 
			
		||||
  # assign toolchains and extra flags
 | 
			
		||||
  --nm="llvm-nm"
 | 
			
		||||
  --ar=emar
 | 
			
		||||
  --ranlib=emranlib
 | 
			
		||||
  --cc=emcc
 | 
			
		||||
  --cxx=em++
 | 
			
		||||
  --objcc=emcc
 | 
			
		||||
  --dep-cc=emcc
 | 
			
		||||
  --extra-cflags="$CFLAGS"
 | 
			
		||||
  --extra-cxxflags="$CFLAGS"
 | 
			
		||||
 | 
			
		||||
  # disable thread when FFMPEG_ST is NOT defined
 | 
			
		||||
  ${FFMPEG_ST:+ --disable-pthreads --disable-w32threads --disable-os2threads}
 | 
			
		||||
 | 
			
		||||
  # extra libraries
 | 
			
		||||
  --enable-gpl
 | 
			
		||||
  --enable-libx264
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if [[ ! -z "$FFMPEG_MT" ]]; then
 | 
			
		||||
  EXTRA_CONF_FLAGS=()
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
emconfigure ./configure \
 | 
			
		||||
  --target-os=none \
 | 
			
		||||
  --arch=x86_32 \
 | 
			
		||||
  --enable-cross-compile \
 | 
			
		||||
  --disable-asm \
 | 
			
		||||
  --disable-stripping \
 | 
			
		||||
  --disable-programs \
 | 
			
		||||
  --disable-doc \
 | 
			
		||||
  --disable-debug \
 | 
			
		||||
  --disable-runtime-cpudetect \
 | 
			
		||||
  --disable-autodetect \
 | 
			
		||||
  --extra-cflags="$CFLAGS" \
 | 
			
		||||
  --extra-cxxflags="$CFLAGS" \
 | 
			
		||||
  --nm="llvm-nm" \
 | 
			
		||||
  --ar=emar \
 | 
			
		||||
  --ranlib=emranlib \
 | 
			
		||||
  --cc=emcc \
 | 
			
		||||
  --cxx=em++ \
 | 
			
		||||
  --objcc=emcc \
 | 
			
		||||
  --dep-cc=emcc \
 | 
			
		||||
  ${EXTRA_CONF_FLAGS[@]} \
 | 
			
		||||
  --enable-gpl \
 | 
			
		||||
  --enable-libx264
 | 
			
		||||
 | 
			
		||||
emconfigure ./configure "${CONF_FLAGS[@]}"
 | 
			
		||||
emmake make -j
 | 
			
		||||
 | 
			
		||||
@ -1,20 +1,16 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
EXTRA_CONF_FLAGS=(
 | 
			
		||||
  --disable-thread
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
 | 
			
		||||
CONF_FLAGS=(
 | 
			
		||||
  --prefix=$INSTALL_DIR           # lib installation dir
 | 
			
		||||
  --host=x86-gnu                  # use x86 linux host
 | 
			
		||||
  --enable-static                 # build static library
 | 
			
		||||
  --disable-cli                   # disable cli build
 | 
			
		||||
  --disable-asm                   # disable assembly
 | 
			
		||||
  --extra-cflags="$CFLAGS"        # add extra cflags
 | 
			
		||||
  ${FFMPEG_ST:+ --disable-thread} # disable thread when FFMPEG_ST is defined
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if [[ ! -z "$FFMPEG_MT" ]]; then
 | 
			
		||||
  EXTRA_CONF_FLAGS=()
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
emconfigure ./configure \
 | 
			
		||||
      --prefix=$INSTALL_DIR \
 | 
			
		||||
      --host=x86-gnu \
 | 
			
		||||
      --enable-static \
 | 
			
		||||
      --disable-cli \
 | 
			
		||||
      --disable-asm \
 | 
			
		||||
      --extra-cflags="$CFLAGS" \
 | 
			
		||||
      ${EXTRA_CONF_FLAGS[@]}
 | 
			
		||||
 | 
			
		||||
emconfigure ./configure "${CONF_FLAGS[@]}"
 | 
			
		||||
emmake make install-lib-static -j
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10923
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						@ -1,50 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@ffmpeg/core-mt",
 | 
			
		||||
  "version": "0.11.0",
 | 
			
		||||
  "description": "ffmpeg.wasm core",
 | 
			
		||||
  "main": "./dist/ffmpeg-core.cjs",
 | 
			
		||||
  "types": "./types/ffmpeg-core.d.ts",
 | 
			
		||||
  "exports": {
 | 
			
		||||
    ".": {
 | 
			
		||||
      "types": "./types/ffmpeg-core.d.ts",
 | 
			
		||||
      "import": "./dist/ffmpeg-core.js",
 | 
			
		||||
      "require": "./dist/ffmpeg-core.cjs"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git+https://github.com/ffmpegwasm/ffmpeg.wasm.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "ffmpeg",
 | 
			
		||||
    "webassembly",
 | 
			
		||||
    "video",
 | 
			
		||||
    "audio",
 | 
			
		||||
    "transcode"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "jeromewus@gmail.com",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://github.com/ffmpegwasm/ffmpeg.wasm/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "homepage": "https://github.com/ffmpegwasm/ffmpeg.wasm#readme",
 | 
			
		||||
  "publishConfig": {
 | 
			
		||||
    "access": "public"
 | 
			
		||||
  },
 | 
			
		||||
  "files": [
 | 
			
		||||
    "dist",
 | 
			
		||||
    "types"
 | 
			
		||||
  ],
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "lint": "eslint types"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@types/emscripten": "^1.39.6"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^5.37.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^5.37.0",
 | 
			
		||||
    "eslint": "^8.23.1",
 | 
			
		||||
    "typescript": "^4.8.3"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,3 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "extends": "../../tsconfig.json"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								packages/core-mt/types/ffmpeg-core.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						@ -1,10 +0,0 @@
 | 
			
		||||
/// <reference types="emscripten" />
 | 
			
		||||
 | 
			
		||||
type Pointer = number;
 | 
			
		||||
type StringArrayPointer = Pointer;
 | 
			
		||||
 | 
			
		||||
interface FFmpegCoreModule extends EmscriptenModule {
 | 
			
		||||
  _ffmpeg: (number, StringArrayPointer) => number;
 | 
			
		||||
}
 | 
			
		||||
declare const createFFmpegCore: EmscriptenModuleFactory<FFmpegCoreModule>;
 | 
			
		||||
export default createFFmpegCore;
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@ffmpeg/core",
 | 
			
		||||
  "version": "0.11.0",
 | 
			
		||||
  "description": "ffmpeg.wasm core",
 | 
			
		||||
  "main": "./dist/ffmpeg-core.cjs",
 | 
			
		||||
  "types": "./types/ffmpeg-core.d.ts",
 | 
			
		||||
  "exports": {
 | 
			
		||||
    ".": {
 | 
			
		||||
      "types": "./types/ffmpeg-core.d.ts",
 | 
			
		||||
      "import": "./dist/ffmpeg-core.js",
 | 
			
		||||
      "require": "./dist/ffmpeg-core.cjs"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git+https://github.com/ffmpegwasm/ffmpeg.wasm.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "ffmpeg",
 | 
			
		||||
    "webassembly",
 | 
			
		||||
    "video",
 | 
			
		||||
    "audio",
 | 
			
		||||
    "transcode"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "jeromewus@gmail.com",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://github.com/ffmpegwasm/ffmpeg.wasm/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "homepage": "https://github.com/ffmpegwasm/ffmpeg.wasm#readme",
 | 
			
		||||
  "publishConfig": {
 | 
			
		||||
    "access": "public"
 | 
			
		||||
  },
 | 
			
		||||
  "files": [
 | 
			
		||||
    "dist",
 | 
			
		||||
    "types"
 | 
			
		||||
  ],
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "lint": "eslint types"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@types/emscripten": "^1.39.6"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^5.37.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^5.37.0",
 | 
			
		||||
    "eslint": "^8.23.1",
 | 
			
		||||
    "typescript": "^4.8.3"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,3 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "extends": "../../tsconfig.json"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2
									
								
								packages/ffmpeg/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,2 @@
 | 
			
		||||
dist/
 | 
			
		||||
types/
 | 
			
		||||
							
								
								
									
										5
									
								
								packages/ffmpeg/jest.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,5 @@
 | 
			
		||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
 | 
			
		||||
module.exports = {
 | 
			
		||||
  preset: 'ts-jest',
 | 
			
		||||
  testEnvironment: 'node',
 | 
			
		||||
};
 | 
			
		||||
@ -2,27 +2,18 @@
 | 
			
		||||
  "name": "@ffmpeg/ffmpeg",
 | 
			
		||||
  "version": "0.11.5",
 | 
			
		||||
  "description": "FFmpeg WebAssembly version",
 | 
			
		||||
  "main": "src/index.js",
 | 
			
		||||
  "types": "src/index.d.ts",
 | 
			
		||||
  "directories": {
 | 
			
		||||
    "example": "examples"
 | 
			
		||||
  "main": "./dist/ffmpeg.cjs",
 | 
			
		||||
  "types": "./types/ffmpeg.d.ts",
 | 
			
		||||
  "exports": {
 | 
			
		||||
    ".": {
 | 
			
		||||
      "types": "./types/ffmpeg.d.ts",
 | 
			
		||||
      "import": "./dist/ffmpeg.js",
 | 
			
		||||
      "require": "./dist/ffmpeg.cjs"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "node scripts/server.js",
 | 
			
		||||
    "start:worker": "node scripts/worker-server.js",
 | 
			
		||||
    "build": "rimraf dist && webpack --config scripts/webpack.config.prod.js",
 | 
			
		||||
    "build:worker": "rimraf dist && webpack --config scripts/webpack.config.worker.prod.js",
 | 
			
		||||
    "prepublishOnly": "npm run build",
 | 
			
		||||
    "wait": "rimraf dist && wait-on http://localhost:3000/dist/ffmpeg.dev.js",
 | 
			
		||||
    "test": "npm-run-all -p -r start test:all",
 | 
			
		||||
    "test:all": "npm-run-all wait test:browser:ffmpeg test:node:all",
 | 
			
		||||
    "test:node": "node node_modules/mocha/bin/_mocha --exit --bail --require ./scripts/test-helper.js",
 | 
			
		||||
    "test:node:all": "npm run test:node -- ./tests/*.test.js",
 | 
			
		||||
    "test:browser": "mocha-headless-chrome -a allow-file-access-from-files -a incognito -a no-sandbox -a disable-setuid-sandbox -a disable-logging -t 300000",
 | 
			
		||||
    "test:browser:ffmpeg": "npm run test:browser -- -f ./tests/ffmpeg.test.html"
 | 
			
		||||
  },
 | 
			
		||||
  "browser": {
 | 
			
		||||
    "./src/node/index.js": "./src/browser/index.js"
 | 
			
		||||
    "lint": "eslint src",
 | 
			
		||||
    "test": "jest"
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
@ -31,7 +22,9 @@
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "ffmpeg",
 | 
			
		||||
    "WebAssembly",
 | 
			
		||||
    "video"
 | 
			
		||||
    "video",
 | 
			
		||||
    "audio",
 | 
			
		||||
    "transcode"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "Jerome Wu <jeromewus@gmail.com>",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
@ -45,16 +38,13 @@
 | 
			
		||||
  "publishConfig": {
 | 
			
		||||
    "access": "public"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "is-url": "^1.2.4",
 | 
			
		||||
    "node-fetch": "^2.6.1",
 | 
			
		||||
    "regenerator-runtime": "^0.13.7",
 | 
			
		||||
    "resolve-url": "^0.2.1"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@types/jest": "^29.0.2",
 | 
			
		||||
    "@typescript-eslint/eslint-plugin": "^5.37.0",
 | 
			
		||||
    "@typescript-eslint/parser": "^5.37.0",
 | 
			
		||||
    "eslint": "^8.23.1",
 | 
			
		||||
    "jest-puppeteer": "^6.1.1",
 | 
			
		||||
    "ts-jest": "^29.0.1",
 | 
			
		||||
    "typescript": "^4.8.3"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								packages/ffmpeg/tests/ffmpeg.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,34 @@
 | 
			
		||||
import type { FFmpegModule } from "..";
 | 
			
		||||
import createFFmpeg from "..";
 | 
			
		||||
 | 
			
		||||
let core: FFmpegModule;
 | 
			
		||||
 | 
			
		||||
beforeAll(async () => {
 | 
			
		||||
  core = await createFFmpeg();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe("core", () => {
 | 
			
		||||
  test("core is ready", () => {
 | 
			
		||||
    expect(core).not.toBeUndefined();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test("core functions are exported", () => {
 | 
			
		||||
    expect("NULL" in core).toBeTruthy();
 | 
			
		||||
    expect("SIZE_I32" in core).toBeTruthy();
 | 
			
		||||
    expect("exec" in core).toBeTruthy();
 | 
			
		||||
    expect("stringToPtr" in core).toBeTruthy();
 | 
			
		||||
    expect("stringsToPtr" in core).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe("stringToPtr()", () => {
 | 
			
		||||
  test("convert a string to pointer", () => {
 | 
			
		||||
    expect(core.stringToPtr("string")).not.toBe(core.NULL);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe("stringsToPtr()", () => {
 | 
			
		||||
  test("convert a string array to pointer", () => {
 | 
			
		||||
    expect(core.stringsToPtr(["string"])).not.toBe(core.NULL);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										2
									
								
								packages/ffprobe-mt/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,2 @@
 | 
			
		||||
dist/
 | 
			
		||||
types/
 | 
			
		||||
							
								
								
									
										2
									
								
								packages/ffprobe/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,2 @@
 | 
			
		||||
dist/
 | 
			
		||||
types/
 | 
			
		||||
| 
		 Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB  | 
| 
		 Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB  | 
| 
		 Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB  | 
| 
		 Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB  | 
| 
		 Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB  | 
| 
		 Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB  | 
| 
		 Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB  | 
| 
		 Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB  | 
| 
		 Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB  | 
| 
		 Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB  |