ffmpeg编译支持AVS3编解码

  1. libuavs3d
    ffmpeg的官方源码中已经支持了libuavs3d解码器的接口(libavcodec/libuavs3d.c中定义),因此如果需要编译ffmpeg支持libuavs3d解码器,只需要安装libuavs3d.so以及开启ffmpeg的编译选项即可。
    安装libuavs3d解码器
#代码仓库
git clone https://github.com/uavs3/uavs3d.git
#可以参考其仓库说明安装,这里使用linux平台
apt install gawk cmake #安装依赖
cd uavs3d
mkdir build/linux
cd build/linux
cmake -DCOMPILE_10BIT=1 -DBUILD_SHARED_LIBS=1 --install-prefix=/usr ../..
make && make install

libuavs3d会安装的文件:

/usr/lib/libuavs3d.so
/usr/include/uavs3d.h
/usr/lib/pkgconfig/uavs3d.pc

如果编译得时候没有-DBUILD_SHARED_LIBS,则uavs3d不会生成libuavs3d.so,静态链接生成uavs3dec可执行文件,这样ffmpeg就不能使用libuavs3d库了。

  1. libuavs3e
    ffmpeg官方源码中还未添加对libuavs3e库的支持,需要做一点修改。
    安装libuavs3e编码器
#代码仓库
git clone https://github.com/uavs3/uavs3d.git
apt install gawk cmake #安装依赖
cd uavs3e
mkdir build/linux
cd build/linux
cmake -DCOMPILE_10BIT=1 -DBUILD_SHARED_LIBS=1 --install-prefix=/usr ../..
make && make install

uavs3e安装的文件比uavs3d的多一个

/usr/lib/libuavs3e.so
/usr/include/uavs3e/uavs3e.h
/usr/include/uavs3e/com_api.h
/usr/lib/pkgconfig/uavs3e.pc

ffmpeg添加libuavs3e.c及接口支持

#libavs3e.c开源代码仓库
git clone https://github.com/uavs3/uavs3e_ffmpeg_interface.git

ffmpeg中configure修改以及allcodecs.c修改:

diff --git a/configure b/configure
index 838e627084..e95345aaf2 100755
--- a/configure
+++ b/configure
@@ -279,6 +279,7 @@ External library support:
                            if openssl, gnutls or mbedtls is not used [no]
   --enable-libtwolame      enable MP2 encoding via libtwolame [no]
   --enable-libuavs3d       enable AVS3 decoding via libuavs3d [no]
+  --enable-libuavs3e       enable AVS3 encoding via libuavs3e [no]
   --enable-libv4l2         enable libv4l2/v4l-utils [no]
   --enable-libvidstab      enable video stabilization using vid.stab [no]
   --enable-libvmaf         enable vmaf filter via libvmaf [no]
@@ -1898,6 +1899,7 @@ EXTERNAL_LIBRARY_LIST="
     libtheora
     libtwolame
     libuavs3d
+    libuavs3e
     libv4l2
     libvmaf
     libvorbis
@@ -3443,6 +3445,7 @@ libsvtav1_encoder_deps="libsvtav1"
 libtheora_encoder_deps="libtheora"
 libtwolame_encoder_deps="libtwolame"
 libuavs3d_decoder_deps="libuavs3d"
+libuavs3e_encoder_deps="libuavs3e"
 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
 libvorbis_decoder_deps="libvorbis"
 libvorbis_encoder_deps="libvorbis libvorbisenc"
@@ -6836,6 +6839,7 @@ enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame
                              { check_lib libtwolame twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
                                die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
 enabled libuavs3d         && require_pkg_config libuavs3d "uavs3d >= 1.1.41" uavs3d.h uavs3d_decode
+enabled libuavs3e         && require_pkg_config libuavs3e "uavs3e >= 1.1.41" uavs3e.h uavs3e_enc
 enabled libv4l2           && require_pkg_config libv4l2 libv4l2 libv4l2.h v4l2_ioctl
 enabled libvidstab        && require_pkg_config libvidstab "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
 enabled libvmaf           && require_pkg_config libvmaf "libvmaf >= 2.0.0" libvmaf.h vmaf_init
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b0f004e15c..9a3b95299b 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -800,6 +800,7 @@ extern const FFCodec ff_libsvtav1_encoder;
 extern const FFCodec ff_libtheora_encoder;
 extern const FFCodec ff_libtwolame_encoder;
 extern const FFCodec ff_libuavs3d_decoder;
+extern const FFCodec ff_libuavs3e_encoder;
 extern const FFCodec ff_libvo_amrwbenc_encoder;
 extern const FFCodec ff_libvorbis_encoder;
 extern const FFCodec ff_libvorbis_decoder;

编译时会报错,pkg-config找不到uavs3e,可以查看ffbuild/config.log中的具体错误,我这里是因为uavse.h头文件和uavs3e.pc中路径不匹配,直接把/usr/include/uavs3e/路径下的两个头文件拷贝到/usr/include/下面(和uavs3d.h路径一致了)

cp /usr/include/uavs3e/* /usr/include/

libuavs3e.c修改,为了适配较新的ffmpeg代码【编码还有问题】

diff --git a/libuavs3e.c b/libuavs3e.c
index a82dde7..91333d0 100644
--- a/libuavs3e.c
+++ b/libuavs3e.c
@@ -15,10 +15,16 @@
 #include "libswscale/swscale_internal.h"
 //#include "mxnet_api.h"
 
+#include "encode.h"
+#include "avcodec.h"
+#include "avs3.h"
+#include "codec_internal.h"
+
 #include "uavs3e/uavs3e.h" 
 
 #define MAX_BUMP_FRM_CNT           (8 <<1)
 #define MAX_BS_BUF                 (32*1024*1024)
+#define FF_API_CODED_FRAME          0
 
 static const int color_primaries_tab[10] = {
     AVCOL_PRI_RESERVED0   , // 0
@@ -167,7 +173,7 @@ static int uavs3e_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
 	int ret;
 
-	if (ff_alloc_packet2(avctx, pkt, MAX_BS_BUF, 0) < 0) {
+	if (ff_alloc_packet(avctx, pkt, MAX_BS_BUF) < 0) {
         return -1;
     }
 
@@ -253,26 +259,21 @@ static const AVClass uavs3e_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static const AVCodecDefault uavs3e_defaults[] = {
-    { "b",                "0" },
-    { NULL },
-};
-
-AVCodec ff_libuavs3e_encoder = {
-    .name           = "libuavs3e",
-    .long_name      = NULL_IF_CONFIG_SMALL("libuavs3e Chinese AVS3 (Audio Video Standard)"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_AVS3,
+const FFCodec ff_libuavs3e_encoder = {
+    .p.name           = "libuavs3e",
+    CODEC_LONG_NAME("libuavs3e Chinese AVS3 (Audio Video Standard)"),
+    .p.type           = AVMEDIA_TYPE_VIDEO,
+    .p.id             = AV_CODEC_ID_AVS3,
     .priv_data_size = sizeof(UAVS3EContext),
     .init           = uavs3e_init,
-    .encode2        = uavs3e_encode_frame,
+    FF_CODEC_ENCODE_CB(uavs3e_encode_frame),
     .close          = uavs3e_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
+    .p.capabilities   = AV_CODEC_CAP_DELAY,
+    .caps_internal  = FF_CODEC_CAP_AUTO_THREADS,
 #if (BIT_DEPTH == 10)
-    .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10LE, AV_PIX_FMT_NONE },
+    .p.pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10LE, AV_PIX_FMT_NONE },
 #else
-    .pix_fmts		= (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
+    .p.pix_fmts		= (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
 #endif
-    .priv_class     = &uavs3e_class,
-    .defaults       = uavs3e_defaults,
+    .p.priv_class     = &uavs3e_class,
 } ;

ffmpeg的配置选项
./configure --enable-libuavs3d --enable-libuavs3e --enable-shared --disable-stripping --enable-ffplay --prefix=/usr

  1. 效果
  • 解码播放avs3视频
    在这里插入图片描述
  • 编码yuv至avs3视频【编码出来的视频播放有问题,待调试解决】
    在这里插入图片描述
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值