您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
ffmpeg-kit的使用(android studio第三方庫、依賴的使用)編譯安卓libx264編譯輸出aar
发布时间:2021-06-20 21:21:20编辑:雪饮阅读()
-
Declare
mavenCentral
repository and addFFmpegKit
dependency to yourbuild.gradle
inffmpeg-kit-<package name>
pattern. Use one of theFFmpegKit
package names given in the project README.repositories { mavenCentral() } dependencies { implementation 'com.arthenica:ffmpeg-kit-full:4.4.LTS' }
AndroidStudio第三方庫的使用或者説是第三方依賴的使用,一般第三方依賴都是如一個git倉庫,例如這裏的https://github.com/tanersener/ffmpeg-kit/tree/main/android開源項目,該項目有個使用説明如:
3. Using
3.1 Android API
它這裏就有說如何加入依賴,這裏的dependencies是位於app/build.gradle:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.penguinvideoedit"
minSdkVersion 25
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
packagingOptions {//加上这写代码
//pickFirst 'jquery/jszip-utils/dist/jszip-utils.js'
//pickFirst 'jquery/jquery-ui.js'
//pickFirst 'package-search-index.js'
//pickFirst 'jquery/jquery-ui.structure.min.css'
//pickFirst 'index.html'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
/*
sourceSets {
main {
jniLibs.srcDirs = ["libs"]
}
}
*/
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//ndkVersion '21.4.7075529'
//android.ndkPath 'D\\:\\\\ndk\\\\android-ndk-r21e'
ndkPath "D:\\ndk\\android-ndk-r21e"
/*
android {
ndkPath "/Users/ndkPath/ndk21" // pointing to your own NDK
}
*/
}
dependencies {
//implementation(name:'ffmpeg-kit-full-4.4.LTS', ext:'aar')
//implementation 'com.arthenica:ffmpeg-kit-full:4.4.LTS'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':ffmpeg-kit-full-4.4.LTS')
implementation fileTree(dir: 'D:\\AndroidStudioProjects\\penguinvideoedit\\com.arthenica\\smart-exception-java\\0.1.0', include: ['*.aar', '*.jar'], exclude: [])
implementation fileTree(dir: 'D:\\AndroidStudioProjects\\penguinvideoedit\\com.arthenica\\smart-exception-common\\0.1.0', include: ['*.aar', '*.jar'], exclude: [])
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
}
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.penguinvideoedit"
minSdkVersion 25
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
packagingOptions {//加上这写代码
//pickFirst 'jquery/jszip-utils/dist/jszip-utils.js'
//pickFirst 'jquery/jquery-ui.js'
//pickFirst 'package-search-index.js'
//pickFirst 'jquery/jquery-ui.structure.min.css'
//pickFirst 'index.html'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
/*
sourceSets {
main {
jniLibs.srcDirs = ["libs"]
}
}
*/
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//ndkVersion '21.4.7075529'
//android.ndkPath 'D\\:\\\\ndk\\\\android-ndk-r21e'
ndkPath "D:\\ndk\\android-ndk-r21e"
/*
android {
ndkPath "/Users/ndkPath/ndk21" // pointing to your own NDK
}
*/
}
dependencies {
//implementation(name:'ffmpeg-kit-full-4.4.LTS', ext:'aar')
//implementation 'com.arthenica:ffmpeg-kit-full:4.4.LTS'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':ffmpeg-kit-full-4.4.LTS')
implementation fileTree(dir: 'D:\\AndroidStudioProjects\\penguinvideoedit\\com.arthenica\\smart-exception-java\\0.1.0', include: ['*.aar', '*.jar'], exclude: [])
implementation fileTree(dir: 'D:\\AndroidStudioProjects\\penguinvideoedit\\com.arthenica\\smart-exception-common\\0.1.0', include: ['*.aar', '*.jar'], exclude: [])
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
}
像我這裏就是用了該依賴,不過也注釋了,因爲我最後想用的是將該依賴進行本地化,因爲我還有自己的定制。
./android.sh
該脚本希望你提供sdk目錄以及ndk目錄,這點可以查看該編譯脚本源代碼,那麽這裏sdk目錄和ndk目錄的提供以環境變量來的,如:
root@xy-virtual-machine:~# cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
#export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export ANDROID_HOME=/usr/local/android-sdk-linux
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export ANDROID_SDK_ROOT=/usr/local/android-sdk-linux
export ANDROID_NDK_ROOT=/disk2/lost+found/android-ndk-r21e
當然這裏別忘了source一下
那麽這裏讓你看看這兩個目錄結構是怎樣的
當然這個脚本使用時候要注意,這裏以如下命令舉例:
./android.sh --enable-gpl --enable-x264 --disable-arm-v7a --disable-arm-v7a-neon --disable-x86 --disable-x86-64
這裏gpl是必要的,這個是ffmpeg編譯時候就有的,至少ffmpeg4.3.2中就是如此,要想支持libx264即--enable-x264選項,則gpl協議是前提。
後面幾個disable都是爲了禁止掉幾個不必要的架構,因爲該脚本還需要你提前編譯好一個合適的libx264,并且頭文件和庫文件正好能被該脚本所能搜尋路徑中找到。
關於什麽是合適的libx264,以及如何編譯(交叉編譯)可以參見https://www.gaojiupan.cn/manshenghuo/chengxurensheng/3797.html此文
關於這裏說需要你提前編譯好一個合適的libx264,這個是我個人實踐所知,不一定正確,反正我這裏如果沒有提前編譯好這個合適的libx264就無法正常編譯成功。
而我這裏編譯的所謂的合適的libx264就是arm64的,所以不要有其它那幾個架構,如果你不禁用,則脚本會還要編譯那幾個架構,由於那幾個架構沒有合適的libx264,所以會導致可能整個整個編譯不成功,可能會影響到比如你的目標架構是arm64(這點是我猜測的,反正我是看到沒有禁用之前,編譯過程中有錯誤,但是爲了謹慎起見總之最好我們不必要的架構都禁用了,萬一影響到我們的目標架構了呢,反正我測試的時候好像是沒有禁用,就導致最後沒有成功吧,好像是沒有生成aar吧)。
編譯成功一般都是能夠成功生成aar文件的。生成與prebuilt目录下。
最後就是編譯過程中的一些調試技巧分享,在編譯過程中android.sh如果有錯誤可以查看同目錄下的build.log,如果這個日志文件中還有一些錯誤,不夠詳細,那麽大多錯誤是來自ffmpeg的錯誤,那麽此時可以查看同目錄下的src\ffmpeg中的config.log。
好,那麽今天的分享就先到這裏了,咱們下期見。
補充:android.sh更多編譯選項,也可以通過./android.sh --help來查看。
关键字词:ffmpeg-kit
相关文章
-
无相关信息