Manually compile android webrtc and enable h.264 codec function

I wrote a blog about " webrtc enables h.264 encoding function " before, but I couldn't successfully enable h.264 decoding. Encoding H.264 is OK, but I haven't corrected the error in time, because I didn't find a simple and direct solution at that time . The method, but by manually modifying BUILD.gn and other scripts in the ffmpeg directory to realize the function of enabling h.264 decoding, is relatively too complicated. I saw an article in the webrtc discussion group by chance . I found a simple method, and I followed the relevant steps to execute it again, and it was really effective, so I made a note for emergencies, and I hope to help you in need. The detailed steps are as follows (take webrtc m70 as an example):

One use build_ffmpeg.py script

使用过ffmpeg的读者应该都清楚,在编译ffmpeg时,第一步就是要执行configure来开启或者关闭某些功能。该脚本就是执行configure,只不过它使用python脚本来实现交叉编译,参数更复杂一些而已。
 - 进入ffmpeg源码目录
   cd src/third_party/ffmpeg
   
2.执行build_ffmpeg.py脚本,并传入相关参数(根据不同的android平台传入不同的参数)
   ./chromium/scripts/build_ffmpeg.py android arm64 -- --enable-jni --enable-mediacodec --enable-decoder=h264_mediacodec,h264,h264_cuvid,h264_v4l2m2m,h264_qsv,h264_crystalhd --enable-hwaccel=h264_mediacodec --enable-parser=h264 --enable-demuxer=h264 --enable-cross-compile 

2 Use
the ./chromium/scripts/copy_config.sh script to copy the generated config.h and other related files to the relevant directory, and execute the following command:

./chromium/scripts/copy_config.sh

3 Use
the ./chromium/scripts/generate_gn.py script to generate the BUILD.gn script for compiling ffmpeg, and execute the following command:

./chromium/scripts/generate_gn.py

Four related
errors If everything is normal, please ignore this step (the following two errors occurred when I performed the above steps)

1 如果出现/usr/bin/ld相关错误,把系统中的ld临时改成别的名称
2. 如果出现GNU assembler not found, install/updadte gas-preprocessor错误,在build_ffmpeg.py参数的最后面加上--disable-asm

Five compile webrtc

Go back to the webrtc source code directory (./src), and perform related configuration and compilation (execute the following commands):

gn gen out/arm-v8a --args='target_os="android" target_cpu="arm64" is_debug=true rtc_include_tests=false rtc_build_examples=false use_rtti=true rtc_use_h264=true proprietary_codecs=true ffmpeg_branding="Chrome"'
ninja -C out/arm-v8a

In this way, libwebrtc.a is finally generated, which can encode and decode h.264 normally.

Guess you like

Origin blog.csdn.net/TopsLuo/article/details/100559687