Commit 2811f758 authored by Jerome Wu's avatar Jerome Wu

Add aom

parent 4e4b74a6
......@@ -28,3 +28,6 @@
[submodule "third_party/theora"]
path = third_party/theora
url = https://github.com/ffmpegwasm/theora
[submodule "third_party/aom"]
path = third_party/aom
url = https://github.com/ffmpegwasm/aom
......@@ -26,6 +26,8 @@ $SCRIPT_ROOT/build-ogg.sh
$SCRIPT_ROOT/build-vorbis.sh
# build theora
$SCRIPT_ROOT/build-theora.sh
# build aom
$SCRIPT_ROOT/build-aom.sh
# configure FFmpeg with Emscripten
$SCRIPT_ROOT/configure-ffmpeg.sh
# build ffmpeg.wasm core
......
Subproject commit bb35ba9148543f22ba7d8642e4fbd29ae301f5dc
#!/bin/bash
set -euo pipefail
source $(dirname $0)/var.sh
LIB_PATH=third_party/aom
CMBUILD_DIR=cmbuild
CFLAGS="-s USE_PTHREADS=1 $OPTIM_FLAGS"
CM_FLAGS=(
-DCMAKE_INSTALL_PREFIX=$BUILD_DIR # assign lib and include install path
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE # use emscripten toolchain file
-DBUILD_SHARED_LIBS=0 # disable shared library build
-DAOM_TARGET_CPU=generic # use generic cpu
-DENABLE_DOCS=0 # disable docs
-DENABLE_TESTS=0 # disable tests
-DENABLE_EXAMPLES=0 # disable examples
-DENABLE_TOOLS=0 # disable tools
-DCONFIG_RUNTIME_CPU_DETECT=0 # disable cpu detect
-DCONFIG_WEBM_IO=0 # disable libwebm support
)
echo "CM_FLAGS=${CM_FLAGS[@]}"
cd $LIB_PATH
rm -rf $CMBUILD_DIR
mkdir -p $CMBUILD_DIR
cd $CMBUILD_DIR
emmake cmake .. \
-DAOM_EXTRA_C_FLAGS="$CFLAGS" \
-DAOM_EXTRA_CXX_FLAGS="$CFLAGS" \
${CM_FLAGS[@]}
emmake make clean
emmake make install -j
cd $ROOT_DIR
#!/bin/bash
set -eo pipefail
source $(dirname $0)/var.sh
mkdir -p wasm/dist
emmake make -j
FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-o wasm/dist/ffmpeg-core.js
-s USE_SDL=2 # use SDL2
-s USE_PTHREADS=1 # enable pthreads support
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
-s INVOKE_RUN=0 # not to run the main() in the beginning
-s EXIT_RUNTIME=1 # exit runtime after execution
-s MODULARIZE=1 # use modularized version to be more flexible
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
$OPTIM_FLAGS
)
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
emcc "${FLAGS[@]}"
......@@ -9,7 +9,7 @@ FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -lx265 -lvpx -lwavpack -lmp3lame -lfdk-aac -lvorbis -lvorbisenc -lvorbisfile -logg -ltheora -ltheoraenc -ltheoradec -pthread
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -lx265 -lvpx -lwavpack -lmp3lame -lfdk-aac -lvorbis -lvorbisenc -lvorbisfile -logg -ltheora -ltheoraenc -ltheoradec -laom -pthread
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-o wasm/dist/ffmpeg-core.js
-s USE_SDL=2 # use SDL2
......
......@@ -6,6 +6,8 @@ source $(dirname $0)/var.sh
FLAGS=(
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
--disable-all
--enable-gpl # required by x264
--enable-libx264 # enable x264
--enable-avcodec
--enable-avformat
--enable-avfilter
......
......@@ -5,6 +5,17 @@ source $(dirname $0)/var.sh
FLAGS=(
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
--enable-gpl # required by x264
--enable-nonfree # required by fdk-aac
--enable-libx264 # enable x264
--enable-libx265 # enable x265
--enable-libvpx # enable libvpx / webm
--enable-libwavpack # enable libwavpack
--enable-libmp3lame # enable libmp3lame
--enable-libfdk-aac # enable libfdk-aac
--enable-libtheora # enable libtheora
--enable-libvorbis # enable libvorbis
--enable-libaom # enable libaom
)
echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
emconfigure ./configure "${FLAGS[@]}"
......@@ -44,16 +44,6 @@ FFMPEG_CONFIG_FLAGS_BASE=(
--disable-stripping # disable stripping
--disable-programs # disable programs build (incl. ffplay, ffprobe & ffmpeg)
--disable-doc # disable doc
--enable-gpl # required by x264
--enable-nonfree # required by fdk-aac
--enable-libx264 # enable x264
--enable-libx265 # enable x265
--enable-libvpx # enable libvpx / webm
--enable-libwavpack # enable libwavpack
--enable-libmp3lame # enable libmp3lame
--enable-libfdk-aac # enable libfdk-aac
--enable-libtheora # enable libtheora
--enable-libvorbis # enable libvorbis
--disable-debug # disable debug info, required by closure
--disable-runtime-cpudetect # disable runtime cpu detect
--disable-autodetect # disable external libraries auto detect
......
<html>
<head>
<style>
html, body {
margin: 0;
width: 100%;
height: 100%
}
body {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
</head>
<body>
<h3>Upload a video to transcode to av1 and play!</h3>
<video id="output-video" controls></video><br/>
<input type="file" id="uploader">
<p id="message">Upload a video</p>
<script type="text/javascript" src="./js/utils.js"></script>
<script type="text/javascript">
const message = document.getElementById('message');
const transcode = async ({ target: { files } }) => {
const IN_FILE_NAME = 'video.avi';
const OUT_FILE_NAME = 'video.mkv';
const args = ['-i', IN_FILE_NAME, '-c:v', 'libaom-av1', '-crf', '48', '-b:v', '0' , '-strict', 'experimental', '-tiles', '2x2', '-row-mt', '1', OUT_FILE_NAME];
message.innerHTML = 'Writing file to MEMFS';
const data = new Uint8Array(await readFromBlobOrFile(files[0]));
const now = Date.now();
console.time(`[${now}] ${files[0].name} execution time`);
message.innerHTML = 'Start to transcode';
const { file } = await runFFmpeg(IN_FILE_NAME, data, args, OUT_FILE_NAME)
const video = document.getElementById('output-video');
video.src = URL.createObjectURL(new Blob([file.buffer], { type: 'video/mp4' }));
console.timeEnd(`[${now}] ${files[0].name} execution time`);
};
document.getElementById('uploader').addEventListener('change', transcode);
</script>
<script type="text/javascript" src="../../dist/ffmpeg-core.js"></script>
</body>
</html>
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mkv';
const FILE_SIZE = 38372;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
/*
* Cannot complete this test as transcoding is extremely slow.
*/
test.skip('transcode avi to av1', async () => {
const args = ['-i', IN_FILE_NAME, '-c:v', 'libaom-av1', '-crf', '48', '-b:v', '0' , '-strict', 'experimental', '-tiles', '2x2', '-row-mt', '1', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(FILE_SIZE);
}, TIMEOUT);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment