java Android:如何在android studio 中配置FFMPEG 最新版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36277628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: How to configure FFMPEG latest version in android studio?
提问by Ravi Vaghela
I want to configure FFMPEG
in android studio but i cant get any document or link for that. Github on many FFMPEG
lib available for android but that all are with old version. And how to run command in android? and i want to know after configure FFMPEG
then how can we run FFMPEG
commands. Help me for that. thanks advance.
我想FFMPEG
在 android studio 中进行配置,但我无法获得任何文档或链接。Github 上有许多FFMPEG
可用于 android 的库,但都是旧版本。以及如何在android中运行命令?我想知道在配置FFMPEG
之后我们如何运行FFMPEG
命令。帮我解决这个问题。提前感谢。
I have used below links but not success in for latest version.
我使用了以下链接,但在最新版本中没有成功。
http://writingminds.github.io/ffmpeg-android-java
https://github.com/WritingMinds/ffmpeg-android-java
https://github.com/havlenapetr/FFMpeg
http://writingminds.github.io/ffmpeg-android-java
https://github.com/WritingMinds/ffmpeg-android-java
https://github.com/havlenapetr/FFMpeg
回答by Janki Gadhiya
The latest version of FFMPEG
is 3.1.1, Just released before 12 days. So i think there is no readily available demo like this oldone.
最新版本FFMPEG
是3.1.1,12天前刚刚发布。所以我认为没有像这个旧的那样现成的演示。
We need to build the FFMPEG
library on our own. Some questions i found just pasting here that might help you. (Not tested)
我们需要自己构建FFMPEG
库。我发现刚刚粘贴在这里的一些问题可能对您有所帮助。(未测试)
How to Build FFmpeg for Android
如何为 Android 构建 FFmpeg
- Compiling FFmpeg 2.3 with Android NDK r10
- How to compile ffmpeg-2.5.3 on windows with android-ndk-r10d
- How to compile ffmpeg-2.2.2 on windows with cygwin and android ndk r9c
- How to buid ffmpeg with android-ndk-r10d in windows
- 使用 Android NDK r10 编译 FFmpeg 2.3
- 如何使用android-ndk-r10d在windows上编译ffmpeg-2.5.3
- 如何使用 cygwin 和 android ndk r9c 在 windows 上编译 ffmpeg-2.2.2
- 如何在 Windows 中使用 android-ndk-r10d 构建 ffmpeg
You need to compile it on your own the by downloading Android NDK& Latest Version of FFMPEG
.
您需要通过下载Android NDK和最新版本的FFMPEG
.
One tutorial is also there : How to Build FFmpeg for Android. This is quite old so you just need to change the versions mentioned here. For FFMPEG
it will be 3.1.1
& NDK it will be r12b
.
还有一个教程:如何为 Android 构建 FFmpeg。这是很旧的所以你只需要改变这里提到的版本。因为FFMPEG
它将是3.1.1
& NDK 它将是r12b
.
Building FFMPEG
with NDK r12b:
建立FFMPEG
与NDK R12B:
Download Android NDK: The latest version of Android NDK can be downloaded at Android NDK website. At the time of writing this answer, the newest version is NDK r12. simply decompress the archive
Download ffmpeg source code: FFMPEG source code can be downloaded from the ffmpeg website. The latest stable release is 3.1.1 (at the time of writing). Download the source code and decompress it to $NDK/sources folder.
Update configure file :Open ffmpeg-3.1.1/configure file with a text editor, and locate the following lines.
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)'
This cause ffmpeg shared libraries to be compiled to libavcodec.so. (e.g. libavcodec.so.55), which is not compatible with Android build system. Therefore we'll need to replace the above lines with the following lines.
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' SLIB_INSTALL_LINKS='$(SLIBNAME)
Build ffmpeg :Copy the following text to a text editor and save it as build_android.sh in ffmpeg_3.1.1 folder.
#!/bin/bash NDK=$HOME/Desktop/adt/android-ndk-r9 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-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-doc --disable-symver --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- --target-os=linux --arch=arm --enable-cross-compile --sysroot=$SYSROOT --extra-cflags="-Os -fpic $ADDI_CFLAGS" --extra-ldflags="$ADDI_LDFLAGS" $ADDITIONAL_CONFIGURE_FLAG make clean make make install } CPU=arm PREFIX=$(pwd)/android/$CPU ADDI_CFLAGS="-marm" build_one
Once the file is saved, go to the directory where this file lies & execute the command below,
sudo chmod +x build_android.sh
Then execute the script by the command,
./build_android.sh
Build Output :The build can take a while to finish depending on your computer speed. Once it's done, you should be able to find a folder $NDK/sources/ffmpeg-3.1.1/android, which contains arm/lib and arm/include folders.
- Make ffmpeg Libraries available for Your Projects
下载Android NDK:最新版本的Android NDK 可在Android NDK 网站下载。在撰写此答案时,最新版本是 NDK r12。只需解压缩存档
下载 ffmpeg 源代码:FFMPEG 源代码可从ffmpeg 网站下载。最新的稳定版本是 3.1.1(在撰写本文时)。下载源代码并解压到 $NDK/sources 文件夹。
更新配置文件:用文本编辑器打开 ffmpeg-3.1.1/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)'
这会导致 ffmpeg 共享库被编译为 libavcodec.so。(例如 libavcodec.so.55),它与 Android 构建系统不兼容。因此,我们需要用以下几行替换以上几行。
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' SLIB_INSTALL_LINKS='$(SLIBNAME)
构建 ffmpeg :将以下文本复制到文本编辑器,并将其另存为 ffmpeg_3.1.1 文件夹中的 build_android.sh。
#!/bin/bash NDK=$HOME/Desktop/adt/android-ndk-r9 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-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-doc --disable-symver --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- --target-os=linux --arch=arm --enable-cross-compile --sysroot=$SYSROOT --extra-cflags="-Os -fpic $ADDI_CFLAGS" --extra-ldflags="$ADDI_LDFLAGS" $ADDITIONAL_CONFIGURE_FLAG make clean make make install } CPU=arm PREFIX=$(pwd)/android/$CPU ADDI_CFLAGS="-marm" build_one
保存文件后,转到该文件所在的目录并执行以下命令,
sudo chmod +x build_android.sh
然后通过命令执行脚本,
./build_android.sh
构建输出:构建可能需要一段时间才能完成,具体取决于您的计算机速度。完成后,您应该能够找到一个文件夹 $NDK/sources/ffmpeg-3.1.1/android,其中包含 arm/lib 和 arm/include 文件夹。
- 使 ffmpeg 库可用于您的项目
Steps above are fully tested and i performed them on my machine and the build was successful. For writing this answer i have took the reference from this article How to Build ffmpeg with NDK r9but as it was for older version i have made some corrections on my own.
上面的步骤已经过全面测试,我在我的机器上执行了它们并且构建成功。为了写这个答案,我参考了这篇文章如何使用 NDK r9 构建 ffmpeg,但对于旧版本,我自己做了一些更正。
Open for asking any doubts.
开放询问任何疑问。
回答by parik dhakan
I suggest you these following URLs that was helpful for me :
http://androidwarzone.blogspot.in/2011/12/ffmpeg4android.html
http://writingminds.github.io/ffmpeg-android-java/
https://androiddeveloperhelp.wordpress.com/2015/12/19/video-editing-android-example/
For knowledge:
http://www.lai18.com/content/5175900.html
Android studio Source Code:
https://drive.google.com/file/d/0B9qAjo6wKhk9MEpNNjMxaG5oWXM/view?usp=sharing
It may be help you.
我建议您使用以下对我有帮助的 URL:
http://androidwarzone.blogspot.in/2011/12/ffmpeg4android.html
http://writingminds.github.io/ffmpeg-android-java/
https://androiddeveloperhelp.wordpress.com/2015/12/19/video-editing-android-example/
对于知识:
http://www.lai18.com/content/5175900.html
安卓工作室源代码:
https://drive.google.com/file/d/0B9qAjo6wKhk9MEpNNjMxaG5oWXM/view?usp=sharing
它可能会帮助你。
回答by TapanHP
Have you seen this link Writingminds's FFmpeg library provided all explanation about it in this link
您是否看到此链接Writingminds的 FFmpeg 库在此链接中提供了有关它的所有解释
Latest Version of that library writingmind is here https://github.com/WritingMinds/ffmpeg-android-java/releases
该库writingmind的最新版本在这里https://github.com/WritingMinds/ffmpeg-android-java/releases
If you want to use latest version of any library you can do it right from in build.gradle
because if any library is not updated it can be seen and can be updated from build.gradle
, I always do this for many library for latest available version.
如果你想使用任何库的最新版本,你可以直接从 in 开始,build.gradle
因为如果任何库没有更新,它可以被看到并且可以从 更新build.gradle
,我总是对许多库执行此操作以获得最新的可用版本。
For gradle in FFMpeg use this
对于 FFMpeg 中的 gradle 使用这个
compile 'com.writingminds:FFmpegAndroid:0.3.2'
More libraries similar to it is given on this link https://android-arsenal.com/details/1/925
此链接上提供了更多类似的库 https://android-arsenal.com/details/1/925
Also i suggest you to read this que, and this que
If you want to use Latest version of Original Library go here : FFmpeg[ latest version will be here]
如果您想使用最新版本的原始库,请转到此处:FFmpeg [最新版本将在此处]
to add with native code then these blogs may help you
添加本机代码,那么这些博客可能会对您有所帮助
http://ffmpeg-android.blogspot.in/and
http://ffmpeg-android.blogspot.in/和
http://www.roman10.net/2011/07/17/how-to-build-android-applications-based-on-ffmpeg-by-an-example/
http://www.roman10.net/2011/07/17/how-to-build-android-applications-based-on-ffmpeg-by-an-example/
回答by Juvi
I've experienced with ffmpeg for android for few weeks.
我已经使用 ffmpeg for android 几个星期了。
The library called FFmpeg4Android and can be found here at WarZone.
名为 FFmpeg4Android 的库可以在 WarZone 中找到。
I know the title says it from December 6, 2011 but i've tested and worked with it and it all runs smoothly. You haven't mentioned what's your exact need with this library but you could read about the ffmpeg abilities at the official site.
我知道标题说的是 2011 年 12 月 6 日,但我已经对其进行了测试和使用,并且一切运行顺利。您还没有提到您对这个库的确切需求,但您可以在官方网站上阅读有关 ffmpeg 功能的信息。
The FFmpeg4Android has an example project that can be a great reference, and also their support is immediate and clear.
FFmpeg4Android 有一个示例项目,可以作为一个很好的参考,而且它们的支持是直接和明确的。
The commands are running according to your string input, e.g:
这些命令根据您的字符串输入运行,例如:
ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -s 160x120 -r 25 -vcodec mpeg4 -b 150k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4
ffmpeg -y -i /sdcard/videokit/in.mp4 -strict Experimental -s 160x120 -r 25 -vcodec mpeg4 -b 150k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4
let me know if you need further help, i'll be glad to help.
如果您需要进一步的帮助,请告诉我,我很乐意提供帮助。