MAC M1系统编译ffmpeg-gl-transition

参考文档:
【gl-transitions配置】原项目dockerfile修改,为视频添加转场效果
【gitee】 ffmpeg-gl-transition

1. 本人系统

在这里插入图片描述

2. 编译💰系统准备

2.1. 下载【ffmpeg-gl-transition】到用户家目录下,并解压

(base)  ~/ffmpeg-gl-transition/ ll
total 88
-rw-rw-r--@ 1 admin  staff   2.8K  9  6  2019 Dockerfile
-rw-rw-r--@ 1 admin  staff   9.2K  9  6  2019 README.md
-rw-rw-r--@ 1 admin  staff   851B  9  6  2019 concat.sh
-rw-rw-r--@ 1 admin  staff   164B  9  6  2019 crosswarp.glsl
-rw-rw-r--@ 1 admin  staff   1.0K  9  6  2019 ffmpeg.diff
drwxrwxr-x@ 7 admin  staff   224B  9  6  2019 media
-rw-rw-r--@ 1 admin  staff    15K  9  6  2019 vf_gltransition.c

在这里插入图片描述

2.2 下载ffmpeg源码

我看网上都是说的ffmpeg-4.2.2。因此我也是下载的ffmpeg-4.2.2

wget http://www.ffmpeg.org/releases/ffmpeg-4.2.2.tar.gz
tar -zxvf ffmpeg-4.2.2.tar.gz
cd ffmpeg-4.2.2
# get ffmpeg sources
(base)  ~/software/ffepeg/ wget http://www.ffmpeg.org/releases/ffmpeg-4.2.2.tar.gz
(base)  ~/software/ffepeg/ tar -zxvf ffmpeg-4.2.2.tar.gz
(base)  ~/software/ffepeg/ ll
total 26752
drwx------  45 admin  staff   1.4K  6 14 20:44 ffmpeg-4.2.2
-rw-r--r--   1 admin  staff    13M  1  1  2020 ffmpeg-4.2.2.tar.gz
(base)  ~/software/ffepeg/ 
(base)  ~/software/ffepeg/ cd ffmpeg-4.2.2
(base)  ~/software/ffepeg/ffmpeg-4.2.2/

2.3. brew安装GLEW + glfw3

(base)  ~/software/ffepeg/ brew install glew glfw
(base)  ~/software/ffepeg/ 
(base)  ~/software/ffepeg/ brew list glew                                
/opt/homebrew/Cellar/glew/2.2.0_1/bin/glewinfo
/opt/homebrew/Cellar/glew/2.2.0_1/bin/visualinfo
/opt/homebrew/Cellar/glew/2.2.0_1/include/GL/ (3 files)
/opt/homebrew/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib
/opt/homebrew/Cellar/glew/2.2.0_1/lib/cmake/ (4 files)
/opt/homebrew/Cellar/glew/2.2.0_1/lib/pkgconfig/glew.pc
/opt/homebrew/Cellar/glew/2.2.0_1/lib/ (3 other files)
/opt/homebrew/Cellar/glew/2.2.0_1/sbom.spdx.json
/opt/homebrew/Cellar/glew/2.2.0_1/share/doc/ (20 files)
(base)  ~/software/ffepeg/ 
(base)  ~/software/ffepeg/ brew list glfw
/opt/homebrew/Cellar/glfw/3.4/include/GLFW/ (2 files)
/opt/homebrew/Cellar/glfw/3.4/lib/libglfw.3.4.dylib
/opt/homebrew/Cellar/glfw/3.4/lib/cmake/ (4 files)
/opt/homebrew/Cellar/glfw/3.4/lib/pkgconfig/glfw3.pc
/opt/homebrew/Cellar/glfw/3.4/lib/ (3 other files)
/opt/homebrew/Cellar/glfw/3.4/sbom.spdx.json
/opt/homebrew/Cellar/glfw/3.4/share/doc/ (204 files)

2.4 复制vf_gltransition.c文件到ffmpeg

(base)  ~/software/ffepeg/ffmpeg-4.2.2/ cp ~/ffmpeg-gl-transition/vf_gltransition.c libavfilter/

2.5 修改ffmpeg源码文件

  1. 修改点
    通过cat ~/ffmpeg-gl-transition/ffmpeg.diff我们可以看到有两个文件要改。
    libavfilter/Makefile
    libavfilter/allfilters.c
    这个我就不说了,git大家应该都熟悉。
(base)  ~/ffmpeg-gl-transition/ cat ffmpeg.diff 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index a90ca30ad7..c0fc73be46 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -367,6 +367,7 @@ OBJS-$(CONFIG_YADIF_FILTER)                  += vf_yadif.o
 OBJS-$(CONFIG_ZMQ_FILTER)                    += f_zmq.o
 OBJS-$(CONFIG_ZOOMPAN_FILTER)                += vf_zoompan.o
 OBJS-$(CONFIG_ZSCALE_FILTER)                 += vf_zscale.o
+OBJS-$(CONFIG_GLTRANSITION_FILTER)           += vf_gltransition.o
 
 OBJS-$(CONFIG_ALLRGB_FILTER)                 += vsrc_testsrc.o
 OBJS-$(CONFIG_ALLYUV_FILTER)                 += vsrc_testsrc.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 6eac828616..0570c1c2aa 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -357,6 +357,7 @@ extern AVFilter ff_vf_yadif;
 extern AVFilter ff_vf_zmq;
 extern AVFilter ff_vf_zoompan;
 extern AVFilter ff_vf_zscale;
+extern AVFilter ff_vf_gltransition;
 
 extern AVFilter ff_vsrc_allrgb;
 extern AVFilter ff_vsrc_allyuv;
(base)  ~/ffmpeg-gl-transition/ 

2.6 设置库目录和头文件目录

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib

3. configure & make

./configure --enable-libx264 --enable-gpl --enable-opengl \
            --enable-filter=gltransition --extra-libs='-lGLEW -lglfw'
make

不指定库目录,configure会抛错ffmpeg gcc is unable to create an executable file C compiler test failed。如下。其实从ffbuild/config.log文件可以看到是无法连接到GLEW

gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “ffbuild/config.log” produced by configure as this will help
solve the problem.

不指定头文件目录,make会抛错fatal error: 'GLFW/glfw3.h' file not found
在这里插入图片描述

4. 结果验证

make没有异常后,可以看到只有二进制文件生成的。
在这里插入图片描述
./ffmpeg -v 0 -filters | grep gltransition

(base)  ~/software/ffepeg/ffmpeg-4.2.2/ ./ffmpeg -v 0 -filters | grep gltransition
 T.. gltransition      VV->V      OpenGL blend transitions
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ 
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ 
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ 
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ cp -r ~/ffmpeg-gl-transition ./
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ ll
...
drwxr-xr-x    18 admin  staff   576B  1  1  2020 compat
-rw-r--r--     1 admin  staff    77K  6 14 20:22 config.h
-rwxr-xr-x     1 admin  staff   246K  1  1  2020 configure
drwxr-xr-x   149 admin  staff   4.7K  6 14 20:40 doc
drwxr-xr-x    13 admin  staff   416B  6 14 20:22 ffbuild
-rwxr-xr-x     1 admin  staff    17M  6 14 20:40 ffmpeg
drwxr-xr-x@   10 admin  staff   320B  6 14 20:42 ffmpeg-gl-transition
-rwxr-xr-x     1 admin  staff    20M  6 14 20:40 ffmpeg_g
-rwxr-xr-x     1 admin  staff    17M  6 14 20:40 ffprobe
-rwxr-xr-x     1 admin  staff    20M  6 14 20:40 ffprobe_g
drwxr-xr-x    29 admin  staff   928B  6 14 20:40 fftools
drwxr-xr-x  3152 admin  staff    99K  6 14 20:40 libavcodec
...

4.1 使用方法

  1. 默认选项:
    ./ffmpeg -i ffmpeg-gl-transition/media/0.mp4 -i ffmpeg-gl-transition/media/1.mp4 -filter_complex gltransition -y out.mp4
(base)  ~/software/ffepeg/ffmpeg-4.2.2/ ./ffmpeg -i ffmpeg-gl-transition/media/0.mp4 -i ffmpeg-gl-transition/media/1.mp4 -filter_complex gltransition -y out.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --enable-libx264 --enable-gpl --enable-opengl --enable-filter=gltransition --extra-libs='-lglew -lglfw'
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
...
  1. 自定义选项:

./ffmpeg -i media/0.mp4 -i media/1.mp4 -filter_complex "gltransition=duration=4:offset=1.5:source=crosswarp.glsl" -y out.mp4

在这里插入图片描述

效果

5. gl-transitions 有一些失败的问题解决

我是从这里看到的解决办法
当我开开心心编译完成后,试了一个crosswarp后发现,哈哈可以用,以为全都ok呢。试着跑了所有的转场,才发现只有一小部分可以使用。原因是uniform类型的原因,官方issue-13问题的回答

解决办法

在这里插入图片描述

6. xfade从4.3开始支持

如上使用的是4.2.2。但是4.3是从4.3才支持的,因为只有从4.3开始编译了。
https://gitee.com/mirrors/ffmpeg.git clone下来,checkout 到4.3。从头改一遍源码,增加一下特性

./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass \
  --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora \
  --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 \
  --enable-libopus --enable-libxvid \
  --enable-opengl --enable-filter=gltransition --extra-libs='-lGLEW -lglfw'

又是一大堆依赖要安装。

brew install x264
brew install nvm
brew install libass
brew install fdk-aac
brew install lame
brew install opus
brew install theora
brew install libvpx
brew install x265
brew install xvid

看看一个编译ffmpeg的网站https://trac.ffmpeg.org/wiki/CompilationGuide/macOS

  • 20
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值