Commit cdf5808f authored by yang.jie's avatar yang.jie

run demo

parent c071d170
#!/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
......@@ -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)
......
......@@ -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]() {
// std::thread t([this]() {
// decodeAudio();
// });
// t.join();
decodeAudio();
});
t.join();
}
int FFAudioDecoder::decode(int *gotframe)
......
......@@ -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[])
......
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