# FFmpeg-PlusPlus
**Repository Path**: wencoo/FFmpeg-PlusPlus
## Basic Information
- **Project Name**: FFmpeg-PlusPlus
- **Description**: 用来加速项目使用
- **Primary Language**: Unknown
- **License**: GPL-3.0
- **Default Branch**: dev
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2023-11-08
- **Last Updated**: 2024-03-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# FFmpeg + OpenGL(GLSL) - For video edit rendering
#### Make your FFmpeg support GLSL - Graphic Rendering
> `Shader++` is a web(pc) develop application for this AVFilter:
>
> You can write and make your shaders on `Shader++`, then make it running with `FFmpeg-Plus-Opengl`
>
> https://www.zzsin.com/shaderplus.html
>
>
## English | 中文
|
|
| plusglshader [GLSL Shader](#shader-render)| Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
| plusglshader [GLSL Shader](#shader-render) | Fragments Shader:
|
|
## FFmpeg-Plus-GL-Shader ##
### FileStruct ###
* Filter Source Code Path: Plus-GL-Shader
* libavfilter.diff
* vf_plusglshader.c
* vf_lutglshader.c
### Build ###
* Dependencies
* Centos 7.x+ || Linux
* first
```shell
yum install -y glew glew-devel
yum install -y glfw glew-devel
yum install -y mesa-dri-drivers
#
# If can not compile , you need
#
yum install -y libGLEW*
yum install -y mesa
yum install -y mesa-libGLU mesa-libGLU-devel
yum install -y libXfont*
```
* second
> If on headless environments
> If you want to running on server machine without Video card
```shell
yum install -y xorg-x11-server-Xvfb
```
* Ubuntu || Linux
* first
```shell
apt-get install libglfw3-dev libglfw3
apt-get install libglew2.0 libglew-dev
```
* second
> If on headless environments
> If you want to running on server machine without Video card
```shell
apt-get install xvfb
```
* MacOS
```shell
brew install glew glfw
```
* Compile
* Download
```shell
git clone https://github.com/numberwolf/FFmpeg-Plus-OpenGL.git
git clone https://github.com/FFmpeg/FFmpeg.git # for 4.1x~4.3x
# OR: wget -O ffmpeg.tar.gz "https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n4.3.1.tar.gz"
cd FFmpeg
#
# Patch
#
cp ../FFmpeg-Plus-OpenGL/Plus-GL-Shader/vf_plusglshader.c libavfilter/
cp ../FFmpeg-Plus-OpenGL/Plus-GL-Shader/vf_lutglshader.c libavfilter/
git apply ../FFmpeg-Plus-OpenGL/Plus-GL-Shader/libavfilter.diff
```
* Build
* Needed
> --enable-opengl \
> --extra-libs='-lGLEW -lglfw' \
> --enable-filter=plusglshader \
> --enable-filter=lutglshader
* Example
```shell
#!/bin/bash
./configure \
--enable-cross-compile \
--pkg-config-flags="--static" \
--extra-ldflags="-lm -lz -llzma -lpthread" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libx264 \
--enable-nonfree \
--disable-shared \
--enable-static \
--enable-opengl \
--extra-libs='-lGLEW -lglfw' \
--enable-filter=plusglshader \
--enable-filter=lutglshader
make clean
make -j16
make install
```
### Run ###
#### shader-render ####
* Check `Plus-GL-Shader`:`plusglshader` filter
* Check Cmd
```shell
ffmpeg -help filter=plusglshader
```
* Output
```shell
ffmpeg version a0d68e65 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.10.44.4)
configuration: --enable-cross-compile --pkg-config-flags=--static --extra-ldflags='-lm -lz -llzma -lpthread' --extra-libs=-lpthread --extra-libs=-lm --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-libass --enable-libfreetype --enable-libfontconfig --enable-libfribidi --enable-libwebp --enable-nonfree --disable-shared --enable-static --enable-opengl --extra-libs='-lGLEW -lglfw' --enable-filter=plusglshader
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Filter plusglshader
Generic OpenGL shader filter
Inputs:
#0: default (video)
Outputs:
#0: default (video)
plusglshader AVOptions:
sdsource
|
|
#### lut-render ####
* Check `Plus-GL-Shader`:`lutglshader` filter
* Check Cmd
```shell
ffmpeg -help filter=lutglshader
```
* Output
```shell
ffmpeg version d48da9a Copyright (c) 2000-2020 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.10.44.4)
configuration: --enable-cross-compile --pkg-config-flags=--static --extra-ldflags='-lm -lz -llzma -lpthread' --extra-libs=-lpthread --extra-libs=-lm --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-libass --enable-libfreetype --enable-libfontconfig --enable-libfribidi --enable-libwebp --enable-nonfree --disable-shared --enable-static --enable-opengl --extra-libs='-lGLEW -lglfw' --enable-filter=plusglshader
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Filter lutglshader
Render Frame by GL shader with LUT
Inputs:
#0: default (video)
Outputs:
#0: default (video)
lutglshader AVOptions:
sdsource
>
> Example image 512x512 ./lut.jpg
* `lut_type` : lut file type, 0:`Image file` ,1:`RGB24 file` (Default is 0)
* `sdsource` : Fragment shader file path (Default is gray)
* `vxsource` : Vertex shader file path (Default is gray)
* `lut_img_w` : LUT Image's width. eg: 512 (px)
* `lut_img_h` : LUT Image's height.
* `lut_lineBlockCount` : LUT Image: Count of blocks for one line. eg: (lut 512x512 's block count is 8. like here )
* `lut_oneBlockW` : LUT Image: Block's width(px, lut 512x512 's block's width is 64px)
* `start` : GL Render start timestamp
* `duration` : GL Render duration
* Filter Rules - Example
* RGB File of LUT
* `lutglshader=lut_source=./lut.rgb:lut_type=1`
* `lutglshader=lut_source=./lut.rgb:lut_type=1:duration=5:lut_img_w=512:lut_img_h=512`
* `lutglshader=lut_source=./lut.rgb:lut_type=1:duration=5:lut_img_w=512:lut_img_h=512:lut_lineBlockCount=8:lut_oneBlockW=64`
* `lutglshader=lut_source=./lut.rgb:lut_type=1:duration=5:lut_img_w=512:lut_img_h=512:lut_lineBlockCount=8:lut_oneBlockW=64:sdsource=gl/lut_shader.gl:vxsource='./lut_vertex.gl'`
* `lutglshader=lut_source=./lut.rgb:lut_type=1:start=1:duration=5:lut_img_w=512:lut_img_h=512:lut_lineBlockCount=8:lut_oneBlockW=64:sdsource=gl/lut_shader.gl:vxsource='./lut_vertex.gl'`
* Image File of LUT
* `lutglshader=lut_source=./lut.jpg`
* `lutglshader=lut_source=./lut.jpg:lut_type=0`
* `lutglshader=lut_source=./lut.jpg:lut_type=0:lut_lineBlockCount=8:lut_oneBlockW=64`
* `lutglshader=lut_source=./lut.jpg:lut_type=0:lut_lineBlockCount=8:lut_oneBlockW=64:start=1:duration=5`
* Use `lutglshader` Example
```bash
ffmpeg -v debug \
-ss 40 -t 15 -i cg.mp4 \
-filter_complex \
"lutglshader=lut_source=./lut.jpg" \
-vcodec libx264 \
-an \
-f mp4 -y output.mp4
```
* Write your own shader!
* Fragment shader
```c
uniform sampler2D tex;
uniform sampler2D externTex;
varying vec2 TextureCoordsVarying;
uniform float playTime;
const float PI = 3.1415926;
float rand(float n) {
return fract(sin(n) * 43758.5453123);
}
vec4 lookupTable(vec4 color, float progress){
//float blueColor = color.b * 63.0 * progress;
float blueColor = color.b * 63.0;
vec2 quad1;
quad1.y = floor(floor(blueColor) / 8.0);
quad1.x = floor(blueColor) - (quad1.y * 8.0);
vec2 quad2;
quad2.y = floor(ceil(blueColor) / 8.0);
quad2.x = ceil(blueColor) - (quad2.y * 8.0);
vec2 texPos1;
texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);
texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);
vec2 texPos2;
texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);
texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);
vec4 newColor1 = texture2D(externTex, texPos1);
vec4 newColor2 = texture2D(externTex, texPos2);
vec4 newColor = mix(newColor1, newColor2, fract(blueColor));
return vec4(newColor.rgb, color.w);
}
void main() {
float duration = 0.5;
float progress = mod(playTime, duration) / duration; // 0~1
vec4 imgColor = texture2D(tex, TextureCoordsVarying);
vec4 lutColor = lookupTable(imgColor, progress);
gl_FragColor = mix(imgColor, lutColor, 1.0);
}
```
## HelpGuide ##
#### FFmpegGuide ####
* If you don't know about how to compile ffmpeg, here u click in. When u did it, u can build with filter `plusglshader`.
* How to compile ffmpeg
* [Build filter `plusglshader`](#build)
## About ##
#### Contact
* Github:
* https://github.com/numberwolf/FFmpeg-Plus-OpenGL
* https://github.com/numberwolf/h265web.js
* Email(porschegt23@foxmail.com)
* QQ: 531365872
* QQ Group number: 925466059
* Discord:numberwolf#8694
* Wechat:numberwolf11