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
d0b4ff36
Commit
d0b4ff36
authored
Sep 24, 2020
by
Jerome Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modularize ffmepg-core and update tests
parent
eb607621
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
62 deletions
+86
-62
build-ffmpeg.sh
wasm/build-scripts/build-ffmpeg.sh
+3
-1
ffmpeg.js
wasm/ffmpeg.js
+25
-28
bootstrap.test.js
wasm/tests/bootstrap.test.js
+0
-16
transcode.test.js
wasm/tests/transcode.test.js
+39
-0
utils.js
wasm/tests/utils.js
+19
-17
No files found.
wasm/build-scripts/build-ffmpeg.sh
View file @
d0b4ff36
...
...
@@ -17,8 +17,10 @@ ARGS=(
-s
USE_PTHREADS
=
1
# enable pthreads support
-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
MODULARIZE
=
1
# use modularized version to be more flexible
-s
EXPORT_NAME
=
"createFFmpegCore"
# assign export name for browser
-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,
ccall,
setValue, writeAsciiToMemory]"
# export preamble funcs
-s
INITIAL_MEMORY
=
1073741824
# 1073741824 bytes = 1 GB
)
emcc
"
${
ARGS
[@]
}
"
wasm/ffmpeg.js
View file @
d0b4ff36
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
Modul
e
=
require
(
'./dist/ffmpeg-core'
);
const
createFFmpegCor
e
=
require
(
'./dist/ffmpeg-core'
);
Module
.
onRuntimeInitialized
=
()
=>
{
const
filePath
=
path
.
join
(
__dirname
,
'tests'
,
'data'
,
'video-15s.avi'
);
(
async
()
=>
{
let
resolve
=
null
;
const
Core
=
await
createFFmpegCore
({
printErr
:
(
m
)
=>
console
.
log
(
m
),
print
:
(
m
)
=>
{
console
.
log
(
m
);
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
}
});
const
filePath
=
path
.
join
(
__dirname
,
'tests'
,
'data'
,
'video-3s.avi'
);
const
data
=
Uint8Array
.
from
(
fs
.
readFileSync
(
filePath
));
Modul
e
.
FS
.
writeFile
(
'video.avi'
,
data
);
Cor
e
.
FS
.
writeFile
(
'video.avi'
,
data
);
const
ffmpeg
=
Modul
e
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
const
ffmpeg
=
Cor
e
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
const
args
=
[
'ffmpeg'
,
'-hide_banner'
,
'-report'
,
'-i'
,
'video.avi'
,
'video.mp4'
];
const
argsPtr
=
Modul
e
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
const
argsPtr
=
Cor
e
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
args
.
forEach
((
s
,
idx
)
=>
{
const
buf
=
Modul
e
.
_malloc
(
s
.
length
+
1
);
Modul
e
.
writeAsciiToMemory
(
s
,
buf
);
Modul
e
.
setValue
(
argsPtr
+
(
Uint32Array
.
BYTES_PER_ELEMENT
*
idx
),
buf
,
'i32'
);
const
buf
=
Cor
e
.
_malloc
(
s
.
length
+
1
);
Cor
e
.
writeAsciiToMemory
(
s
,
buf
);
Cor
e
.
setValue
(
argsPtr
+
(
Uint32Array
.
BYTES_PER_ELEMENT
*
idx
),
buf
,
'i32'
);
});
console
.
time
(
'execution time'
);
ffmpeg
(
args
.
length
,
argsPtr
);
/*
* The execution of ffmpeg is not synchronized,
* so we need to parse the log file to check if completed.
*/
const
timer
=
setInterval
(()
=>
{
const
logFileName
=
Module
.
FS
.
readdir
(
'.'
).
find
(
name
=>
name
.
endsWith
(
'.log'
));
if
(
typeof
logFileName
!==
'undefined'
)
{
const
log
=
String
.
fromCharCode
.
apply
(
null
,
Module
.
FS
.
readFile
(
logFileName
));
if
(
log
.
includes
(
"frames successfully decoded"
))
{
clearInterval
(
timer
);
const
output
=
Module
.
FS
.
readFile
(
'video.mp4'
);
fs
.
writeFileSync
(
'video.mp4'
,
output
);
console
.
timeEnd
(
'execution time'
);
process
.
exit
(
1
);
}
}
},
500
);
};
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
output
=
Core
.
FS
.
readFile
(
'video.mp4'
);
fs
.
writeFileSync
(
path
.
join
(
__dirname
,
'video.mp4'
),
output
);
console
.
timeEnd
(
'execution time'
);
process
.
exit
(
1
);
})();
wasm/tests/bootstrap.test.js
deleted
100644 → 0
View file @
eb607621
const
{
initModule
,
parseArgs
,
}
=
require
(
'./utils'
);
let
Module
=
null
;
let
ffmpeg
=
null
;
beforeAll
(
async
()
=>
{
Module
=
await
initModule
();
ffmpeg
=
Module
.
cwrap
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
]);
});
test
(
'test'
,
()
=>
{
const
ret
=
ffmpeg
(...
parseArgs
([
'ffmpeg'
,
'-v'
]));
expect
(
ret
).
toBe
(
0
);
});
wasm/tests/transcode.test.js
0 → 100644
View file @
d0b4ff36
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
Core
=
null
;
let
resolve
=
null
;
let
data
=
null
;
beforeAll
(
async
()
=>
{
data
=
Uint8Array
.
from
(
fs
.
readFileSync
(
filePath
));
Core
=
await
createFFmpegCore
({
printErr
:
()
=>
{},
print
:
(
m
)
=>
{
if
(
m
.
startsWith
(
'FFMPEG_END'
))
{
resolve
();
}
},
});
Core
.
FS
.
writeFile
(
'video.avi'
,
data
);
});
test
(
'transcode avi to x264 mp4'
,
async
()
=>
{
ffmpeg
(
Core
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
fileSize
=
Core
.
FS
.
readFile
(
'video.mp4'
).
length
;
Core
.
FS
.
unlink
(
'video.mp4'
);
expect
(
fileSize
).
toBe
(
98326
);
},
30000
);
test
(
'transcode avi to x264 mp4 twice'
,
async
()
=>
{
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
ffmpeg
(
Core
,
[
'-i'
,
'video.avi'
,
'video.mp4'
]);
await
new
Promise
((
_resolve
)
=>
{
resolve
=
_resolve
});
const
fileSize
=
Core
.
FS
.
readFile
(
'video.mp4'
).
length
;
Core
.
FS
.
unlink
(
'video.mp4'
);
expect
(
fileSize
).
toBe
(
98326
);
}
},
30000
);
wasm/tests/utils.js
View file @
d0b4ff36
let
Module
=
null
;
exports
.
initModule
=
()
=>
(
new
Promise
((
resolve
)
=>
{
const
_Module
=
require
(
'../dist/ffmpeg-core.js'
);
_Module
.
onRuntimeInitialized
=
()
=>
{
Module
=
_Module
;
resolve
(
Module
);
}
})
);
exports
.
parseArgs
=
(
args
)
=>
{
const
argsPtr
=
Module
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
const
parseArgs
=
(
Core
,
args
)
=>
{
const
argsPtr
=
Core
.
_malloc
(
args
.
length
*
Uint32Array
.
BYTES_PER_ELEMENT
);
args
.
forEach
((
s
,
idx
)
=>
{
const
buf
=
Modul
e
.
_malloc
(
s
.
length
+
1
);
Modul
e
.
writeAsciiToMemory
(
s
,
buf
);
Modul
e
.
setValue
(
argsPtr
+
(
Uint32Array
.
BYTES_PER_ELEMENT
*
idx
),
buf
,
'i32'
);
const
buf
=
Cor
e
.
_malloc
(
s
.
length
+
1
);
Cor
e
.
writeAsciiToMemory
(
s
,
buf
);
Cor
e
.
setValue
(
argsPtr
+
(
Uint32Array
.
BYTES_PER_ELEMENT
*
idx
),
buf
,
'i32'
);
});
return
[
args
.
length
,
argsPtr
];
};
const
ffmpeg
=
(
Core
,
args
)
=>
{
Core
.
ccall
(
'proxy_main'
,
'number'
,
[
'number'
,
'number'
],
parseArgs
(
Core
,
[
'ffmpeg'
,
'-nostdin'
,
...
args
]),
);
}
module
.
exports
=
{
ffmpeg
,
parseArgs
,
}
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