Commit 1099b3f5 authored by Jerome Wu's avatar Jerome Wu

Fix pkg-config and x265 multilib issue

parent 6f5211d1
...@@ -43,6 +43,7 @@ If nothing goes wrong, you can find JavaScript files in `wasm/dist`. ...@@ -43,6 +43,7 @@ If nothing goes wrong, you can find JavaScript files in `wasm/dist`.
#### Video #### Video
- x264 (mp4): 0.160.x - x264 (mp4): 0.160.x
- x265 (mp4): 3.4 (only works with `-pix_fmt yuv420p10le` and `-pix_fmt yuv420p12le`)
- libvpx (webm): 1.9.0 - libvpx (webm): 1.9.0
#### Audio #### Audio
......
...@@ -10,8 +10,8 @@ emcc -v ...@@ -10,8 +10,8 @@ emcc -v
$SCRIPT_ROOT/install-deps.sh $SCRIPT_ROOT/install-deps.sh
# build x264 # build x264
$SCRIPT_ROOT/build-x264.sh $SCRIPT_ROOT/build-x264.sh
# build x265 (WIP) # build x265
# $SCRIPT_ROOT/build-x265.sh $SCRIPT_ROOT/build-x265.sh
# build libvpx # build libvpx
$SCRIPT_ROOT/build-libvpx.sh $SCRIPT_ROOT/build-libvpx.sh
# build WavPack # build WavPack
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
# Copyright (c) 2005-2008 Mans Rullgard # Copyright (c) 2005-2008 Mans Rullgard
# #
# Set PKG_CONFIG_PATH manually
export PKG_CONFIG_PATH=/src/build/lib/pkgconfig
# Prevent locale nonsense from breaking basic text processing. # Prevent locale nonsense from breaking basic text processing.
LC_ALL=C LC_ALL=C
export LC_ALL export LC_ALL
......
...@@ -9,7 +9,7 @@ FLAGS=( ...@@ -9,7 +9,7 @@ FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include -I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib -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 -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 -lvpx -lwavpack -lmp3lame -lfdk-aac -pthread -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -lx265 -lvpx -lwavpack -lmp3lame -lfdk-aac -pthread
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-o wasm/dist/ffmpeg-core.js -o wasm/dist/ffmpeg-core.js
-s USE_SDL=2 # use SDL2 -s USE_SDL=2 # use SDL2
......
...@@ -4,13 +4,14 @@ set -euo pipefail ...@@ -4,13 +4,14 @@ set -euo pipefail
source $(dirname $0)/var.sh source $(dirname $0)/var.sh
LIB_PATH=third_party/vorbis LIB_PATH=third_party/vorbis
CFLAGS="-s USE_PTHREADS=1 $OPTIM_FLAGS -I$BUILD_DIR/include -Qunused-arguments" CFLAGS="-s USE_PTHREADS=1 $OPTIM_FLAGS -I$BUILD_DIR/include"
LDFLAGS="-L$BUILD_DIR/lib" LDFLAGS="-L$BUILD_DIR/lib"
CONF_FLAGS=( CONF_FLAGS=(
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include --prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-linux # use i686 linux --host=i686-linux # use i686 linux
--disable-shared # disable shared library --enable-shared=no # disable shared library
--disable-oggtest # disable tests --disable-oggtest # disable tests
--enable-fast-install=no
) )
echo "CONF_FLAGS=${CONF_FLAGS[@]}" echo "CONF_FLAGS=${CONF_FLAGS[@]}"
(cd $LIB_PATH && \ (cd $LIB_PATH && \
......
...@@ -4,15 +4,75 @@ set -euo pipefail ...@@ -4,15 +4,75 @@ set -euo pipefail
source $(dirname $0)/var.sh source $(dirname $0)/var.sh
LIB_PATH=third_party/x265/source LIB_PATH=third_party/x265/source
CONF_FLAGS=( CXXFLAGS="-s USE_PTHREADS=1 $OPTIM_FLAGS"
-DCMAKE_INSTALL_PREFIX=$BUILD_DIR BASE_FLAGS=(
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE
-DENABLE_SHARED:bool=off -DENABLE_LIBNUMA=OFF
-DENABLE_CLI:bool=off -DENABLE_SHARED=OFF
-DENABLE_CLI=OFF
) )
echo "CONF_FLAGS=${CONF_FLAGS[@]}"
rm -rf $LIB_PATH/build FLAGS_12BIT=(
mkdir -p $LIB_PATH/build ${BASE_FLAGS[@]}
(cd $LIB_PATH/build && emmake cmake .. "${CONF_FLAGS[@]}") -DHIGH_BIT_DEPTH=ON
emmake make -C $LIB_PATH/build clean -DEXPORT_C_API=OFF
emmake make -C $LIB_PATH/build install -j -DMAIN12=ON
)
FLAGS_10BIT=(
${BASE_FLAGS[@]}
-DHIGH_BIT_DEPTH=ON
-DEXPORT_C_API=OFF
)
FLAGS_MAIN=(
${BASE_FLAGS[@]}
-DEXTRA_LIB="x265_main10.a;x265_main12.a"
-DEXTRA_LINK_FLAGS=-L.
-DLINKED_10BIT=ON
-DLINKED_12BIT=ON
)
cd $LIB_PATH
rm -rf build
mkdir -p build
cd build
mkdir -p main 10bit 12bit
cd 12bit
emmake cmake ../.. -DCMAKE_CXX_FLAGS="$CXXFLAGS" ${FLAGS_12BIT[@]}
emmake make -j
cd ../10bit
emmake cmake ../.. -DCMAKE_CXX_FLAGS="$CXXFLAGS" ${FLAGS_10BIT[@]}
emmake make -j
cd ../main
ln -sf ../10bit/libx265.a libx265_main10.a
ln -sf ../12bit/libx265.a libx265_main12.a
emmake cmake ../.. -DCMAKE_CXX_FLAGS="$CXXFLAGS" ${FLAGS_MAIN[@]}
emmake make -j
mv libx265.a libx265_main.a
# Merge static libraries
emar -M <<EOF
CREATE libx265.a
ADDLIB libx265_main.a
ADDLIB libx265_main10.a
ADDLIB libx265_main12.a
SAVE
END
EOF
# Copy files to build directory
mkdir -p $BUILD_DIR
mkdir -p $BUILD_DIR/include
mkdir -p $BUILD_DIR/lib
mkdir -p $BUILD_DIR/lib/pkgconfig
cp x265_config.h $BUILD_DIR/include
cp ../../x265.h $BUILD_DIR/include
cp libx265.a $BUILD_DIR/lib
cp x265.pc $BUILD_DIR/lib/pkgconfig
cd $ROOT_DIR
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
cmds=() cmds=()
# Detect what dependencies are missing. # Detect what dependencies are missing.
for cmd in autoconf automake libtool for cmd in autoconf automake libtool pkg-config
do do
if ! command -v $cmd &> /dev/null if ! command -v $cmd &> /dev/null
then then
......
...@@ -24,8 +24,11 @@ fi ...@@ -24,8 +24,11 @@ fi
# Convert array to string # Convert array to string
OPTIM_FLAGS="${OPTIM_FLAGS[@]}" OPTIM_FLAGS="${OPTIM_FLAGS[@]}"
# Root directory
ROOT_DIR=$PWD
# Directory to install headers and libraries # Directory to install headers and libraries
BUILD_DIR=$PWD/build BUILD_DIR=$ROOT_DIR/build
# Toolchain file path for cmake # Toolchain file path for cmake
TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
...@@ -44,6 +47,7 @@ FFMPEG_CONFIG_FLAGS_BASE=( ...@@ -44,6 +47,7 @@ FFMPEG_CONFIG_FLAGS_BASE=(
--enable-gpl # required by x264 --enable-gpl # required by x264
--enable-nonfree # required by fdk-aac --enable-nonfree # required by fdk-aac
--enable-libx264 # enable x264 --enable-libx264 # enable x264
--enable-libx265 # enable x265
--enable-libvpx # enable libvpx / webm --enable-libvpx # enable libvpx / webm
--enable-libwavpack # enable libwavpack --enable-libwavpack # enable libwavpack
--enable-libmp3lame # enable libmp3lame --enable-libmp3lame # enable libmp3lame
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</style> </style>
</head> </head>
<body> <body>
<h3>Upload a video to transcode to mp4 (x265) and play!</h3> <h3>Upload a video to transcode to mp4 (x265)!</h3>
<video id="output-video" controls></video><br/> <video id="output-video" controls></video><br/>
<input type="file" id="uploader"> <input type="file" id="uploader">
<p id="message">Upload a video</p> <p id="message">Upload a video</p>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
const transcode = async ({ target: { files } }) => { const transcode = async ({ target: { files } }) => {
const IN_FILE_NAME = 'video.avi'; const IN_FILE_NAME = 'video.avi';
const OUT_FILE_NAME = 'video.mp4'; const OUT_FILE_NAME = 'video.mp4';
const args = ['-i', IN_FILE_NAME, '-c:v', 'libx265', '-c:a', 'copy', OUT_FILE_NAME]; const args = ['-i', IN_FILE_NAME, '-c:v', 'libx265', '-pix_fmt', 'yuv420p10le', '-c:a', 'copy', OUT_FILE_NAME];
message.innerHTML = 'Writing file to MEMFS'; message.innerHTML = 'Writing file to MEMFS';
const data = new Uint8Array(await readFromBlobOrFile(files[0])); const data = new Uint8Array(await readFromBlobOrFile(files[0]));
const now = Date.now(); const now = Date.now();
......
module.exports = { module.exports = {
TIMEOUT: 30000, TIMEOUT: 60000,
}; };
...@@ -21,6 +21,7 @@ const ffmpeg = (Core, args) => { ...@@ -21,6 +21,7 @@ const ffmpeg = (Core, args) => {
const runFFmpeg = async (ifilename, data, args, ofilename) => { const runFFmpeg = async (ifilename, data, args, ofilename) => {
let resolve = null; let resolve = null;
let file = null;
let fileSize = -1; let fileSize = -1;
const Core = await createFFmpegCore({ const Core = await createFFmpegCore({
printErr: () => {}, printErr: () => {},
...@@ -34,10 +35,11 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => { ...@@ -34,10 +35,11 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => {
ffmpeg(Core, args); ffmpeg(Core, args);
await new Promise((_resolve) => { resolve = _resolve }); await new Promise((_resolve) => { resolve = _resolve });
if (typeof ofilename !== 'undefined') { if (typeof ofilename !== 'undefined') {
fileSize = Core.FS.readFile(ofilename).length; file = Core.FS.readFile(ofilename);
fileSize = file.length;
Core.FS.unlink(ofilename); Core.FS.unlink(ofilename);
} }
return { Core, fileSize }; return { Core, file, fileSize };
}; };
module.exports = { module.exports = {
......
...@@ -4,15 +4,23 @@ const { TIMEOUT } = require('./config'); ...@@ -4,15 +4,23 @@ const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils'); const { runFFmpeg } = require('./utils');
const IN_FILE_NAME = 'video-1s.avi'; const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4'; const OUT_FILE_NAME = 'video.mp4';
const MP4_SIZE = 38372; const MP4_10BIT_SIZE1 = 22507;
const MP4_10BIT_SIZE2 = 22520;
const MP4_12BIT_SIZE = 22718;
let aviData = null; let aviData = null;
beforeAll(() => { beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME))); aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
}); });
test('transcode avi to x265 mp4', async () => { test('transcode avi to x265 10bit mp4', async () => {
const args = ['-i', IN_FILE_NAME, '-c:v', 'libx265', OUT_FILE_NAME]; const args = ['-i', IN_FILE_NAME, '-c:v', 'libx265', '-pix_fmt', 'yuv420p10le', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME); const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(MP4_SIZE); expect(fileSize === MP4_10BIT_SIZE1 || fileSize === MP4_10BIT_SIZE2).toBe(true);
}, TIMEOUT);
test('transcode avi to x265 12bit mp4', async () => {
const args = ['-i', IN_FILE_NAME, '-c:v', 'libx265', '-pix_fmt', 'yuv420p12le', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(MP4_12BIT_SIZE);
}, TIMEOUT); }, 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