安卓:如何在安卓工作室中配置最新版本的FFMPEG?

50
我想在Android Studio中配置FFmpeg,但是找不到任何相关文档或链接。尽管在Github上有许多适用于Android的FFmpeg库,但它们都是旧版本。在Android中如何运行命令?并且我想知道在配置FFmpeg后,如何运行FFmpeg命令。请帮助我,谢谢。
我已经尝试过以下链接,但没有成功使用最新版本。

http://writingminds.github.io/ffmpeg-android-java

https://github.com/WritingMinds/ffmpeg-android-java

https://github.com/havlenapetr/FFMpeg

https://github.com/appunite/AndroidFFmpeg

https://github.com/WritingMinds/ffmpeg-android


你所说的FFMPEG最新版本是什么意思?我的意思是,最新版本和你上面提供的链接有什么区别。我已经使用过FFMPEG Android并成功地创建了许多视频..!! - Janki Gadhiya
@jankigadhiya 我想在FFMPEG中使用reverse命令,但并不是所有库都能从上面提供的链接中正常工作。 - Ravi Vaghela
@jankigadhiya 我需要使用反转命令或易于反转视频的方式吗? - Ravi Vaghela
但是最新版本可以使用反向命令。 - Ravi Vaghela
我已经在NDK r12b上执行了它,请查看我的答案更新,这是Android Studio的完整设置..!! - Janki Gadhiya
@jankigadhiya 你也用SDK做过吗?我需要关于SDK的帮助。 - Narendra Singh
4个回答

37

FFMPEG的最新版本是3.1.1,仅在12天前发布。因此我认为没有像这个旧版本那样随时可用的演示

我们需要自己构建FFMPEG库。我在这里贴出一些问题,可能会对你有所帮助。(未经测试)

如何为Android构建FFmpeg

  1. 使用Android NDK r10编译FFmpeg 2.3
  2. 如何在Windows上使用android-ndk-r10d编译ffmpeg-2.5.3
  3. 如何在Windows上使用cygwin和android ndk r9c编译ffmpeg-2.2.2
  4. 如何在Windows上使用android-ndk-r10d构建FFmpeg
您需要自己编译它,方法是下载Android NDK最新版本的FFMPEG。 还有一篇教程:如何为Android构建FFmpeg。这篇教程比较老,所以您只需要更改这里提到的版本。对于FFMPEG,它将是3.1.1,对于NDK,它将是r12b

使用 NDK r12b 构建 FFMPEG

  1. 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

  2. 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.

  3. 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)
    
  4. 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
    
  5. 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.

  6. Make ffmpeg Libraries available for Your Projects
以下步骤已经过充分测试,我在我的机器上执行了这些步骤,并且构建成功。在撰写答案时,我参考了这篇文章《如何使用NDK r9构建FFmpeg》(How to Build ffmpeg with NDK r9),但是由于它是针对旧版本的,因此我进行了一些自己的更正。
欢迎提出任何疑问。

让我们在聊天中继续这个讨论 - Jaydeep Devda
2
你好,我正在使用Ubuntu,在执行./build_android.sh命令后出现了以下错误:/configure: 3244: ./configure: 语法错误:重定向意外。 ./build_android.sh: 第8行:--prefix=/home/techniche/Android/ndk/android-ndk-r12b/sources/ffmpeg-3.1.3/android/arm:没有那个文件或目录。 - pranavjayadev
1
我已经成功地使用了您的脚本来处理 ffmpeg 3.1.4,但是在完成后没有生成 android 文件夹(第5步)的输出,而是生成了包含 .o.d、make 文件等文件夹。如何获取 .so 文件呢? - Volodymyr Kulyk
2
嗨@jankigadhiya..我发现在执行build_android.sh时出现了问题,错误:./build_android.sh:第8行:--prefix=/home/controller/Android/Sdk/ndk-bundle/ffmpeg-3.2.2/android/arm:没有这个文件或目录。 - Angad Tiwari
谢谢你的回答。我按照你说的做了,但是我收到了这个错误信息:./build_android.sh: 34: ./build_android.sh: build_one: not found !!! - Davood Falahati
显示剩余4条评论

13

我想使用最新版本的FFMPEG。 - Ravi Vaghela
谢谢。你帮我节省了2到3天的时间。 - Ankita Shah
@RaviVaghela: 你找到最新版本的解决方案了吗? - Anand Savjani

5

你是否看到了这个链接Writingminds提供的FFmpeg库,所有解释都在这个链接中。

该库writingmind的最新版本在这里https://github.com/WritingMinds/ffmpeg-android-java/releasesenter image description here

如果您想使用任何库的最新版本,可以直接从build.gradle中进行,因为如果任何库未更新,则可以从build.gradle中查看并更新,我总是为许多库执行此操作以获取最新可用版本。

对于FFMpeg中的gradle,请使用以下内容

compile 'com.writingminds:FFmpegAndroid:0.3.2'

这个链接提供了更多类似的库https://android-arsenal.com/details/1/925

我建议您阅读this quethis que

如果您想使用原始库的最新版本,请访问FFmpeg [最新版本将在此处]

如果要添加本地代码,则这些博客可能会对您有所帮助

http://ffmpeg-android.blogspot.in/

http://www.roman10.net/2011/07/17/how-to-build-android-applications-based-on-ffmpeg-by-an-example/


我想使用最新版本的FFMPEG。 - Ravi Vaghela
我在我的答案中已经两次提到了最新版本@RaviVGHL。我在我的答案中给您的链接是http://writingminds.github.io/ffmpeg-android-java/,您可以直接从build.gradle更新最新的库版本。 - TapanHP
但是在这里没有使用该库构建的任何最新版本。 - Ravi Vaghela
我已经在我的答案中提供了这个信息,你可以随时从官方网站获取最新版本。 https://ffmpeg.org/download.html - TapanHP
这是过时的依赖项,请更新您的答案。 - Anand Savjani
请问您能否编辑一下这个内容,因为我已经不再从事Java和Android方面的工作,也不确定您所要求的是哪个版本?@AnandSavjani - TapanHP

1

我已经使用过几周的Android ffmpeg。

这个库叫做FFmpeg4Android,可以在 WarZone找到。

我知道标题说的是2011年12月6日,但我已经测试并且它运行得非常顺畅。你没有提及你对这个库的确切需求,但你可以在官方网站上了解ffmpeg的能力。

FFmpeg4Android有一个示例项目,可以作为很好的参考,而且他们的支持非常迅速和清晰。

命令根据您的字符串输入运行,例如:

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

如果需要进一步帮助,请告诉我,我很乐意帮忙。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接