编译命令:
emconfigure ./configure --cc="emcc" --cxx="em++" --ar="emar" --ranlib=emranlib --prefix=$(pwd)/dist --enable-cross-compile --target-os=none --arch=x86_64 --cpu=generic --disable-ffplay --disable-ffprobe --disable-asm --disable-doc --disable-devices --disable-indevs --disable-outdevs --disable-network --disable-w32threads --disable-pthreads --enable-ffmpeg --enable-static --disable-shared --enable-decoder=pcm_mulaw --enable-decoder=pcm_alaw --enable-decoder=adpcm_ima_smjpeg --enable-decoder=aac --enable-decoder=hevc --enable-decoder=h264 --enable-protocol=file --disable-stripping
测试CM艾克Lists.txt
# CMakeList.txt: EmccVideo 的 CMake 项目,在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.8)
set(ProgramName "EmccVideo.js")
project (${ProgramName})
# 指定使用的编译器
set(CMAKE_C_COMPILER "/home/ubuntu/Downloads/emsdk/upstream/emscripten/emcc")
set(CMAKE_CXX_COMPILER "/home/ubuntu/Downloads/emsdk/upstream/emscripten/emcc")
set(ffmpeg_dir "/home/ubuntu/emcc_ffmpeg_2")
include_directories(${ffmpeg_dir}/include)
link_directories(${ffmpeg_dir}/lib)
link_libraries(libavcodec.a libavutil.a libswresample.a libswscale.a)
# 将源代码添加到此项目的可执行文件。
add_executable (${ProgramName} "emcc/emcc_define.h" "test/test1.cpp" "main.cpp" "video/real_video/real_video.cpp" "ffmpeg/FFMPEG_Common.h" "h264/h264decoder.h" "h264/h264decoder.cpp")
if (CMAKE_HOST_UNIX)
message("current platform: Linux")
elseif (CMAKE_HOST_WIN32)
message("current platform: Windows")
else()
message("current platform: unknown")
endif()
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET EmccVideo PROPERTY CXX_STANDARD 20)
endif()
# TODO: 如有需要,请添加测试并安装目标。
测试的html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Emscripten:Export1</title>
</head>
<body>
<script>
Module = {};
Module.onRuntimeInitialized = function() {
console.log(Module._show_me_the_answer());
console.log(Module._add(12, 1.0));
Module._print_ffmpeg_avcodec_configuration();
}
</script>
<script src="./build/EmccVideo.js"></script>
</body>
</html>
测试文件
- emcc_define.h
#ifndef EMCC_DEFINE_H
#ifndef EM_PORT_API
# if defined(__EMSCRIPTEN__)
# include <emscripten.h>
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE
# else
# define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE
# endif
# else
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype
# else
# define EM_PORT_API(rettype) rettype
# endif
# endif
#endif
#endif // ! EMCC_DEFINE_H
- FFMPEG_Common.h
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/version.h>
#include <libavutil/avutil.h>
#include <libavutil/frame.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
#endif // FFMPEG_COMMON_H
- test.cpp
#include "../../emcc/emcc_define.h"
#include "FFMPEG_Common.h"
#include <stdio.h>
EM_PORT_API(int)
print_ffmpeg_avcodec_configuration()
{
printf(avcodec_configuration());
return 0;
}
注意事项
- 加载ffmpeg的头文件时,需要添加如下标识,否则链接库时找不到对应符号。
extern "C"
{}
标签:Web,enable,emscripten,ffmpeg,--,emcc,disable,include
From: https://www.cnblogs.com/ganshang/p/17107442.html