Ubuntu FFmpeg编译

///Ubuntu FFmpeg 编译

第一次编译的时候遇到很多问题,各种测试,最后终于成功。。。

  1. 准备:FFmepg3.2.1

下载链接:http://ffmpeg.org/releases/ffmpeg-3.2.1.tar.gz

  1. Ubuntu 18

下载连接:http://211.162.127.20/files/1239000006D7AC14/mirrors.yun-idc.com/ubuntu-releases/18.10/ubuntu-18.10-desktop-amd64.iso

下载完成安装之后可能没有安装make工具,自己安装即可

  1. NDK下载

https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2

环境准备完成后,开始准备脚本build_android.sh

build_android.sh

#!/bin/bash
make clean
#填写你具体的ndk解压目录
export NDK=/home/ime/ffmpeg/android-ndk-r9b
export SYSROOT=$NDK/platforms/android-8/arch-arm/
#arm-linux-androideabi-4.6 要确保NDK下这个目录存在,还有ndk需要与 ubuntu的版本位数对应上,我这里都是64位
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
export CPU=arm
#编译后的文件会放置在 当前路径下的android/arm/下
export PREFIX=$(pwd)/android/$CPU
export ADDI_CFLAGS="-marm"
 
 
#./configure 即为ffmpeg 根目录下的可执行文件configure
#你可以在ffmpeg根目录下使用./configure --hellp 查看 ./configure后可填入的参数。
 
./configure --target-os=linux \
    --prefix=$PREFIX --arch=arm \
    --disable-doc \
    --enable-static \    #编译静态库
    --disable-shared \   #禁止编译动态库
    --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_CFLAGS" \
    $ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install

编译完成后会生成这两个目录ubuntu

最后在eclispse上建立工程并编译测试

android.mk如下

# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)

include $(CLEAR_VARS)
$(warning jnipath=$(LOCAL_PATH)) #在Android.mk中打印输出信息的方法是:$(warning string)或者$(error string)  $(info string)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := libavcodec.a
LOCAL_CFLAGS :=-Ilibavcodec
LOCAL_EXPORT_C_INCLUDES := libavcodec
LOCAL_EXPORT_CFLAGS := -Ilibavcodec
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)	#编译动态库

include $(CLEAR_VARS)
LOCAL_MODULE := avdevice
LOCAL_SRC_FILES := libavdevice.a
LOCAL_CFLAGS :=-Ilibavdevice
LOCAL_EXPORT_C_INCLUDES := libavdevice
LOCAL_EXPORT_CFLAGS := -Ilibavdevice
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
LOCAL_SRC_FILES := libavfilter.a
LOCAL_CFLAGS :=-Ilibavfilter
LOCAL_EXPORT_C_INCLUDES := libavfilter
LOCAL_EXPORT_CFLAGS := -Ilibavfilter
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := libavformat.a
LOCAL_CFLAGS :=-Ilibavformat
LOCAL_EXPORT_C_INCLUDES := libavformat
LOCAL_EXPORT_CFLAGS := -Ilibavformat
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := libavutil.a
LOCAL_CFLAGS :=-Ilibavutil
LOCAL_EXPORT_C_INCLUDES := libavutil
LOCAL_EXPORT_CFLAGS := -Ilibavutil
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := postproc
LOCAL_SRC_FILES := libpostproc.a
LOCAL_CFLAGS :=-Ilibpostproc
LOCAL_EXPORT_C_INCLUDES := libpostproc
LOCAL_EXPORT_CFLAGS := -Ilibpostproc
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES := libswresample.a
LOCAL_CFLAGS :=-Ilibswresample
LOCAL_EXPORT_C_INCLUDES := libswresample
LOCAL_EXPORT_CFLAGS := -Ilibswresample
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := libswscale.a
LOCAL_CFLAGS :=-Ilibswscale
LOCAL_EXPORT_C_INCLUDES := libswscale
LOCAL_EXPORT_CFLAGS := -Ilibswscale
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := FFmpegUtil
LOCAL_SRC_FILES := FFmpegUtil.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
#$(warning LOCAL_C_INCLUDES=$(LOCAL_PATH)/include) 
LOCAL_LDLIBS    := -llog -lm -lz -ljnigraphics

###the flowing static libaraies must order
LOCAL_STATIC_LIBRARIES += avformat avcodec avutil swscale avfilter avdevice swresample postproc  

include $(BUILD_SHARED_LIBRARY)

完成

 

编译过程中遇到的问题

 

javah生成方法名字

1、

javah -classpath 包名文件夹路径 -d 头文件输出路径 -jni 包名.类名(不带.class)

-classpath <路径> 用于装入类的路径。注意是包名文件夹的路径,不是class的路径,如果没有包名的话就是class的路径。

-d <目录> 输出目录

-jni 生成 JNI样式的头文件(默认)

 

javah -classpath classes  -d jniheader -jni com.test.ffmpeg.domo.jni.FFmpegJni

 

路径中包含bitmap失败情况处理:

没有找到Bitmap是因为Java没有Bitmap类,将对应的C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-25\android.jar包添加到classpath即可,注意两个路径中间加分号。全部命令为:

Eg:

javah -classpath D:\adt-bundle-windows-x86_64-20131030\sdk\platforms\android-19\android.jar;classes  -d jniheader -jni com.test.ffmpeg.domo.jni.FFmpegJni

发布了16 篇原创文章 · 获赞 4 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览