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
b426683e
Commit
b426683e
authored
Sep 24, 2020
by
Jerome Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add closure flag, documents and update test data
parent
48e9a933
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
16 deletions
+33
-16
build-ffmpeg.sh
wasm/build-scripts/build-ffmpeg.sh
+3
-2
build-x264.sh
wasm/build-scripts/build-x264.sh
+6
-6
configure.sh
wasm/build-scripts/configure.sh
+3
-2
optimization-flags.md
wasm/docs/optimization-flags.md
+13
-0
ffmpeg.js
wasm/ffmpeg.js
+7
-5
data
wasm/tests/data
+1
-1
No files found.
wasm/build-scripts/build-ffmpeg.sh
View file @
b426683e
...
@@ -11,13 +11,14 @@ ARGS=(
...
@@ -11,13 +11,14 @@ ARGS=(
-Qunused-arguments
-Qunused-arguments
-o
wasm/dist/ffmpeg-core.js fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-o
wasm/dist/ffmpeg-core.js fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-lavdevice
-lavfilter
-lavformat
-lavcodec
-lswresample
-lswscale
-lavutil
-lpostproc
-lm
-lx264
-pthread
-lavdevice
-lavfilter
-lavformat
-lavcodec
-lswresample
-lswscale
-lavutil
-lpostproc
-lm
-lx264
-pthread
-O3
# Optimize code with performance first
-O3
# optimize code with performance first
--closure
1
# code size optimization
-s
USE_SDL
=
2
# use SDL2
-s
USE_SDL
=
2
# use SDL2
-s
USE_PTHREADS
=
1
# enable pthreads support
-s
USE_PTHREADS
=
1
# enable pthreads support
-s
PROXY_TO_PTHREAD
=
1
# detach main() from browser/UI main thread
-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
INVOKE_RUN
=
0
# not to run the main() in the beginning
-s
EXPORTED_FUNCTIONS
=
"[_main, _proxy_main]"
# export main and proxy_main funcs
-s
EXPORTED_FUNCTIONS
=
"[_main, _proxy_main]"
# export main and proxy_main funcs
-s
EXTRA_EXPORTED_RUNTIME_METHODS
=
"[FS, cwrap, setValue, writeAsciiToMemory]"
# export preamble funcs
-s
EXTRA_EXPORTED_RUNTIME_METHODS
=
"[FS, cwrap, setValue, writeAsciiToMemory]"
# export preamble funcs
-s
INITIAL_MEMORY
=
268435456
# 268435456 bytes = 256 M
B
-s
INITIAL_MEMORY
=
1073741824
# 1073741824 bytes = 1 G
B
)
)
emcc
"
${
ARGS
[@]
}
"
emcc
"
${
ARGS
[@]
}
"
wasm/build-scripts/build-x264.sh
View file @
b426683e
...
@@ -12,7 +12,7 @@ ARGS=(
...
@@ -12,7 +12,7 @@ ARGS=(
--enable-static
# enable building static library
--enable-static
# enable building static library
--disable-cli
# disable cli tools
--disable-cli
# disable cli tools
--disable-asm
# disable asm optimization
--disable-asm
# disable asm optimization
--extra-cflags
=
"-s USE_PTHREADS=1
"
# pass this flags for using pthreads
--extra-cflags
=
"-s USE_PTHREADS=1
-O3 --closure 1"
# flags to use pthread and code optimization
)
)
emconfigure ./configure
"
${
ARGS
[@]
}
"
emconfigure ./configure
"
${
ARGS
[@]
}
"
emmake make install-lib-static
-j4
emmake make install-lib-static
-j4
...
...
wasm/build-scripts/configure.sh
View file @
b426683e
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
set
-eo
pipefail
set
-eo
pipefail
BUILD_DIR
=
$1
BUILD_DIR
=
$1
CFLAGS
=
"-s USE_PTHREADS -
O3 -I
$BUILD_DIR
/include
"
CFLAGS
=
"-s USE_PTHREADS -
I
$BUILD_DIR
/include -O3 --closure 1
"
LDFLAGS
=
"
$CFLAGS
-L
$BUILD_DIR
/lib
-s INITIAL_MEMORY=33554432"
# 33554432 bytes = 32 MB
LDFLAGS
=
"
$CFLAGS
-L
$BUILD_DIR
/lib
"
ARGS
=(
ARGS
=(
--target-os
=
none
# use none to prevent any os specific configurations
--target-os
=
none
# use none to prevent any os specific configurations
--arch
=
x86_32
# use x86_32 to achieve minimal architectural optimization
--arch
=
x86_32
# use x86_32 to achieve minimal architectural optimization
...
@@ -16,6 +16,7 @@ ARGS=(
...
@@ -16,6 +16,7 @@ ARGS=(
--disable-doc
# disable doc
--disable-doc
# disable doc
--enable-gpl
# required by x264
--enable-gpl
# required by x264
--enable-libx264
# enable x264
--enable-libx264
# enable x264
--disable-debug
# disable debug info, required by closure
--extra-cflags
=
"
$CFLAGS
"
--extra-cflags
=
"
$CFLAGS
"
--extra-cxxflags
=
"
$CFLAGS
"
--extra-cxxflags
=
"
$CFLAGS
"
--extra-ldflags
=
"
$LDFLAGS
"
--extra-ldflags
=
"
$LDFLAGS
"
...
...
wasm/docs/optimization-flags.md
0 → 100644
View file @
b426683e
# Optimization Flags
Statistics of using different flags to optimize code:
| flags | build time | execution time | ffmpeg-core.js size | ffmpeg-core.wasm size | ffmpeg.worker.js size |
| ----- | ---------- | ---------------| ------------------- | --------------------- | --------------------- |
| N/A | 6m 19s | 7.5s | 584,269 bytes | 30,406,730 bytes | 9,048 bytes |
| -Oz | 7m 40s | 6s | 295,674 bytes | 14,919,062 bytes | 3,363 bytes |
| -O3 | 8m 36s | 5s | 295,676 bytes | 17,746,341 bytes | 3,363 bytes |
| -O3 --closure 1 | 10m 20s | 5s | 142,076 bytes | 17,746,766 bytes | 3,624 bytes |
| -O3 --closure 1 -flto | 12m 36s | 5s | 141,516 bytes | 18,960,830 bytes | 3,624 bytes |
The best one to use in case of performance is
`-O3 --closure 1`
.
wasm/ffmpeg.js
View file @
b426683e
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
fs
=
require
(
'fs'
);
const
Module
=
require
(
'./dist/ffmpeg-core'
);
const
Module
=
require
(
'./dist/ffmpeg-core'
);
Module
.
onRuntimeInitialized
=
()
=>
{
Module
.
onRuntimeInitialized
=
()
=>
{
const
data
=
Uint8Array
.
from
(
fs
.
readFileSync
(
'tests/data/flame.avi'
));
const
filePath
=
path
.
join
(
__dirname
,
'tests'
,
'data'
,
'video-15s.avi'
);
Module
.
FS
.
writeFile
(
'flame.avi'
,
data
);
const
data
=
Uint8Array
.
from
(
fs
.
readFileSync
(
filePath
));
Module
.
FS
.
writeFile
(
'video.avi'
,
data
);
const
ffmpeg
=
Module
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
const
ffmpeg
=
Module
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
const
args
=
[
'ffmpeg'
,
'-hide_banner'
,
'-report'
,
'-i'
,
'
flame.avi'
,
'flame
.mp4'
];
const
args
=
[
'ffmpeg'
,
'-hide_banner'
,
'-report'
,
'-i'
,
'
video.avi'
,
'video
.mp4'
];
const
argsPtr
=
Module
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
const
argsPtr
=
Module
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
args
.
forEach
((
s
,
idx
)
=>
{
args
.
forEach
((
s
,
idx
)
=>
{
const
buf
=
Module
.
_malloc
(
s
.
length
+
1
);
const
buf
=
Module
.
_malloc
(
s
.
length
+
1
);
...
@@ -26,8 +28,8 @@ Module.onRuntimeInitialized = () => {
...
@@ -26,8 +28,8 @@ Module.onRuntimeInitialized = () => {
const
log
=
String
.
fromCharCode
.
apply
(
null
,
Module
.
FS
.
readFile
(
logFileName
));
const
log
=
String
.
fromCharCode
.
apply
(
null
,
Module
.
FS
.
readFile
(
logFileName
));
if
(
log
.
includes
(
"frames successfully decoded"
))
{
if
(
log
.
includes
(
"frames successfully decoded"
))
{
clearInterval
(
timer
);
clearInterval
(
timer
);
const
output
=
Module
.
FS
.
readFile
(
'
flame
.mp4'
);
const
output
=
Module
.
FS
.
readFile
(
'
video
.mp4'
);
fs
.
writeFileSync
(
'
flame
.mp4'
,
output
);
fs
.
writeFileSync
(
'
video
.mp4'
,
output
);
console
.
timeEnd
(
'execution time'
);
console
.
timeEnd
(
'execution time'
);
process
.
exit
(
1
);
process
.
exit
(
1
);
}
}
...
...
data
@
e5e81752
Subproject commit
de37794135511be2806ff02bd4dea28adbbf27db
Subproject commit
e5e817520bcba4b56b394989ba3d136d9f110b1c
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