Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
66aa1dd2
Commit
66aa1dd2
authored
Oct 27, 2020
by
Jerome Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add libvpx in build scripts
parent
e7deac90
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
155 additions
and
43 deletions
+155
-43
build.sh
build.sh
+2
-0
build-ffmpeg.sh
wasm/build-scripts/build-ffmpeg.sh
+1
-1
build-libvpx.sh
wasm/build-scripts/build-libvpx.sh
+22
-0
build-x264.sh
wasm/build-scripts/build-x264.sh
+6
-5
var.sh
wasm/build-scripts/var.sh
+1
-0
transcode-mp4.html
wasm/examples/transcode-mp4.html
+0
-0
transcode-webm.html
wasm/examples/transcode-webm.html
+73
-0
transcode.test.js
wasm/tests/transcode.test.js
+29
-33
utils.js
wasm/tests/utils.js
+21
-4
No files found.
build.sh
View file @
66aa1dd2
...
...
@@ -8,6 +8,8 @@ SCRIPT_ROOT=$(dirname $0)/wasm/build-scripts
emcc
-v
# build x264
$SCRIPT_ROOT
/build-x264.sh
# build libvpx
$SCRIPT_ROOT
/build-libvpx.sh
# configure FFmpeg with Emscripten
$SCRIPT_ROOT
/configure-ffmpeg.sh
# build ffmpeg.wasm
...
...
wasm/build-scripts/build-ffmpeg.sh
View file @
66aa1dd2
...
...
@@ -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
-pthread
-lavdevice
-lavfilter
-lavformat
-lavcodec
-lswresample
-lswscale
-lavutil
-lpostproc
-lm
-lx264
-
lvpx
-
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
...
...
wasm/build-scripts/build-libvpx.sh
0 → 100755
View file @
66aa1dd2
#!/bin/bash
set
-euo
pipefail
source
$(
dirname
$0
)
/var.sh
LIB_PATH
=
third_party/libvpx
FLAGS
=
"-c -s USE_PTHREADS=1
$OPTIM_FLAGS
"
CONF_FLAGS
=(
--prefix
=
$BUILD_DIR
# install library in a build directory for FFmpeg to include
--target
=
generic-gnu
# target with miminal features
--disable-install-bins
# not to install bins
--disable-examples
# not to build examples
--disable-tools
# not to build tools
--disable-docs
# not to build docs
--disable-unit-tests
# not to do unit tests
--extra-cflags
=
"
$FLAGS
"
# flags to use pthread and code optimization
--extra-cxxflags
=
"
$FLAGS
"
# flags to use pthread and code optimization
)
echo
"CONF_FLAGS=
${
CONF_FLAGS
[@]
}
"
(
cd
$LIB_PATH
&&
LDFLAGS
=
"
$FLAGS
"
STRIP
=
"llvm-strip"
emconfigure ./configure
"
${
CONF_FLAGS
[@]
}
"
)
emmake make
-C
$LIB_PATH
clean
emmake make
-C
$LIB_PATH
install
-j
wasm/build-scripts/build-x264.sh
View file @
66aa1dd2
...
...
@@ -3,8 +3,8 @@
set
-euo
pipefail
source
$(
dirname
$0
)
/var.sh
X264
_PATH
=
third_party/x264
FLAGS
=(
LIB
_PATH
=
third_party/x264
CONF_
FLAGS
=(
--prefix
=
$BUILD_DIR
# install library in a build directory for FFmpeg to include
--host
=
i686-gnu
# use i686 linux
--enable-static
# enable building static library
...
...
@@ -12,6 +12,7 @@ FLAGS=(
--disable-asm
# disable asm optimization
--extra-cflags
=
"-c -s USE_PTHREADS=1
$OPTIM_FLAGS
"
# flags to use pthread and code optimization
)
echo
"FLAGS=
${
FLAGS
[@]
}
"
(
cd
$X264_PATH
&&
emconfigure ./configure
"
${
FLAGS
[@]
}
"
)
emmake make
-C
$X264_PATH
install-lib-static
-j
echo
"CONF_FLAGS=
${
CONF_FLAGS
[@]
}
"
(
cd
$LIB_PATH
&&
emconfigure ./configure
"
${
CONF_FLAGS
[@]
}
"
)
emmake make
-C
$LIB_PATH
clean
emmake make
-C
$LIB_PATH
install-lib-static
-j
wasm/build-scripts/var.sh
View file @
66aa1dd2
...
...
@@ -37,6 +37,7 @@ FFMPEG_CONFIG_FLAGS_BASE=(
--disable-doc
# disable doc
--enable-gpl
# required by x264
--enable-libx264
# enable x264
--enable-libvpx
# enable libvpx / webm
--disable-debug
# disable debug info, required by closure
--disable-runtime-cpudetect
# disable runtime cpu detect
--disable-autodetect
# disable external libraries auto detect
...
...
wasm/examples/transcode.html
→
wasm/examples/transcode
-mp4
.html
View file @
66aa1dd2
File moved
wasm/examples/transcode-webm.html
0 → 100644
View file @
66aa1dd2
<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 webm and play!
</h3>
<video
id=
"output-video"
controls
></video><br/>
<input
type=
"file"
id=
"uploader"
>
<p
id=
"message"
>
Update a video
</p>
<script
type=
"text/javascript"
>
const
readFromBlobOrFile
=
(
blob
)
=>
(
new
Promise
((
resolve
,
reject
)
=>
{
const
fileReader
=
new
FileReader
();
fileReader
.
onload
=
()
=>
{
resolve
(
fileReader
.
result
);
};
fileReader
.
onerror
=
({
target
:
{
error
:
{
code
}
}
})
=>
{
reject
(
Error
(
`File could not be read! Code=
${
code
}
`
));
};
fileReader
.
readAsArrayBuffer
(
blob
);
})
);
const
message
=
document
.
getElementById
(
'message'
);
const
transcode
=
async
({
target
:
{
files
}
})
=>
{
let
resolve
=
null
;
const
Core
=
await
createFFmpegCore
({
printErr
:
(
m
)
=>
console
.
log
(
m
),
print
:
(
m
)
=>
{
console
.
log
(
m
);
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
}
});
message
.
innerHTML
=
'Writing file to MEMFS'
;
const
data
=
await
readFromBlobOrFile
(
files
[
0
]);
Core
.
FS
.
writeFile
(
'video.avi'
,
new
Uint8Array
(
data
));
const
ffmpeg
=
Core
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
// const args = ['ffmpeg', '-hide_banner', '-nostdin', '-i', 'video.mp4', '-vf', 'scale=512:-1', '-vcodec', 'h264', '-acodec', 'copy', 'scaled.mp4'];
const
args
=
[
'ffmpeg'
,
'-hide_banner'
,
'-nostdin'
,
'-threads'
,
'0'
,
'-i'
,
'video.avi'
,
'-acodec'
,
'copy'
,
'-row-mt'
,
'1'
,
'video.webm'
];
const
argsPtr
=
Core
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
args
.
forEach
((
s
,
idx
)
=>
{
const
buf
=
Core
.
_malloc
(
s
.
length
+
1
);
Core
.
writeAsciiToMemory
(
s
,
buf
);
Core
.
setValue
(
argsPtr
+
(
Uint32Array
.
BYTES_PER_ELEMENT
*
idx
),
buf
,
'i32'
);
});
const
d
=
Date
.
now
();
console
.
time
(
`[
${
d
}
]
${
files
[
0
].
name
}
execution time`
);
message
.
innerHTML
=
'Start to transcode'
;
ffmpeg
(
args
.
length
,
argsPtr
);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
output
=
Core
.
FS
.
readFile
(
'video.webm'
);
Core
.
FS
.
unlink
(
'video.webm'
);
const
video
=
document
.
getElementById
(
'output-video'
);
video
.
src
=
URL
.
createObjectURL
(
new
Blob
([
output
.
buffer
],
{
type
:
'video/mp4'
}));
console
.
timeEnd
(
`[
${
d
}
]
${
files
[
0
].
name
}
execution time`
);
};
document
.
getElementById
(
'uploader'
).
addEventListener
(
'change'
,
transcode
);
</script>
<script
type=
"text/javascript"
src=
"../dist/ffmpeg-core.js"
></script>
</body>
</html>
wasm/tests/transcode.test.js
View file @
66aa1dd2
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
createFFmpegCore
=
require
(
'../dist/ffmpeg-core'
);
const
{
parseArgs
,
ffmpeg
}
=
require
(
'./utils'
);
const
filePath
=
path
.
join
(
__dirname
,
'data'
,
'video-3s.avi'
);
let
data
=
null
;
const
{
runFFmpeg
}
=
require
(
'./utils'
);
const
aviFilePath
=
path
.
join
(
__dirname
,
'data'
,
'video-3s.avi'
);
const
TIMEOUT
=
120000
;
const
MP4_SIZE
=
98326
;
const
WEBM_SIZE
=
114591
;
let
aviData
=
null
;
beforeAll
(
async
()
=>
{
data
=
Uint8Array
.
from
(
fs
.
readFileSync
(
f
ilePath
));
aviData
=
Uint8Array
.
from
(
fs
.
readFileSync
(
aviF
ilePath
));
});
test
(
'transcode avi to x264 mp4'
,
async
()
=>
{
let
resolve
=
null
;
const
Core
=
await
createFFmpegCore
({
printErr
:
()
=>
{},
print
:
(
m
)
=>
{
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
},
});
Core
.
FS
.
writeFile
(
'video.avi'
,
data
);
ffmpeg
(
Core
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
Core
=
await
runFFmpeg
(
'video.avi'
,
aviData
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
const
fileSize
=
Core
.
FS
.
readFile
(
'video.mp4'
).
length
;
Core
.
FS
.
unlink
(
'video.mp4'
);
expect
(
fileSize
).
toBe
(
98326
);
},
30000
);
expect
(
fileSize
).
toBe
(
MP4_SIZE
);
},
TIMEOUT
);
test
(
'transcode avi to x264 mp4 twice'
,
async
()
=>
{
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
let
resolve
=
null
;
const
Core
=
await
createFFmpegCore
({
printErr
:
()
=>
{},
print
:
(
m
)
=>
{
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
},
});
Core
.
FS
.
writeFile
(
'video.avi'
,
data
);
ffmpeg
(
Core
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
Core
=
await
runFFmpeg
(
'video.avi'
,
aviData
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
const
fileSize
=
Core
.
FS
.
readFile
(
'video.mp4'
).
length
;
Core
.
FS
.
unlink
(
'video.mp4'
);
expect
(
fileSize
).
toBe
(
98326
);
expect
(
fileSize
).
toBe
(
MP4_SIZE
);
}
},
30000
);
},
TIMEOUT
);
test
(
'transcode avi to webm'
,
async
()
=>
{
const
Core
=
await
runFFmpeg
(
'video.avi'
,
aviData
,
[
'-i'
,
'video.avi'
,
'-row-mt'
,
'1'
,
'video.webm'
]);
const
fileSize
=
Core
.
FS
.
readFile
(
'video.webm'
).
length
;
Core
.
FS
.
unlink
(
'video.webm'
);
expect
(
fileSize
).
toBe
(
WEBM_SIZE
);
},
TIMEOUT
);
test
(
'transcode avi to webm twice'
,
async
()
=>
{
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
const
Core
=
await
runFFmpeg
(
'video.avi'
,
aviData
,
[
'-i'
,
'video.avi'
,
'-row-mt'
,
'1'
,
'video.webm'
]);
const
fileSize
=
Core
.
FS
.
readFile
(
'video.webm'
).
length
;
Core
.
FS
.
unlink
(
'video.webm'
);
expect
(
fileSize
).
toBe
(
WEBM_SIZE
);
}
},
TIMEOUT
);
wasm/tests/utils.js
View file @
66aa1dd2
const
createFFmpegCore
=
require
(
'../dist/ffmpeg-core'
);
const
parseArgs
=
(
Core
,
args
)
=>
{
const
argsPtr
=
Core
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
args
.
forEach
((
s
,
idx
)
=>
{
...
...
@@ -15,9 +17,24 @@ const ffmpeg = (Core, args) => {
[
'number'
,
'number'
],
parseArgs
(
Core
,
[
'ffmpeg'
,
'-nostdin'
,
...
args
]),
);
}
};
const
runFFmpeg
=
async
(
filename
,
data
,
args
)
=>
{
let
resolve
=
null
;
const
Core
=
await
createFFmpegCore
({
printErr
:
()
=>
{},
print
:
(
m
)
=>
{
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
},
});
Core
.
FS
.
writeFile
(
filename
,
data
);
ffmpeg
(
Core
,
args
);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
return
Core
;
};
module
.
exports
=
{
ffmpeg
,
parseArgs
,
}
runFFmpeg
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment