Commit c808d567 authored by Jerome Wu's avatar Jerome Wu

Update libass build scripts and add test cases

parent 7255c577
......@@ -11,13 +11,10 @@ CONF_FLAGS=(
--enable-shared=no # not to build shared library
--enable-static
--disable-dependency-tracking
--disable-debug
--without-glib
--disable-docs
)
echo "CONF_FLAGS=${CONF_FLAGS[@]}"
(cd $LIB_PATH && \
emconfigure ./autogen.sh && \
CFLAGS=$CFLAGS emconfigure ./configure "${CONF_FLAGS[@]}")
emmake make -C $LIB_PATH clean
emmake make -C $LIB_PATH install -j1
emmake make -C $LIB_PATH install -j
......@@ -4,7 +4,6 @@ set -euo pipefail
source $(dirname $0)/var.sh
LIB_PATH=third_party/libass
LIBASS_PC_PATH="$BUILD_DIR/lib/pkgconfig"
CONF_FLAGS=(
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-gnu # use i686 linux
......@@ -15,6 +14,6 @@ CONF_FLAGS=(
--disable-require-system-font-provider
)
echo "CONF_FLAGS=${CONF_FLAGS[@]}"
(cd $LIB_PATH && ./autogen.sh && EM_PKG_CONFIG_PATH=$LIBASS_PC_PATH emconfigure ./configure "${CONF_FLAGS[@]}")
(cd $LIB_PATH && ./autogen.sh && EM_PKG_CONFIG_PATH=$EM_PKG_CONFIG_PATH emconfigure ./configure "${CONF_FLAGS[@]}")
emmake make -C $LIB_PATH clean
emmake make -C $LIB_PATH install -j
......@@ -3,7 +3,6 @@
set -euo pipefail
source $(dirname $0)/var.sh
FFMPEG_WEBM_PC_PATH="$BUILD_DIR/lib/pkgconfig"
FLAGS=(
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
--enable-gpl # required by x264
......@@ -20,7 +19,10 @@ FLAGS=(
--enable-libfreetype # enable freetype
--enable-libopus # enable opus
--enable-libwebp # enable libwebp
--enable-libass # enable libass
--enable-libfribidi # enable libfribidi
# --enable-filter=subtitles,overlay
# --enable-libaom # enable libaom
)
echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
EM_PKG_CONFIG_PATH=${FFMPEG_WEBM_PC_PATH} emconfigure ./configure "${FLAGS[@]}"
EM_PKG_CONFIG_PATH=${EM_PKG_CONFIG_PATH} emconfigure ./configure "${FLAGS[@]}"
......@@ -30,6 +30,9 @@ ROOT_DIR=$PWD
# Directory to install headers and libraries
BUILD_DIR=$ROOT_DIR/build
# Directory to look for pkgconfig files
EM_PKG_CONFIG_PATH=$BUILD_DIR/lib/pkgconfig
# Toolchain file path for cmake
TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
......@@ -58,8 +61,6 @@ FFMPEG_CONFIG_FLAGS_BASE=(
--cxx=em++
--objcc=emcc
--dep-cc=emcc
--enable-libass
--enable-filter=subtitles,overlay
)
echo "EMSDK=$EMSDK"
......
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg, b64ToUint8Array } = require('./utils');
const ARIAL_TTF = require('./data/arial.ttf.js');
const SRT_FILE = `
1
00:00:00,000 --> 00:00:01,000
ffmpeg.wasm test
`;
const ASS_FILE = `
[Script Info]
; Script generated by FFmpeg/Lavc58.91.100
ScriptType: v4.00+
PlayResX: 240
PlayResY: 256
ScaledBorderAndShadow: yes
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:01.00,Default,,0,0,0,,ffmpeg.wasm test
`;
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const MP4_WITH_SRT_FILE_SIZE = 38695;
const MP4_WITH_ASS_FILE_SIZE = 38532;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to x264 mp4 with *.srt subtitle', async () => {
const args = ['-i', IN_FILE_NAME, '-vf', 'subtitles=test.srt:fontsdir=/fonts:force_style="Fontname=Arial"', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME, [{ name: '/fonts/arial.ttf', data: b64ToUint8Array(ARIAL_TTF) }, { name: 'test.srt', data: SRT_FILE }], ['/fonts']);
expect(fileSize).toBe(MP4_WITH_SRT_FILE_SIZE);
}, TIMEOUT);
test('transcode avi to x264 mp4 with *.ass subtitle', async () => {
const args = ['-i', IN_FILE_NAME, '-vf', 'ass=test.ass:fontsdir=/fonts', OUT_FILE_NAME];
const { fileSize, file } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME, [{ name: '/fonts/arial.ttf', data: b64ToUint8Array(ARIAL_TTF) }, { name: 'test.ass', data: ASS_FILE }], ['/fonts']);
fs.writeFileSync('subtitle.mp4', file);
expect(fileSize).toBe(MP4_WITH_ASS_FILE_SIZE);
}, TIMEOUT);
......@@ -19,7 +19,7 @@ const ffmpeg = (Core, args) => {
);
};
const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = []) => {
const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = [], extraFolders = []) => {
let resolve = null;
let file = null;
let fileSize = -1;
......@@ -31,6 +31,9 @@ const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = []) => {
}
},
});
extraFolders.forEach((f) => {
Core.FS.mkdir(f);
});
extraFiles.forEach(({ name, data: d }) => {
Core.FS.writeFile(name, d);
});
......
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