Commit 036df612 authored by Jerome Wu's avatar Jerome Wu

Add libmp3lame

parent 6326ad09
...@@ -39,3 +39,4 @@ If nothing goes wrong, you can find JavaScript files in `wasm/dist`. ...@@ -39,3 +39,4 @@ If nothing goes wrong, you can find JavaScript files in `wasm/dist`.
#### Audio #### Audio
- wavpack (wav): 5.3.0 - wavpack (wav): 5.3.0
- lame (mp3): 3.100
...@@ -16,6 +16,8 @@ $SCRIPT_ROOT/build-x264.sh ...@@ -16,6 +16,8 @@ $SCRIPT_ROOT/build-x264.sh
$SCRIPT_ROOT/build-libvpx.sh $SCRIPT_ROOT/build-libvpx.sh
# build WavPack # build WavPack
$SCRIPT_ROOT/build-wavpack.sh $SCRIPT_ROOT/build-wavpack.sh
# build lame
$SCRIPT_ROOT/build-lame.sh
# configure FFmpeg with Emscripten # configure FFmpeg with Emscripten
$SCRIPT_ROOT/configure-ffmpeg.sh $SCRIPT_ROOT/configure-ffmpeg.sh
# build ffmpeg.wasm core # build ffmpeg.wasm core
......
...@@ -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 -pthread -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -lvpx -lwavpack -lmp3lame -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
......
#!/bin/bash
set -euo pipefail
source $(dirname $0)/var.sh
LIB_PATH=third_party/lame
FLAGS="-c -s USE_PTHREADS=1 $OPTIM_FLAGS"
CONF_FLAGS=(
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-linux # use i686 linux
--disable-shared # disable shared library
--disable-frontend # exclude lame executable
--disable-analyzer-hooks # exclude analyzer hooks
)
echo "CONF_FLAGS=${CONF_FLAGS[@]}"
(cd $LIB_PATH && emconfigure ./configure "${CONF_FLAGS[@]}")
emmake make -C $LIB_PATH clean
emmake make -C $LIB_PATH install -j
...@@ -45,6 +45,7 @@ FFMPEG_CONFIG_FLAGS_BASE=( ...@@ -45,6 +45,7 @@ FFMPEG_CONFIG_FLAGS_BASE=(
--enable-libx264 # enable x264 --enable-libx264 # enable x264
--enable-libvpx # enable libvpx / webm --enable-libvpx # enable libvpx / webm
--enable-libwavpack # enable libwavpack --enable-libwavpack # enable libwavpack
--enable-libmp3lame # enable libmp3lame
--disable-debug # disable debug info, required by closure --disable-debug # disable debug info, required by closure
--disable-runtime-cpudetect # disable runtime cpu detect --disable-runtime-cpudetect # disable runtime cpu detect
--disable-autodetect # disable external libraries auto 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 wav file to transcode to mp3 and play!</h3>
<audio id="output-audio" controls></audio><br/>
<input type="file" id="uploader">
<p id="message">Upload a wav file</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 = 'audio.wav';
const OUT_FILE_NAME = 'audio.mp3';
const args = ['-i', IN_FILE_NAME, 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 audio = document.getElementById('output-audio');
audio.src = URL.createObjectURL(new Blob([file.buffer], { type: 'audio/mp3' }));
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 = 'audio-1s.wav';
const OUT_FILE_NAME = 'audio.mp3';
const MP3_SIZE = 4039;
let wavData = null;
beforeAll(() => {
wavData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('convert wav to mp3', async () => {
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, wavData, args, OUT_FILE_NAME);
expect(fileSize).toBe(MP3_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