Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wasm-trans-mp3
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
yang.jie
wasm-trans-mp3
Commits
cdf5808f
Commit
cdf5808f
authored
Mar 17, 2022
by
yang.jie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run demo
parent
c071d170
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
30 deletions
+103
-30
build-demo-mp3.sh
build-demo-mp3.sh
+65
-0
CMakeLists.txt
demo_transcode_mp3/CMakeLists.txt
+25
-20
FFAudioDecoder.cpp
demo_transcode_mp3/audio/FFAudioDecoder.cpp
+11
-10
main.cpp
demo_transcode_mp3/main.cpp
+2
-0
No files found.
build-demo-mp3.sh
0 → 100644
View file @
cdf5808f
#!/bin/bash
#set -eo pipefail
WORKPATH
=
$(
cd
$(
dirname
$0
)
;
pwd
)
DEMO_PATH
=
$WORKPATH
/demo_transcode_mp3
echo
"WORKPATH"
=
$WORKPATH
rm
-rf
${
WORKPATH
}
/demo_transcode_mp3/transcode_mp3.js
${
WORKPATH
}
/demo_transcode_mp3/transcode_mp3.wasm
FFMPEG_ST
=
yes
EMSDK
=
/emsdk
THIRD_DIR
=
${
WORKPATH
}
/lib/third/build
DEBUG
=
""
DEBUG
=
"-g -fno-inline -gseparate-dwarf=/code/demo/temp.debug.wasm -s SEPARATE_DWARF_URL=http://localhost:5000/temp.debug.wasm"
#--closure 压缩胶水代码,有可能会造成变量重复定义。生产发布可设为1
OPTIM_FLAGS
=
"-O1
$DEBUG
--closure 0"
if
[[
"
$FFMPEG_ST
"
!=
"yes"
]]
;
then
EXTRA_FLAGS
=(
-pthread
-s
USE_PTHREADS
=
1
# enable pthreads support
-s
PROXY_TO_PTHREAD
=
1
# detach main() from browser/UI main thread
-o
${
DEMO_PATH
}
/transcode_mp3.js
)
else
EXTRA_FLAGS
=(
-o
${
DEMO_PATH
}
/transcode_mp3.js
)
fi
FLAGS
=(
-I
$WORKPATH
/lib/ffmpeg-emcc/include
-L
$WORKPATH
/lib/ffmpeg-emcc/lib
-I
$THIRD_DIR
/include
-L
$THIRD_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
-lharfbuzz
-lfribidi
-lass
-lx264
-lx265
-lvpx
-lwavpack
-lmp3lame
-lfdk-aac
-lvorbis
-lvorbisenc
-lvorbisfile
-logg
-ltheora
-ltheoraenc
-ltheoradec
-lz
-lfreetype
-lopus
-lwebp
$DEMO_PATH
/audio/FFAudioDecoder.cpp
$DEMO_PATH
/audio/FFAudioEncoder.cpp
$DEMO_PATH
/ffmbase/FFMBase.cpp
$DEMO_PATH
/main.cpp
-I
$DEMO_PATH
/audio
-I
$DEMO_PATH
/ffmbase
-I
$DEMO_PATH
-s
FORCE_FILESYSTEM
=
1
-s
WASM
=
1
-s
USE_SDL
=
2
# use SDL2
-s
INVOKE_RUN
=
0
# not to run the main() in the beginning
-s
EXIT_RUNTIME
=
1
# exit runtime after execution
-s
MODULARIZE
=
1
# 延迟加载 use modularized version to be more flexible
-s
EXPORT_NAME
=
"createTranscodeMp3"
# assign export name for browser
-s
EXPORTED_FUNCTIONS
=
"[_main,_malloc,_free]"
# export main and proxy_main funcs
-s
EXPORTED_RUNTIME_METHODS
=
"[FS, cwrap, ccall, setValue, writeAsciiToMemory]"
# export preamble funcs
-s
INITIAL_MEMORY
=
134217728
# 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB
-s
ALLOW_MEMORY_GROWTH
=
1
--pre-js
$WORKPATH
/pre.js
--post-js
$WORKPATH
/post.js
$OPTIM_FLAGS
${
EXTRA_FLAGS
[@]
}
)
echo
"FFMPEG_EM_FLAGS=
${
FLAGS
[@]
}
"
em++
"
${
FLAGS
[@]
}
"
cp
${
WORKPATH
}
/demo_transcode_mp3/transcode_mp3.
*
${
WORKPATH
}
/demo_transcode_mp3/build
demo_transcode_mp3/CMakeLists.txt
View file @
cdf5808f
...
...
@@ -3,11 +3,11 @@ project(transcode_mp3)
set
(
CMAKE_CXX_STANDARD 17
)
set
(
CMAKE_EXECUTABLE_SUFFIX
".html"
)
# 编译生成.html
#pre.js and pro.js path
#
set(PRE_PATH "/code")
#
set(POST_PATH "/code")
#
set(CMAKE_EXECUTABLE_SUFFIX ".html") # 编译生成.html
set
(
CMAKE_VERBOSE_MAKEFILE on
)
#
pre.js and pro.js path
set
(
PRE_PATH
"/code"
)
set
(
POST_PATH
"/code"
)
include_directories
(
"../lib/ffmpeg-emcc/include"
)
link_directories
(
"../lib/ffmpeg-emcc/lib"
)
...
...
@@ -23,21 +23,26 @@ add_executable(${PROJECT_NAME} ${DIR})
add_subdirectory
(
audio
)
add_subdirectory
(
ffmbase
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s FORCE_FILESYSTEM=1"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s WASM=1"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s USE_SDL=2"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s INVOKE_RUN=0"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s EXIT_RUNTIME=1"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s MODULARIZE=1"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s EXPORT_NAME=
${
PROJECT_NAME
}
"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s EXPORTED_FUNCTIONS=[_main,_malloc,_free]"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s EXPORTED_RUNTIME_METHODS=[FS, cwrap, ccall, setValue, writeAsciiToMemory]"
)
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"-s INITIAL_MEMORY=134217728"
)
# set_target_properties(transcode_mp3 PROPERTIES LINK_FLAGS "-s TOTAL_MEMORY=134217728")
# set_target_properties(transcode_mp3 PROPERTIES LINK_FLAGS "-s ALLOW_MEMORY_GROWTH=1")
# set_target_properties(transcode_mp3 PROPERTIES LINK_FLAGS "--pre-js ${PRE_PATH}/pre.js")
# set_target_properties(transcode_mp3 PROPERTIES LINK_FLAGS "--post-js ${POST_PATH}/post.js")
set_target_properties
(
transcode_mp3 PROPERTIES LINK_FLAGS
"\
-Wno-deprecated-declarations \
-Wno-pointer-sign \
-Wno-implicit-int-float-conversion \
-Wno-switch -Wno-parentheses\
-Qunused-arguments \
-s FORCE_FILESYSTEM=1 \
-s WASM=1 \
-s USE_SDL=2 \
-s INVOKE_RUN=0 \
-s EXIT_RUNTIME=1 \
-s MODULARIZE=1 \
-s EXPORT_NAME=
\"
createTrancodeMp3
\"
\
-s EXPORTED_FUNCTIONS=
\"
[_main,_malloc,_free]
\"
\
-s EXPORTED_RUNTIME_METHODS=
\"
[FS, cwrap, ccall, setValue, writeAsciiToMemory]
\"
\
-s INITIAL_MEMORY=134217728 \
-s ALLOW_MEMORY_GROWTH=1 \
--pre-js
${
PRE_PATH
}
/pre.js \
--post-js
${
POST_PATH
}
/post.js \
"
)
target_link_libraries
(
${
PROJECT_NAME
}
PRIVATE audio
)
target_link_libraries
(
${
PROJECT_NAME
}
PRIVATE ffmbase
)
...
...
demo_transcode_mp3/audio/FFAudioDecoder.cpp
View file @
cdf5808f
...
...
@@ -16,7 +16,7 @@ namespace FFM {
avformat_free_context
(
pFormatCtx
);
AVFormatContext
*
_pFormatCtx
=
avformat_alloc_context
();
//
AVDictionary ò key =
rtbufsize , value = 18432000
//
����AVDictionary ������ key =
rtbufsize , value = 18432000
AVDictionary
*
format_opts
=
nullptr
;
//av_dict_set_int(&format_opts, "video_device_number", 0, 0);
...
...
@@ -56,10 +56,11 @@ namespace FFM {
void
FFAudioDecoder
::
startDecoder
()
{
std
::
thread
t
([
this
]()
{
decodeAudio
();
});
t
.
join
();
// std::thread t([this]() {
// decodeAudio();
// });
// t.join();
decodeAudio
();
}
int
FFAudioDecoder
::
decode
(
int
*
gotframe
)
...
...
@@ -82,10 +83,10 @@ namespace FFM {
*
gotframe
=
1
;
if
(
m_pPkt
->
pts
==
AV_NOPTS_VALUE
)
{
printf
(
"AV_NOPTS_VALUE
\n
"
);
if
(
m_pPkt
->
pts
==
AV_NOPTS_VALUE
)
{
printf
(
"AV_NOPTS_VALUE
\n
"
);
if
(
m_pPkt
->
pts
==
AV_NOPTS_VALUE
)
{
//Write PTS
AVRational
time_base1
=
m_pCodecCtx
->
time_base
;
...
...
@@ -97,7 +98,7 @@ namespace FFM {
m_pPkt
->
dts
=
m_pPkt
->
pts
;
m_pPkt
->
duration
=
(
double
)
calc_duration
/
(
double
)(
av_q2d
(
time_base1
)
*
AV_TIME_BASE
);
m_frameIndex
++
;
}
}
}
}
...
...
demo_transcode_mp3/main.cpp
View file @
cdf5808f
...
...
@@ -29,6 +29,7 @@ using namespace FFM;
EM_PORT_API
(
int
)
tanscode_mp3
(
std
::
string
&
in_file
,
std
::
string
&
out_file
)
{
printf
(
"in_file: %s, out_file: %s
\n
"
,
in_file
.
c_str
(),
out_file
.
c_str
());
FFAudioDecoder
decoder
(
in_file
);
FFAudioEncoder
encoder
(
out_file
,
decoder
.
getInSream
());
...
...
@@ -42,6 +43,7 @@ EM_PORT_API(int) tanscode_mp3(std::string &in_file, std::string &out_file)
decoder
.
setFrameCallBack
(
audio_frame_callBack
);
decoder
.
startDecoder
();
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
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