diff --git a/build_ffmpeg.md b/ffmpeg.md similarity index 55% rename from build_ffmpeg.md rename to ffmpeg.md index 4fa5c2d..f263f04 100644 --- a/build_ffmpeg.md +++ b/ffmpeg.md @@ -69,4 +69,101 @@ sudo make install cd nv-codec-headers make sudo make install - ``` \ No newline at end of file + ``` + +编译ffmeg arm64版本 + +在源码目录下创建buildarm64.sh,内容如下 + +```shell +#!/bin/bash + +export NDK=~/android/android-ndk-r20b #这里配置先你的 NDK 路径 +TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64 + +# 编译到安卓上,尽可能小一些(--enable-small),只是用来解码,也就取消编译封装编码相关的 +function build_android +{ + +./configure \ +--disable-programs \ +--disable-avdevice \ +--disable-encoders \ +--disable-muxers \ +--disable-filters \ +--enable-neon \ +--enable-gpl \ +--disable-sdl2 \ +--disable-postproc \ +--disable-debug \ +--enable-small \ +--enable-static \ +--enable-shared \ +--disable-doc \ +--enable-ffmpeg \ +--disable-ffplay \ +--disable-ffprobe \ +--disable-avdevice \ +--disable-doc \ +--disable-symver \ +--prefix=$PREFIX \ +--cross-prefix=$CROSS_PREFIX \ +--target-os=android \ +--arch=$ARCH \ +--cpu=$CPU \ +--cc=$CC \ +--cxx=$CXX \ +--enable-cross-compile \ +--sysroot=$SYSROOT \ +--extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \ +--extra-ldflags="$ADDI_LDFLAGS" + + +make clean +make -j16 +make install + +echo "============================ build android arm64-v8a success ==========================" + +} + +#arm64-v8a +ARCH=arm64 +CPU=armv8-a +API=21 +CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang +CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++ +SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot +CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android- +PREFIX=$(pwd)/android/$CPU +OPTIMIZE_CFLAGS="-march=$CPU" + +build_android + + +``` + +```shell +chomd +x buildarm64.sh +./buildarm64.sh +# 编译好后,对应的源文件和库文件会安装到./android/armv-v8a中 +``` + +## 硬编码 + +```c++ +// 与软编码相比,没有很多额外的配置 +// 仅仅是在查找编码器时按名称查找 hevc_nvenc ,其余和软编码一样 +auto pCodec = avcodec_find_encoder_by_name("hevc_nvenc"); +// ... +// 其次就是注意软编码出来的每一帧数据 前面都会带有SEI增强帧,关键帧后面才是I帧或者P帧 + auto naluHeader = (pkt->data[4] & 0x7E) >> 1; // 前四个字节是0x00 00 00 01 分隔符 + if (naluHeader == 39) { // SEI + auto header = getNextSplit(pkt->data, pkt->size); // 往后找,跳过这个SEI + if (header == nullptr) + return 0; + naluHeader = ((*header) & 0x7E) >> 1; + // cout << "naluHeader: " << naluHeader << endl; + } +``` + diff --git a/flutter_plugin.md b/flutter_plugin.md new file mode 100644 index 0000000..807484c --- /dev/null +++ b/flutter_plugin.md @@ -0,0 +1,76 @@ +# flutter plugin + +创建插件命令 + +```shell +flutter create --template=plugin --platforms=windows,android yourname +``` + +--platforms 可以指定支持哪些平台,如 windows,macos,ios,android,linux + +如果没有创建相应平台目录,可以使用下面的命令开启相应的平台 + +```bash +flutter config --enable-linux-desktop # 开启linux 桌面 +flutter config --enable-macos-desktop # 开启macos 桌面 +flutter config --enable-ios # 开启ios +# 更多的命令可以通过help查看 +flutter config --help +``` + +## Android安卓 + +1. gradle文件配置 + + ```gradle + defaultConfig { + minSdkVersion 19 + ndk { + // 只编译arm64 + abiFilters "arm64-v8a" + } + + externalNativeBuild { + // 依赖的自定义cmake路径 + cmake { + arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_STL=c++_shared" + path "../src/CMakeLists.txt" + } + } + consumerProguardFiles "consumer-rules.pro" + } + // 一部分动态库需要安装时一并打包,避免出现找不到依赖的动态库 + sourceSets { + main { + // 指定动态库路径 安卓的需要的动态库我放到了../src/bin/arm64-v8a, 在指定时只需要到bin即可,但是一定得放到arm64-v8a里面 + jniLibs.srcDirs = ['../src/bin/'] + } + } + ``` + +2. cmake 文件 + + ```cmake + # 安卓使用 + cmake_minimum_required(VERSION 3.18) + + set(PROJECT_NAME "pass_track") + project(${PROJECT_NAME}) # CXX + # 包含头文件搜索目录和库的搜索目录 + # 指定所有需要编译的头文件和源文件${all_sources} ${all_headers} + add_library(${PROJECT_NAME} SHARED + ${all_sources} + ${all_headers} + ) + + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden) + + target_compile_definitions(${PROJECT_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) + target_link_libraries(${PROJECT_NAME} PRIVATE 。。。) + + + + ``` + + \ No newline at end of file