ffmpeg4.3 ndk编译,andorid调用ffmepg解码rtsp 坑坑总结

编程入门 行业动态 更新时间:2024-10-08 04:32:09

ffmpeg4.3  ndk编译,andorid调用ffmepg解码rtsp <a href=https://www.elefans.com/category/jswz/34/1420203.html style=坑坑总结"/>

ffmpeg4.3 ndk编译,andorid调用ffmepg解码rtsp 坑坑总结

ffmpeg4.3 nkd编译
编译过程:
1.下载源码
我编译的是ffmpeg4.3版本

git clone .git ffmpeg

2.改写configure文件
找到注释掉的这几行,用下面的替换

#SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
#LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
#SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
#SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'  
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'  
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'  
SLIB_INSTALL_LINKS='$(SLIBNAME)' 

3.编写android_arm64-v8a_build.sh脚本

#!/bin/bash
NDK=/home/whuna/Android/Sdk/ndk/21.1.6352462
ADDI_LDFLAGS="-fPIE -pie"
ADDI_CFLAGS="-fPIE -pie -march=armv8-a -mfloat-abi=softfp -mfpu=neon"
CPU=armv8-a
ARCH=arm64
SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
PREFIX=$(pwd)/android/$CPU
configure()
{./configure \--prefix=./android \--enable-cross-compile \--disable-x86asm \--target-os=android \--arch=$ARCH \--sysroot=$SYSROOT \--cc=$TOOLCHAIN/aarch64-linux-android21-clang \--cxx=$TOOLCHAIN/aarch64-linux-android21-clang++ \--strip=$TOOLCHAIN/aarch64-linux-android-strip \--extra-cflags="$ADDI_CFLAGS" \--extra-ldflags="$ADDI_LDFLAGS" \--disable-x86asm \--disable-neon \--disable-hwaccels \--disable-gpl \--disable-postproc \--enable-shared \--enable-jni \--disable-mediacodec \--disable-decoder=h264_mediacodec \--disable-static \--disable-doc \--disable-ffmpeg \--disable-ffplay \--disable-ffprobe \--disable-avdevice \--disable-doc \--disable-symver \}build()
{configuremake cleanmake -j8make install
}build

4.命令行运行脚本即可

sh android_arm64-v8a_build.sh.sh

andoird调用
1.创建一个带ndk的工程
2. 将编译好的库放到对应的文件夹中

  1. 修改CMakeLists.txt文件
# For more information about using CMake with Android Studio, read the
# documentation: .html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.10.2)project("androidsdktest")#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffast-math")set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")# disable rtti and exceptions
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.add_library(libopencv_java4 SHARED IMPORTED)
# change this folder path to yours
set_target_properties(libopencv_java4 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libopencv_java4.so)
include_directories(${CMAKE_SOURCE_DIR}/ncnn-android-vulkan-lib/include/ncnn)add_library(libffmpeg_warp SHARED IMPORTED)
set_target_properties(libffmpeg_warpPROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libffmpeg_warp.so
)add_library(libavcodec SHARED IMPORTED)
set_target_properties(libavcodecPROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libavcodec.so
)add_library(libavformat SHARED IMPORTED)
set_target_properties(libavformatPROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libavformat.so
)add_library(libswresample SHARED IMPORTED)
set_target_properties(libswresamplePROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libswresample.so
)add_library(libswscale SHARED IMPORTED)
set_target_properties(libswscalePROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libswscale.so
)add_library(libavutil SHARED IMPORTED)
set_target_properties(libavutilPROPERTIESIMPORTED_LOCATION${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libavutil.so
)add_library( # Sets the name of the library.native-lib# Sets the library as a shared library.SHARED# Provides a relative path to your source file(s).native-lib.cpp )# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.find_library( # Sets the name of the path variable.log-lib# Specifies the name of the NDK library that# you want CMake to locate.log )# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.target_link_libraries( # Specifies the target library.native-liblibffmpeg_warplibavcodeclibavformatlibavutillibswscalelibswresamplelibopencv_java4# Links the target library to the log library# included in the NDK.${log-lib} )
target_include_directories(native-libPUBLIC${CMAKE_SOURCE_DIR}/libs/include
)
  1. 在native.cpp中调用接口
    1.avformat_open_input 总返回-13的错误,是由于权限问题
    在AndroidManifest.xml中增加读写权限和网络权限
    <uses-permission android:name="android.permission.CAMERA"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.INTERNET" />

2.可以通过如下方式打印错误码对应的提示信息

 result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);result = -13;if (result < 0) {char errStr[256] = { 0 };av_strerror(result, errStr, sizeof(errStr));std::cout << errStr << std::endl;av_log(NULL, AV_LOG_ERROR, "Can't open file\n");return result;}

更多推荐

ffmpeg4.3 ndk编译,andorid调用ffmepg解码rtsp 坑坑总结

本文发布于:2024-03-12 09:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1731258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:坑坑   ndk   andorid   rtsp   ffmepg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!