精华内容
参与话题
问答
  • Android编译FFmpeg

    千次阅读 2019-08-14 17:49:06
    1、环境配置 1.系统:Linux虚拟机 Distributor ID: Ubuntu Description: Ubuntu 18.04.2 LTS Release: 18.04 Codename: bionic ...根据自己需求添加编写脚本,这里只是简单的使用 ...echo "进入编译ffmpeg脚本" ND...

    1、环境配置

    • 1.系统:Linux虚拟机
    Distributor ID:	Ubuntu
    Description:	Ubuntu 18.04.2 LTS
    Release:	18.04
    Codename:	bionic
    
    

    2、脚本命令

    根据自己需求添加编写脚本,这里只是简单的使用

    #!/bin/bash
    echo "进入编译ffmpeg脚本"
    NDK=/home/hou/NDK/android-ndk-r14b
    PLATFORM=$NDK/platforms/android-21/arch-arm
    TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
    CPU=armv7-a
    #输出路径
    PREFIX=./android/$CPU
    function build
    {
    	echo "start ffmpeg"
    	./configure \
        --prefix=$PREFIX \
        --target-os=android \
        --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
        --arch=arm \
        --cpu=armv7-a  \
        --sysroot=$PLATFORM \
        --extra-cflags="-I$PLATFORM/usr/include -fPIC -DANDROID -mfpu=neon -mfloat-abi=softfp " \
        --cc=$TOOLCHAIN/bin/arm-linux-androideabi-gcc \
        --nm=$TOOLCHAIN/bin/arm-linux-androideabi-nm \
        --enable-shared \
        --enable-runtime-cpudetect \
        --enable-gpl \
        --enable-small \
        --enable-cross-compile \
        --enable-asm \
        --enable-neon \
        --enable-jni \
        --enable-mediacodec \
        --enable-decoder=h264_mediacodec \
        --enable-hwaccel=h264_mediacodec \
        --disable-debug \
        --disable-static \
        --disable-doc \
        --disable-ffmpeg \
        --disable-ffplay \
        --disable-ffprobe \
        --disable-postproc \
        --disable-avdevice \
        --disable-symver \
        --disable-stripping 
        make -j16
        make install
    	echo "end!"
    }
    
    build
    

    注意: 给脚本添加权限,我直接给了777

    chmod 777 bulid_android.sh
    ./bulid_android.sh   //运行脚本
    

    编译出结果有对应的 so 和 include 文件夹

    3、创建JNI 项目

    3.1 项目配置

    3.1.1 将2中生成的文件拷贝到项目中

    1. 将include复制到项目中
    2..so复制到libs
    

    3.1.2 配置项目的build

    android {
        compileSdkVersion 28
        defaultConfig {
            ...
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++11"
                }
                ndk{
                    abiFilters("armeabi-v7a")
                }
            }
            sourceSets{
                main{
                    jniLibs.srcDirs=['libs']
                }
            }
        }
      ...
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
    }
    

    3.1.3 配置项目的CMakeLists.txt

    # 添加头文件路径
    include_directories(include)
    #设置ffmpeg库所在路径的变量
    set(FFMPEG ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI})
    #设置ffmpeg 导入库
    add_library(avcodec SHARED IMPORTED)
    #导入库那个库
    set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG}/libavcodec.so)
    
    
    target_link_libraries( # Specifies the target library.
                           native-lib
                           android
                           avcodec
                           # Links the target library to the log library
                           # included in the NDK.
                           ${log-lib} )
    

    3.2 引用avcodec.h

    #include <jni.h>
    #include <string>
    #include <android/log.h>
    extern "C"{
        #include <libavcodec/avcodec.h>
    }
    
    extern "C" JNIEXPORT jstring JNICALL
    Java_com_billshuai_testplayer_MainActivity_stringFromJNI(
            JNIEnv* env,
            jobject /* this */) {
        std::string hello = "Hello from C++";
        hello += avcodec_configuration();
        return env->NewStringUTF(hello.c_str());
    }
    
    展开全文
  • android 编译FFmpeg

    2015-08-26 16:42:42
    参考来源 : ... 编译ffmpeg库按照文中的说明在linux环境下编译成功。 文中有些许文字和格式错误,一下为正确的。 build_android.sh: #!/bin/bash NDK=/home/dennis/android-nd

    参考来源 : http://blog.csdn.net/gobitan/article/details/22750719


    编译ffmpeg库按照文中的说明在linux环境下编译成功。


    文中有些许文字和格式错误,以下为正确的。

    build_android.sh:


        #!/bin/bash  
        NDK=/home/dennis/android-ndk-r9d  
        SYSROOT=$NDK/platforms/android-9/arch-arm/  
        TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64  
          
        function build_one  
        {  
        ./configure \
            --prefix=$PREFIX \
            --enable-shared \
            --disable-static \
            --disable-doc \
            --disable-ffserver \
            --enable-cross-compile \
            --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
            --target-os=linux \
            --arch=arm \
            --sysroot=$SYSROOT \
            --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
            --extra-ldflags="$ADDI_LDFLAGS" \
            $ADDITIONAL_CONFIGURE_FLAG  
        }  
        CPU=arm
        PREFIX=$(pwd)/android/$CPU
        ADDI_CFLAGS="-marm"
        build_one

    Android.mk:

        LOCAL_PATH := $(call my-dir)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=avcodec-55-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libavcodec-55.so  
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=avdevice-55-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libavdevice-55.so  
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=avfilter-4-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libavfilter-4.so
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=avformat-55-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libavformat-55.so  
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=  avutil-52-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libavutil-52.so
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=  avswresample-0-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libswresample-0.so  
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=  avswscale-2-prebuilt  
        LOCAL_SRC_FILES :=prebuilt/libswscale-2.so  
        include $(PREBUILT_SHARED_LIBRARY)  
           
        include $(CLEAR_VARS)  
        LOCAL_MODULE :=ffmpeg_codec  
        LOCAL_SRC_FILES :=cn_dennishucd_FFmpegNative.c  
           
        LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid  
        LOCAL_SHARED_LIBRARIES:= avcodec-55-prebuilt avdevice-55-prebuilt avfilter-4-prebuilt avformat-55-prebuilt avutil-52-prebuilt    
        include $(BUILD_SHARED_LIBRARY) 

    static{  
                                    System.loadLibrary("avutil-52");  
                                    System.loadLibrary("avcodec-55");  
                                    System.loadLibrary("swresample-0");  
                                    System.loadLibrary("avformat-55");  
                                    System.loadLibrary("swscale-2");  
                                    System.loadLibrary("avfilter-4");  
                                    System.loadLibrary("ffmpeg_codec");  
                    }  
                    publicnative int avcodec_find_decoder(int codecID);  




    展开全文
  • Android编译ffmpeg

    2017-09-18 17:30:47
    DEMO:https://github.com/zhaopingfu/FFmpegDemoffmpeg下载地址:...创建ffmpeg文件夹mkdir ffmpeg cd ffmpeg 下载ffmpegwget http://ffmpeg.org/releases/ffmpeg-2.6.9.tar.gz 解压tar -xzf ffmpeg-2.6.9

    DEMO:https://github.com/zhaopingfu/FFmpegDemo

    ffmpeg下载地址:https://ffmpeg.org/releases/

    创建ffmpeg文件夹

    mkdir ffmpeg
    cd ffmpeg
    

    下载ffmpeg

    wget http://ffmpeg.org/releases/ffmpeg-2.6.9.tar.gz
    

    解压

    tar -xzf ffmpeg-2.6.9.tar.gz
    

    给权限

    chmod 777 -R ffmpeg-2.6.9
    

    进入ffmpeg-2.6.9里面,创建build_android.sh,在里面写入配置

    #!/bin/bash
    #注意下面这几个,把路径修改为自己的
    export NDK=/usr/ndk/android-ndk-r15b
    export SYSROOT=$NDK/platforms/android-9/arch-arm/
    export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
    
    export CPU=arm
    export PREFIX=$(pwd)/android/$CPU
    export ADDI_CFLAGS="-marm"
    
    ./configure --target-os=linux \
    --prefix=$PREFIX --arch=arm \
    --disable-doc \
    --enable-shared \
    --disable-static \
    --disable-yasm \
    --disable-symver \
    --enable-gpl \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-doc \
    --disable-symver \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
    $ADDITIONAL_CONFIGURE_FLAG
    make clean
    make
    make install
    

    执行build_android.sh

    ./build_android.sh
    

    发现问题

    编译后会在当前路径下生成/android/arm/lib和/android/arm/include
    但是在lib中生成的so库文件的名字有点不太对,是libavdevice.so.56
    我们想要的是libavdevice-56.so
    所以
    cd ../../../

    解决问题

    在ffmpeg里找到configure文件,编辑configure文件

    在2779行修改

    #把原来的命名规则注掉
    #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)'
    	#zhaopf 修改生成的so库的命名规则                                        
    	SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
    	LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
    SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
    SLIB_INSTALL_LINKS='$(SLIBNAME)'
    

    这样在当前目录下会生成一个android文件加,里面的lib下有想要的.so库

    这里写图片描述

    在AndroidStudio中配置

    app下的build.gradle中

    defaultConfig {
        applicationId "com.pf.ffmpegdemo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        sourceSets{
            main{
                jniLibs.srcDirs = ['libs']
            }
        }
        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions"
                abiFilters 'armeabi'
            }
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    
    #寻找SDK中自带的库
    #路径:\SDK\ndk-bundle\platforms\android-23\arch-arm\usr\lib
    find_library( log-lib
                  log )
    
    #设置变量
    set(DIR ../../../../libs)
    
    add_library(avcodec-56
                SHARED
                IMPORTED)
    set_target_properties( avcodec-56
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libavcodec-56.so)
    
    add_library(avdevice-56
                SHARED
                IMPORTED)
    set_target_properties( avdevice-56
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libavdevice-56.so)
    
    add_library(avfilter-5
                SHARED
                IMPORTED)
    set_target_properties( avfilter-5
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libavfilter-5.so)
    
    add_library(avformat-56
                SHARED
                IMPORTED)
    set_target_properties( avformat-56
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libavformat-56.so)
    
    add_library(avutil-54
                SHARED
                IMPORTED)
    set_target_properties( avutil-54
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libavutil-54.so)
    
    add_library(postproc-53
                SHARED
                IMPORTED)
    set_target_properties( postproc-53
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libpostproc-53.so)
    
    add_library(swresample-1
                SHARED
                IMPORTED)
    set_target_properties( swresample-1
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libswresample-1.so)
    
    add_library(swscale-3
                SHARED
                IMPORTED)
    set_target_properties( swscale-3
                           PROPERTIES IMPORTED_LOCATION
                           ${DIR}/armeabi/libswscale-3.so)
    
    #引入include下的头文件
    include_directories(libs/include)
    #include_directories(src/main/cpp/include)
    
    #引入自己的库
    add_library( native-lib
                 SHARED
                 src/main/cpp/native-lib.cpp )
    
    #链接的目标库
    target_link_libraries( native-lib
                           avcodec-56
                           avdevice-56
                           avfilter-5
                           avformat-56
                           avutil-54
                           postproc-53
                           swresample-1
                           swscale-3
                           ${log-lib} )
    

    这样就可以了,编译可以通过

    展开全文
  • Android 编译ffmpeg

    2016-05-14 11:00:58
    首先我是在mac下编译ffmpeg, 下载了android 的SDK 在这之前就已经编译过了x264, 如果你不要x264, 则可以关闭x264选项 或者直接下载已经编译好的x264库如果脚本没有权限, 执行一下 chmod 777 ./build_ffmpeg.sh ...

    首先我是在mac下编译的ffmpeg, 下载了android 的SDK
    在这之前就已经编译过了x264, 如果你不要x264, 则可以关闭x264选项
    或者直接下载已经编译好的x264库

    如果脚本没有权限, 执行一下
    chmod 777 ./build_ffmpeg.sh (你的脚本名)

    #!/bin/bash
    
    ANDROID_NDK="/Users/RunningDay/Library/Android/sdk/ndk-bundle"
    SDK_VERSION=21
    #ARCH=arm64
    ARCH=arm
    
    if [ "$ARCH" = "arm64" ]
    then
        PLATFORM_PREFIX="aarch64-linux-android-"
        HOST="aarch64"
        X264_LIB=$(pwd)/../x264-lib-android/arm64
        PLATFORM_VERSION=4.9
    else
        PLATFORM_PREFIX="arm-linux-androideabi-"
        HOST="arm"
        X264_LIB=$(pwd)/../x264-lib-android/arm
        PLATFORM_VERSION=4.8
    fi
    
    PREFIX=$(pwd)/android/${ARCH}
    
    SYSROOT=$ANDROID_NDK/platforms/android-${SDK_VERSION}/arch-${ARCH}
    TOOLCHAIN=$ANDROID_NDK/toolchains/${PLATFORM_PREFIX}${PLATFORM_VERSION}/prebuilt/darwin-x86_64
    CC=$TOOLCHAIN/bin/${PLATFORM_PREFIX}gcc
    CXX=$TOOLCHAIN/bin/${PLATFORM_PREFIX}c++
    CROSS_PREFIX=$TOOLCHAIN/bin/${PLATFORM_PREFIX}
    NM=$TOOLCHAIN/bin/${PLATFORM_PREFIX}nm
    
    CFLAGS="-Os -fpic -DANDROID -std=c99"
    CFLAGS="$CFLAGS -I${SYSROOT}/usr/include"
    CFLAGS="$CFLAGS -I$X264_LIB/include"
    
    LDFLAGS="-L${SYSROOT}/usr/lib"
    LDFLAGS="$LDFLAGS -L$X264_LIB/lib"
    LDFLAGS="$LDFLAGS -llog -lc -lm -ldl -lx264"
    
    echo "--extra-cflags="$CFLAGS""
    echo "--extra-ldflags="$LDFLAGS""
    echo ${PREFIX}
    
    ./configure \
    --prefix=$PREFIX \
    --target-os=linux --arch=${ARCH} --enable-cross-compile \
    --cc=$CC \
    --cxx=$CXX \
    --cross-prefix=$CROSS_PREFIX \
    --nm=$NM \
    --sysroot=$SYSROOT \
    --extra-cflags="$CFLAGS" \
    --extra-ldflags="$LDFLAGS" \
    --enable-version3 \
    --enable-nonfree \
    --disable-shared --enable-static --disable-debug --enable-pthreads --disable-stripping \
    --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver \
    --enable-network --enable-postproc --enable-gpl \
    --enable-protocols \
    --enable-muxers \
    --enable-demuxers \
    --disable-devices \
    --enable-avfilter --enable-bsfs --enable-filters \
    --disable-encoders \
    --enable-libx264 --enable-encoder=libx264 \
    --enable-encoder=mjpeg --enable-encoder=aac \
    --disable-decoders \
    --enable-decoder=h264 \
    --enable-decoder=aac \
    --enable-decoder=aac_latm \
    --enable-decoder=ac3 \
    --enable-decoder=mp3 \
    --enable-decoder=pcm_alaw \
    --enable-decoder=pcm_s8 \
    --enable-decoder=pcm_s8_planar \
    --enable-decoder=pcm_u16be \
    --enable-decoder=pcm_u16le \
    --enable-decoder=pcm_u8 \
    --enable-decoder=pcm_mulaw \
    --enable-decoder=pcm_s16be \
    --enable-decoder=pcm_s16le \
    --enable-decoder=pcm_s16le_planar \
    --enable-decoder=movtext \
    --enable-decoder=text \
    --disable-symver \
    --disable-doc --disable-asm --enable-neon \
    --pkg-config=/usr/bin/pkg-config \
    
    
    # "$?" is configure result
    if [ $? -ne 0 ];then
    echo "configure fail..."
    exit $?;
    fi
    
    echo ""
    echo "###################################"
    echo "Configure success ..."
    echo "###################################"
    echo ""
    
    #make clean
    #make -j8
    #make install
    
    

    修改一下ANDROID_NDK的路径为自己的NDK路径
    SDK_VERSION=你的SDK版本
    ARCH=你要编译的平台(arm 或者arm64)

    最后生成的ffmpeg库

    展开全文
  • android 编译 ffmpeg

    2016-09-21 14:21:08
    公司需要完成一个能够加速播放的视频的播放器,这是个比较头疼的问题,传统的视频播放器都没有这个功能,特别是android 更是无从下手。网上找了很多资料,最后决定使用ffmpeg+opengl es 自己实现这个播放器。开始的...
  • android 编译ffmpeg

    2016-02-02 15:47:57
    ffmpeg版本:2.2.16 1、新见build.sh并执行:#!/bin/bash NDK=/Users/gz/Downloads/android-ndk-r10e/ SYSROOT=$NDK/platforms/android-18/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt...
  • android编译ffmpeg+x264

    2016-02-24 08:53:14
    android编译ffmpeg+x264 编译x264: 下载最新版的x264 ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ 1.解压到指定的目录 2.切换当前目录为该目录 3.创建一个shell脚本build_x264.sh,内容如下: ...
  • Android编译FFmpeg类库

    2017-09-19 14:17:17
    FFmpeg使用第一步,编译FFmpeg源码 –> .so 库。 编译环境 Mac OS X Capitan 10.11.3NDK-r10e (64-bit)FFmpeg 3.0 准备工作 下载安装NDK 下载地址下载FFmpeg源码 下载地址 编译过程 ...
  • 我使用的系统ubuntu18.04,先编译FFmpeg,成功之后再添加X264的库。 编译FFmpeg的脚本如下: #!/bin/bash #!/bin/bash NDK=/home/hong/Public/android-ndk-r14b SYSROOT=$NDK/platforms/android-21/arch-ar...
  • Android 编译FFmpeg x264

    2017-06-09 19:40:36
    原文:... 1. Android FFmpeg开发基本流程 (1)X264/FFmpeg + NDK编译  (2)ffmpeg.so + 编解码C代码  (3)Android.mk 编译  (4)JNI  (5)Java代码调用 基本流程如下图
  • android编译ffmpeg+x264+faac http://blog.csdn.net/vblittleboy/article/details/24316303 1. 在x264的源码目录下创建b1.sh,内容如下: 点击(此处)折叠或打开 export NDK=/opt/google/android/android-ndk...
  • 自己写了一个音视频的小Demo,编译时,报了一个错,记录一下,避免下次再犯这种奇葩错误!!! libavformat/utils.c:5548: error: undefined reference to 'av_bitstream_filter_filter' libavformat/codec2.c:74: ...
  • 1、X264编译NDK=/home/lb/Android/NDk/android-ndk-r14b SYSROOT=$NDK/platforms/android-19/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 CPREFIX=$TOOLCHAIN/bin/arm-...
  • 环境: Mac电脑 Mac下的NDK:android-ndk-r14b-darwin-x86_64.zip FFmpeg-release-3.3.zip 1. 解压FFmpeg-release-3.3.zip,目录结构如下: ...如果直接按照未修改的配置进行编译,结果编译出来的so文件类似l
  • ffmpeg官方推荐Android平台编译的开源工程: ffmpeg-android-maker ubuntu下的编译工具:clang、make、yasm等,这里如果没有安装,编译时候会有提示,按照提示apt install 就可以 Android sdk、ndk,这里可以直接去...

空空如也

1 2 3 4 5 ... 20
收藏数 2,581
精华内容 1,032
热门标签
关键字:

android 编译ffmpeg