1.第一个坑:/bin/bash^M: bad interpreter: No such file or directory
shell脚本报错/bin/bash^M: bad interpreter: No such file or directory,通过查阅资料得知,shell脚本格式必须是unix才行,但我这个脚本是在windows上编写完成传到Linux服务器上的,所以一执行就报错
windows环境下的文件是dos格式,即每行结尾以\r\n来标识,而linux下的文件是unix格式,行尾则以\n来标识
查看文件是dos还是unix的格式的方法:
1.cat -A filename,如果输出结果中行末是^M$,则是dos格式 ,如果行末只是$,则是unix格式。
2.vim filename,编辑文件,执行“:set ff”,若执行结果为fileformat=dos则为dos格式,若执行结果为fileformat=unix则为unix格式。
3.od -t x1 filename,以16进制查看文件,若输出结果中存在“0d 0a”则为dos格式,如果只有“0a”则为unix格式。其中“0d”即为回车符“\r”,“0a”即为换行符“\n”。
文件格式转换:
1.sed -i “s/\r//” filename 或sed -i “s/^M//” filename,直接将回车符替换为空字符串。
2.vim filename,编辑文件,执行“: set ff=unix”,将文件设置为unix格式,然后执行“:wq”,保存退出。
3.dos2unix filename或busybox dos2unix filename
转换成unix格式就可以正常运行脚本了
2.编译so
脚本
#!/bin/bash make clean #填写你具体的ndk解压目录 建议用相对路径 export NDK=../android-ndk-r20b export SYSROOT=$NDK/platforms/android-28/arch-arm/ export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/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-shared \ --disable-static \ --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
编译成功会生成如下目录
include是头文件 lib是so库
遇到的问题
1.编译FFMPEG时,出现了错误 nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
原因
这是因为 FFMPEG为了提高编译速度,使用了汇编指令,如MMX和SSE等。如果系统中没有yasm指令的话,就会该错误。
解决办法
安装yasm。
安装yasm
Windows系统安装yasm
如果是Windows系统, 从网上下载一个 yasm.exe 并安装在mingw/bin下面,重新编译,就不会出现该错误了。
Linux系统安装yasm
如果是Linux系统,则更简单,直接在终端输入 yum install yasm , 安装好后,重新编译就 OK了。
除了使用yum安装yasm,还可以编译安装,如下:
在http://www.tortall.net/projects/yasm/releases下面找到适合自己平台的yasm版本。然后进行安装。举例如下:
1)下载:wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
2)解压:tar zxvf yasm-1.3.0.tar.gz
3)切换路径: cd yasm-1.3.0
4)执行配置: ./configure
5)编译:make
6)安装:make install
2.执行脚本报错 缺少文件
root@realbom2-PowerEdge-R730xd:/lv1/wanglongjiang/ffmpeg/ffmpeg-6.0# ./build.sh Makefile:2: ffbuild/config.mak: No such file or directory Makefile:42: /tools/Makefile: No such file or directory Makefile:43: /ffbuild/common.mak: No such file or directory Makefile:113: /libavutil/Makefile: No such file or directory Makefile:113: /ffbuild/library.mak: No such file or directory Makefile:115: /fftools/Makefile: No such file or directory Makefile:116: /doc/Makefile: No such file or directory Makefile:117: /doc/examples/Makefile: No such file or directory Makefile:184: /tests/Makefile: No such file or directory make: *** No rule to make target '/tests/Makefile'. Stop. Unknown option "--disable-ffserver". See ./configure --help for available options. Makefile:2: ffbuild/config.mak: No such file or directory Makefile:42: /tools/Makefile: No such file or directory Makefile:43: /ffbuild/common.mak: No such file or directory Makefile:113: /libavutil/Makefile: No such file or directory Makefile:113: /ffbuild/library.mak: No such file or directory Makefile:115: /fftools/Makefile: No such file or directory Makefile:116: /doc/Makefile: No such file or directory Makefile:117: /doc/examples/Makefile: No such file or directory Makefile:184: /tests/Makefile: No such file or directory make: *** No rule to make target '/tests/Makefile'. Stop. Makefile:2: ffbuild/config.mak: No such file or directory Makefile:42: /tools/Makefile: No such file or directory Makefile:43: /ffbuild/common.mak: No such file or directory Makefile:113: /libavutil/Makefile: No such file or directory Makefile:113: /ffbuild/library.mak: No such file or directory Makefile:115: /fftools/Makefile: No such file or directory Makefile:116: /doc/Makefile: No such file or directory Makefile:117: /doc/examples/Makefile: No such file or directory Makefile:184: /tests/Makefile: No such file or directory make: *** No rule to make target '/tests/Makefile'. Stop. Makefile:2: ffbuild/config.mak: No such file or directory Makefile:42: /tools/Makefile: No such file or directory Makefile:43: /ffbuild/common.mak: No such file or directory Makefile:113: /libavutil/Makefile: No such file or directory Makefile:113: /ffbuild/library.mak: No such file or directory Makefile:115: /fftools/Makefile: No such file or directory Makefile:116: /doc/Makefile: No such file or directory Makefile:117: /doc/examples/Makefile: No such file or directory Makefile:184: /tests/Makefile: No such file or directory make: *** No rule to make target '/tests/Makefile'. Stop.
解决方法:
先不要执行make和make install,先在ffmpeg目录下执行./configure,该命令会自动生成缺少的文件