ExoPlayer播放器播放MP2音频格式视频无声音加入Ffmpeg软解码功能

ExoPlayer播放器不支持MP2音频格式,在播放视频为MP2音频格式的视频时,在华为悦盒E6108C系列的盒子上没有声音,为解决问题添加ExoPlayer的扩展ffmpeg软解码库,历时4天终于完成

准备:参考ExoPlayer的github文档

git ExoPlayer到本地

windows安装cygwin 参考:https://blog.csdn.net/chunleixiahe/article/details/55666792

下载按android-ndk-r15c 官方说一定要15c版本

接下来的步骤参考 ExoPlayer下面的ffmpeg文档

一下是按照文档编译过程中所遇到的问题:

1.问题:$ export TMPDIR = E:/cygwin/tmp-bash: export: `=': 不是有效的标识符-bash: export: `E:/cygwin/tmp': 不是有效的标识符

解决:=号两边不要有空格

2.Unknown option "–-enable-decoder=mp3".See ./configure --help for available options.

解决: mp3后面必须是一个空格+\

3.​{FFMPEG_EXT_PATH}"/jni && \

${NDK_PATH}/ndk-build APP_ABI="armeabi-v7a arm64-v8a x86" -j4-bash: F:\Android\android-ndk-r15c/ndk-build: No such file or directory

解决:路径/隔开

4.$ ./build.sh./build.sh:行21: $'\r': 未找到命令./build.sh: 第 22 行

/jni/ffmpeg: No such file or directory./build.sh:行23: ./configure: No such file or directory./build.sh:行24: --libdir=android-libs/armeabi-v7a: No such file or directory./build.sh:行25: --arch=arm: 未找到命令./build.sh:行26: --cpu=armv7-a: 未找到命令./build.sh:行27: --cross-prefix=/toolchains/arm-linux-androideabi-4.9/prebuilt//bin/arm-linux-androideabi-: No such file or directory./build.sh:行28: --sysroot=/platforms/android-9/arch-arm/: No such file or directory./build.sh:行29: --extra-cflags=-march=armv7-a -mfloat-abi=softfp: 未找到命令./build.sh:行30: --extra-ldflags=-Wl,--fix-cortex-a8: 未找到命令./build.sh:行31: --extra-ldexeflags=-pie: 未找到命令./build.sh:行32: $'\\r': 未找到命令./build.sh:行33: 未预期的符号 `&&' 附近有语法错误'/build.sh:行33: ` && \

解决:分步执行命令

5.

$ ./configure \

--libdir=android-libs/armeabi-v7a \--arch=arm \--cpu=armv7-a \--cross-prefix="​{HOST_PLATFORM}/bin/arm-linux-androideabi-" \--sysroot="${NDK_PATH}/platforms/android-9/arch-arm/" \--extra-cflags="-march=armv7-a -mfloat-abi=softfp" \--extra-ldflags="-Wl,--fix-cortex-a8" \--extra-ldexeflags=-pie \${COMMON_OPTIONS} \&& \

F:/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc is unable to create an executable file.C compiler test failed.

If you think configure made a mistake, make sure you are using the latestversion from Git. If the latest version fails, report the problem to [email protected] mailing list or IRC #ffmpeg on irc.freenode.net.Include the log file "ffbuild/config.log" produced by configure as this will helpsolve the problem.

解决:--prefix=/cygdrive/f/android/android-ndk-r10b/sources/ffmpeg-release-3.0/android/arm -->

--prefix=F:/android/android-ndk-r10b/sources/ffmpeg-release-3.0/android/arm

--cross-prefix=/cygdrive/f/android/android-ndk-r10b/toolchains -->

--cross-prefix=F:/android/android-ndk-r10b/toolchains

--sysroot=/cygdrive/f/android/android-ndk-r10b/platforms/android-18/arch-arm/ -->

--sysroot=F:/android/android-ndk-r10b/platforms/android-18/arch-arm/

 

6.LD libavresample/libavresample.so.4f:/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so:1:1: syntax error, unexpected '!', expecting $endf:/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so: not an object or archivecollect2.exe: error: ld returned 1 exit statusmake: *** [ffbuild/library.mak:103:libavresample/libavresample.so.4] 错误 1make: *** 正在等待未完成的任务....f:/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so:1:1: syntax error, unexpected '!', expecting $endf:/android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so: not an object or archivecollect2.exe: error: ld returned 1 exit statusmake: *** [ffbuild/library.mak:103:libavcodec/libavcodec.so.58] 错误 1

 

解决:移除libavutil.so 复制libavutil-56.so更名为libavutil.so

cd ffmpeg-release-3.0/libavutil/ rm libavutil.so cp libavutil/libavutil.so.55 libavutil/libavutil.so

原因:原因是Maybe NDK still dosen’t support cygwin fully.需要删除symbolic links,然后直接用文件替代

 

7.libavutil/libavutil.so: file not recognized: File format not recognizedcollect2.exe: error: ld returned 1 exit statuslibavutil/libavutil.so: file not recognized: File format not recognizedcollect2.exe: error: ld returned 1 exit statusmake: *** [ffbuild/library.mak:103:libavresample/libavresample-4.so] 错误 1make: *** 正在等待未完成的任务....make: *** [ffbuild/library.mak:103:libavcodec/libavcodec-58.so] 错误 1

 

解决:修改configure文件:

android)

disable symver

enable section_data_rel_ro

SLIB_INSTALL_NAME='$(SLIBNAME)'

SLIB_INSTALL_LINKS=

SHFLAGS='-shared -Wl,-soname,$(SLIBNAME)'

----> 增加ln_s="cp -f"

android)

disable symver

enable section_data_rel_ro

ln_s="cp -f"

SLIB_INSTALL_NAME='$(SLIBNAME)'

SLIB_INSTALL_LINKS=

SHFLAGS='-shared -Wl,-soname,$(SLIBNAME)'

 

8.$ ${NDK_PATH}/ndk-build APP_ABI="armeabi-v7a arm64-v8a" -j4-bash: /cygdrive/f/Android/android-ndk-r15c/ndk-build: No such file or directory

 

解决:打开cmd窗口执行

 

9.ndk-build APP_ABI="armeabi-v7a arm64-v8a" -j4Android NDK: android-9 is unsupported. Using minimum supported version android-14.Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in E:/hkk/ExoPlayer-release-v2/extensions/ffmpeg/src/main/AndroidManifest.xml. NDK binaries will not be comptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.[armeabi-v7a] Install : libavcodec.so => libs/armeabi-v7a/libavcodec.so[armeabi-v7a] Install : libavresample.so => libs/armeabi-v7a/libavresample.so[armeabi-v7a] Install : libavutil.so => libs/armeabi-v7a/libavutil.so[armeabi-v7a] Install : libffmpeg.so => libs/armeabi-v7a/libffmpeg.so[armeabi-v7a] Install : libavcodec.so => libs/arm64-v8a/libavcodec.so[armeabi-v7a] Install : libavresample.so => libs/arm64-v8a/libavresample.so[armeabi-v7a] Install : libavutil.so => libs/arm64-v8a/libavutil.so[armeabi-v7a] SharedLibrary : libffmpeg.soE:/hkk/ExoPlayer-release-v2/extensions/ffmpeg/src/main/obj/local/arm64-v8a/libavcodec.so: error adding symbols: File in wrong formatclang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [E:/hkk/ExoPlayer-release-v2/extensions/ffmpeg/src/main/obj/local/arm64-v8a/libffmpeg.so] Error 1

 

解决:分别执行ndk-build APP_ABI="armeabi-v7a" -j4 和ndk-build APP_ABI="arm64-v8a" -j4

 

10.F:/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc is unable to create an executable file.C compiler test failed.

If you think configure made a mistake, make sure you are using the latestversion from Git. If the latest version fails, report the problem to [email protected] mailing list or IRC #ffmpeg on irc.freenode.net.Include the log file "ffbuild/config.log" produced by configure as this will helpsolve the problem.

 

解决:添加临时路径export TMPDIR="E:/cygwin/tmp"

 

11.F:/Android/android-ndk-r15c//toolchains/arm-linux-androideabi-4.9/prebuilt//bin/arm-linux-androideabi-gcc is unable to create an executable file.C compiler test failed.

If you think configure made a mistake, make sure you are using the latestversion from Git. If the latest version fails, report the problem to [email protected] mailing list or IRC #ffmpeg on irc.freenode.net.Include the log file "ffbuild/config.log" produced by configure as this will helpsolve the problem.

解决:NDK_PATH多了“/”,HOST_PLAYFORM更变为HOST_PLATFORM

 

另附:Android Studio中build项目时报错Execution failed for task ':extension-ffmpeg:compileReleaseNdk'.

com.android.ide.common.process.ProcessException: Error while executing 'F:\Android\sdk\ndk-bundle\ndk-build.cmd' with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=E:\hkk\ExoplayerTest\extensions\ffmpeg\buildout\intermediates\ndk\release\Android.mk APP_PLATFORM=android-25 NDK_OUT=E:\hkk\ExoplayerTest\extensions\ffmpeg\buildout\intermediates\ndk\release\obj NDK_LIBS_OUT=E:\hkk\ExoplayerTest\extensions\ffmpeg\buildout\intermediates\ndk\release\lib APP_ABI=armeabi-v7a,armeabi}

解决:添加sourceSets.main { jniLibs.srcDir 'src/main/libs' jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.}

 

特别致谢:https://blog.csdn.net/openswc/article/details/53287144

https://blog.csdn.net/xdestiny110/article/details/79366371

参考文献:https://blog.csdn.net/cmsbupt/article/details/46819009

https://github.com/google/ExoPlayer/tree/release-v2/extensions/ffmpeg

http://tieba.baidu.com/p/4522087962

你可能感兴趣的:(Android)