当前位置:网站首页>MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding

MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding

2022-07-07 07:17:00 xhoufei2010

1 explain

Use ffmpeg Source code , Cross compile , Support H264 and G711A Coding support

2 Environmental statement

Hardware environment : mips Architecture chip
Software environment : Linux Any version

3 principle

(1) download ffmpeg Source code , Download from official website
(2) Modify source code , Add to G711A (PCM_ALAW) Support
(3) Use cross compilation , Yes ffmpeg tailoring , In the final control 2M within

4 Operation steps

4.1 download ffmpeg Source code

from ffmpeg Download the source package on the official website , Address the following :

https://ffmpeg.org/download.html#releases

I use ffmpeg-4.4.2 edition

https://ffmpeg.org/releases/ffmpeg-4.4.2.tar.xz

 chart 4-1 ffmpeg Download address

4.2 Modify source code , increase uclibc Support for , solve sys/auxv.h: No such file or directory

If you compile directly , It will give you an error

libavutil/mips/cpu.c:26:22: fatal error: sys/auxv.h: No such file or directory

Please refer to the following patch for modification :

      
diff --git a/libavutil/mips/cpu.c b/libavutil/mips/cpu.c
index 59619d54de..c5da77b22b 100644
--- a/libavutil/mips/cpu.c
+++ b/libavutil/mips/cpu.c
@@ -19,7 +19,8 @@ 
 #include "libavutil/cpu.h"
 #include "libavutil/cpu_internal.h"
 #include "config.h"
-#if defined __linux__ || defined __ANDROID__
+#include <features.h>
+#if (defined __linux__ || defined __ANDROID__) && !defined(__UCLIBC__)
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -28,7 +29,7 @@ 
 #include "libavutil/avstring.h"
 #endif
 
-#if defined __linux__ || defined __ANDROID__
+#if (defined __linux__ || defined __ANDROID__) && !defined(__UCLIBC__)
 
 #define HWCAP_LOONGSON_CPUCFG (1 << 14)
 
@@ -105,7 +106,7 @@  static int cpu_flags_cpuinfo(void)
 
 int ff_get_cpu_flags_mips(void)
 {
    
-#if defined __linux__ || defined __ANDROID__
+#if (defined __linux__ || defined __ANDROID__) && !defined(__UCLIBC__)
     if (cpucfg_available())
         return cpu_flags_cpucfg();
     else

4.3 increase G711A Format support

modify ffmpeg-4.4.2/libavformat/movenc.c file , Refer to the following patch package for modification , You can also patch directly
This patch is for ffmpeg-4.4.2 edition , For other versions, please refer to code modification to adjust the location of the code

--- ffmpeg-4.4.2/libavformat/movenc.c	2022-04-15 04:13:38.000000000 +0800
+++ ffmpeg-4.4.2_new/libavformat/movenc.c	2022-05-18 02:28:02.335515063 +0800
@@ -1190,12 +1190,18 @@ static int mov_write_audio_tag(AVFormatC
                 track->par->codec_id == AV_CODEC_ID_ALAC ||
                 track->par->codec_id == AV_CODEC_ID_OPUS) {
    
                 avio_wb16(pb, track->par->channels);
+            } else if (track->par->codec_id == AV_CODEC_ID_PCM_ALAW) {
    
+                avio_wb16(pb, track->par->channels > 0 ?
+                              track->par->channels : 1);
             } else {
    
                 avio_wb16(pb, 2);
             }
             if (track->par->codec_id == AV_CODEC_ID_FLAC ||
                 track->par->codec_id == AV_CODEC_ID_ALAC) {
    
                 avio_wb16(pb, track->par->bits_per_raw_sample);
+            } else if (track->par->codec_id == AV_CODEC_ID_PCM_ALAW) {
    
+                avio_wb16(pb, track->par->bits_per_coded_sample > 0 ?
+                              track->par->bits_per_coded_sample : 16);
             } else {
    
                 avio_wb16(pb, 16);
             }
@@ -7208,6 +7214,7 @@ static const AVCodecTag codec_mp4_tags[]
     {
     AV_CODEC_ID_VP9,             MKTAG('v', 'p', '0', '9') },
     {
     AV_CODEC_ID_AV1,             MKTAG('a', 'v', '0', '1') },
     {
     AV_CODEC_ID_AAC,             MKTAG('m', 'p', '4', 'a') },
+    {
     AV_CODEC_ID_PCM_ALAW,        MKTAG('a', 'l', 'a', 'w') },
     {
     AV_CODEC_ID_ALAC,            MKTAG('a', 'l', 'a', 'c') },
     {
     AV_CODEC_ID_MP4ALS,          MKTAG('m', 'p', '4', 'a') },
     {
     AV_CODEC_ID_MP3,             MKTAG('m', 'p', '4', 'a') },

4.4 Cross compilation , And cut it

./configure \
--prefix=$(pwd)/output \
--enable-cross-compile --arch=mips --target-os=linux \
--cross-prefix=mips-linux-uclibc-gnu- --cc=mips-linux-uclibc-gnu-gcc-5.4.0 \
--disable-everything \
--disable-mipsfpu --disable-yasm \
--disable-autodetect \
--disable-avdevice \
--disable-avfilter \
--disable-msa \
--disable-debug \
--disable-protocols --enable-protocol=file \
--disable-demuxers --enable-demuxer=mov \
--disable-muxers --enable-muxer=mp4 --enable-muxer=mov \
--disable-decoders --enable-decoder=pcm_alaw --enable-decoder=h264  --enable-decoder=mpeg4 \
--disable-encoders --enable-encoder=pcm_s16le \
--disable-bsfs --enable-bsf=h264_mp4toannexb \
--disable-static --enable-shared \
--enable-small

explain :
–prefix=$(pwd)/output Set installation directory
–enable-cross-compile --arch=mips --target-os=linux Configure to mips framework
–cross-prefix=mips-linux-uclibc-gnu- --cc=mips-linux-uclibc-gnu-gcc-5.4.0 Cross compiling tool chain and GCC Compiler settings
–disable-everything Close redundant items , Reduce the size of the compilation Library , This depends on your personal situation
–disable-mipsfpu --disable-yasm close mipsfpu , If you do not close the compilation, an error will be reported
–disable-autodetect close autodetect , Reduce library mention
–disable-avdevice close avdevice, Embedded devices do not need
–disable-avfilter close avfilter, The project does not need
–disable-msa close msa , The project does not need
–disable-debug \ close debug , Reduce volume

–disable-protocols --enable-protocol=file The protocol only supports file protocols , It can support the encapsulation and de encapsulation of files

–disable-demuxers --enable-demuxer=mov Support for mov Separation of format files , My project uses MP4 Format ,demuxers No, MP4 Options , however Mov Format compatible mp4

–disable-muxers --enable-muxer=mp4 --enable-muxer=mov
Support mp4 File merge , Used for packing Mp4 file

–disable-decoders --enable-decoder=pcm_alaw --enable-decoder=h264 --enable-decoder=mpeg4
The decoder only turns on pcm_alaw (g711a) h264 mpeg4 this 3 format

–disable-encoders --enable-encoder=pcm_s16le
The encoder is only on pcm_s16le Format , Because my project needs to resample the audio as PCM 16K, So we need to use encoder

–disable-bsfs --enable-bsf=h264_mp4toannexb
bsfs Turn on h264, be used for h264 File decoding , Mandatory

–disable-static --enable-shared
Make the compilation mode of Dynamic State Library

–enable-small
Make file compilation smaller

After the size of the compiled file library is finally trimmed , Pictured 4-2 Shown :
 chart 4-2 Library file size

5 Video format introduction :

Composite file : h264+g711a --> mp4 , among h264 and g711a use mips The hardware encoder of the chip , therefore ffmeg The corresponding encoder is not compiled

decode : mp4—> h264 + pcm, take h264 and pcm decode
Different projects adopt different coding formats , You need to modify the configuration parameters for yourself , If you don't know the configuration parameters , have access to

./configure --help

see

if necessary pcm To g711a, Refer to other blogs , Transcoding

https://blog.csdn.net/jenie/article/details/106298846
原网站

版权声明
本文为[xhoufei2010]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070330043683.html