Skip to content

Commit 30d2961

Browse files
committed
Merge branch 'AkashiSN-vaapi'
2 parents 797a306 + acfb4ee commit 30d2961

File tree

8 files changed

+333
-119
lines changed

8 files changed

+333
-119
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ on:
99

1010
jobs:
1111
build-linux:
12-
name: native build in linux
12+
name: build in native linux
1313
runs-on: ubuntu-20.04
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717

18+
- name: install libva-dev
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y libva-dev
22+
1823
- name: build ffmpeg
1924
run: |
2025
while sleep 300; do echo "=====[ $SECONDS seconds still running ]====="; done &
@@ -31,7 +36,7 @@ jobs:
3136
./build-ffmpeg --cleanup
3237
3338
build-macos:
34-
name: native build in macos
39+
name: build in native macOS
3540
runs-on: macos-10.15
3641
steps:
3742
- name: Checkout code
@@ -74,8 +79,8 @@ jobs:
7479
run: |
7580
docker run --rm ffmpeg:ubuntu -buildconf
7681
77-
build-cuda-docker:
78-
name: build in docker with cuda
82+
build-cuda-ubuntu-docker:
83+
name: build in ubuntu docker with cuda
7984
runs-on: ubuntu-20.04
8085
steps:
8186
- name: Checkout code
@@ -85,36 +90,58 @@ jobs:
8590
id: cuda_ubuntu_pull
8691
run: |
8792
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
88-
docker pull nvidia/cuda:11.1-runtime-ubuntu20.04
93+
docker pull ubuntu:20.04
8994
- name: run if cuda_ubuntu_pull failed
9095
if: failure() && steps.cuda_ubuntu_pull.outcome == 'failure'
9196
run: |
9297
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
93-
docker pull nvidia/cuda:11.1-runtime-ubuntu20.04
98+
docker pull ubuntu:20.04
99+
- name: build ffmpeg
100+
run: |
101+
docker build -t ffmpeg:cuda-ubuntu -f cuda-ubuntu.dockerfile .
102+
- name: test run ffmepg
103+
run: |
104+
docker run --rm ffmpeg:cuda-ubuntu -buildconf
105+
106+
build-cuda-centos-docker:
107+
name: build in centos docker with cuda
108+
runs-on: ubuntu-20.04
109+
steps:
110+
- name: Checkout code
111+
uses: actions/checkout@v2
112+
113+
- name: pull base image
114+
id: cuda_centos_pull
115+
run: |
116+
docker pull nvidia/cuda:11.1-devel-centos8
117+
docker pull centos:8
118+
- name: run if cuda_centos_pull failed
119+
if: failure() && steps.cuda_centos_pull.outcome == 'failure'
120+
run: |
121+
docker pull nvidia/cuda:11.1-devel-centos8
122+
docker pull centos:8
94123
- name: build ffmpeg
95124
run: |
96-
docker build -t ffmpeg:cuda -f cuda-ubuntu.dockerfile .
125+
docker build -t ffmpeg:cuda-centos -f cuda-centos.dockerfile .
97126
- name: test run ffmepg
98127
run: |
99-
docker run --rm ffmpeg:cuda -buildconf
128+
docker run --rm ffmpeg:cuda-centos -buildconf
100129
101130
build-full-static:
102-
name: build full static linking in docker
131+
name: full static build in docker
103132
runs-on: ubuntu-20.04
104133
steps:
105134
- name: Checkout code
106135
uses: actions/checkout@v2
107136

108137
- name: pull base image
109-
id: cuda_ubuntu_centos_pull
138+
id: cuda_ubuntu_pull
110139
run: |
111140
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
112-
docker pull centos:8
113-
- name: run if cuda_ubuntu_centos_pull failed
114-
if: failure() && steps.cuda_ubuntu_centos_pull.outcome == 'failure'
141+
- name: run if cuda_ubuntu_pull failed
142+
if: failure() && steps.cuda_ubuntu_pull.outcome == 'failure'
115143
run: |
116144
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
117-
docker pull centos:8
118145
- name: build ffmpeg
119146
run: |
120147
docker build -t ffmpeg:cuda-static -f full-static.dockerfile .

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
FROM ubuntu:20.04 AS build
22

3+
ENV DEBIAN_FRONTEND noninteractive
4+
35
RUN apt-get update \
4-
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates libz-dev \
6+
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates libva-dev \
57
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
68
&& update-ca-certificates
79

@@ -12,6 +14,11 @@ RUN SKIPINSTALL=yes /app/build-ffmpeg --build
1214

1315
FROM ubuntu:20.04
1416

17+
# install va-driver
18+
RUN apt-get update \
19+
&& apt-get -y install libva-drm2 \
20+
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
21+
1522
COPY --from=build /app/workspace/bin/ffmpeg /usr/bin/ffmpeg
1623
COPY --from=build /app/workspace/bin/ffprobe /usr/bin/ffprobe
1724

README.md

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
build-ffmpeg
77
==========
88

9-
The FFmpeg build script provides an easy way to build a static FFmpeg on **OSX** and **Linux** with **non-free codecs** included.
9+
The FFmpeg build script provides an easy way to build a static FFmpeg on **macOS** and **Linux** with **non-free codecs** included.
1010

1111

1212
[![How-To build FFmpeg on MacOS](https://img.youtube.com/vi/Z9p3mM757cM/0.jpg)](https://www.youtube.com/watch?v=Z9p3mM757cM "How-To build FFmpeg on OSX")
@@ -32,6 +32,8 @@ because I don't have the resources and the time to maintain other systems.
3232
* `theora`: Free lossy video compression format
3333
* `opus`: Lossy audio coding format
3434
* `srt`: Secure Reliable Transport
35+
36+
### HardwareAccel
3537
* `nv-codec`: [NVIDIA's GPU accelerated video codecs](https://devblogs.nvidia.com/nvidia-ffmpeg-transcoding-guide/). Installation is triggered only if CUDA installation is detected, follow [these](#Cuda-installation) instructions for installation. Supported codecs in nvcodec:
3638
* Decoders
3739
* H264 `h264_cuvid`
@@ -46,67 +48,133 @@ because I don't have the resources and the time to maintain other systems.
4648
* Encoders
4749
* H264 `nvenc_h264`
4850
* H265 `nvenc_hevc`
51+
* `vaapi`: [Video Acceleration API](https://trac.ffmpeg.org/wiki/Hardware/VAAPI). Installation is triggered only if libva driver installation is detected, follow [these](#Vaapi-installation) instructions for installation. Supported codecs in vaapi:
52+
* Encoders
53+
* H264 `h264_vaapi`
54+
* H265 `hevc_vaapi`
55+
* Motion JPEG `mjpeg_vaapi`
56+
* MPEG2 video `mpeg2_vaapi`
57+
* VP8 `vp8_vaapi`
58+
* VP9 `vp9_vaapi`
59+
4960

5061
## Continuos Integration
5162
ffmpeg-build-script is rockstable. Every commit runs against Linux and MacOS with https://github.com/markus-perl/ffmpeg-build-script/actions just to make sure everything works as expected.
5263

53-
Requirements MacOS
54-
------------
64+
65+
## Requirements
66+
### MacOS
5567

5668
* XCode 10.x or greater
5769

58-
Requirements Linux
59-
------------
70+
### Linux
71+
6072
* Debian >= Buster, Ubuntu => Focal Fossa, other Distributions might work too
61-
* build-essentials installed:
73+
* build-essentials, curl is required installed
6274

63-
```
75+
```bash
6476
# Debian and Ubuntu
65-
$ sudo apt-get install build-essential curl g++
77+
$ sudo apt install build-essential curl
6678

6779
# Fedora
68-
$ sudo dnf install @development-tools
80+
$ sudo dnf install @development-tools curl
6981
```
7082

71-
Installation
72-
------------
83+
## Installation
7384

74-
### Quick install and run
85+
### Quick install and run (macOS, Linux)
7586

7687
Open your command line and run (needs curl to be installed):
7788

7889
```bash
7990
$ bash <(curl -s "https://raw.githubusercontent.com/markus-perl/ffmpeg-build-script/master/web-install.sh?v1")
8091
```
92+
8193
This command downloads the build script and automatically starts the build process.
8294

83-
### Run with Docker
95+
### Common installation (macOS, Linux)
8496

85-
#### Default - Without CUDA
8697
```bash
8798
$ git clone https://github.com/markus-perl/ffmpeg-build-script.git
8899
$ cd ffmpeg-build-script
100+
$ ./build-ffmpeg --help
101+
```
102+
103+
### Build in Docker (Linux)
104+
105+
The main advantage of using Docker is the ability to reliably build without polluting the host environment. And you don't even have to install the CUDA SDK on your host!
106+
107+
If you are running below kind of operating system and having Docker version 19.03 or higher, this is your best option.
108+
* Ubuntu >= 16.04 (16.04, 18.04, 20.04)
109+
* Centos >= 7 (7, 8)
110+
111+
1. Enable Docker BuildKit
112+
```bash
113+
$ export DOCKER_BUILDKIT=1
114+
```
115+
116+
2. Set the following DIST (`ubuntu` or `centos`) and VER (ubuntu: `16.04` , `18.04`, `20.04` or centos: `7`, `8`) environment variables in conjunction with your operating system.
117+
```bash
118+
$ export DIST=centos
119+
$ export VER=8
120+
```
121+
122+
3. Start the docker build as follows.
123+
```bash
124+
$ sudo -E docker build --tag=ffmpeg:cuda-$DIST -f cuda-$DIST.dockerfile --build-arg VER=$VER .
125+
```
126+
127+
4. Build an `export.dockerfile` that copies only what you need from the image you just built as follows. When running, move the library in the lib to a location where the linker can find it or set the `LD_LIBRARY_PATH`.
128+
Since we have matched the operating system and version, it should work well with dynamic links. If it doesn't work, edit the `export.dockerfile` and copy the necessary libraries and try again.
129+
130+
```bash
131+
$ sudo -E docker build --output type=local,dest=build -f export.dockerfile .
132+
$ ls build
133+
bin lib
134+
$ ls build/bin
135+
ffmpeg ffprobe
136+
$ ls build/lib
137+
libnppc.so.11 libnppicc.so.11 libnppidei.so.11 libnppig.so.11
138+
```
139+
140+
### Build in Docker (full static ver.) (Linux)
141+
If you're running an operating system other than the one above, a completely static build may work.
142+
It's easy to do, just run the following command.
143+
```bash
144+
$ sudo -E docker build --tag=ffmpeg:cuda-static --output type=local,dest=build -f full-static.dockerfile .
145+
```
146+
147+
### Run with Docker (macOS, Linux)
148+
You can also run the entire Docker if the above two fail.
149+
150+
#### Default - Without CUDA (macOS, Linux)
151+
If you don't use CUDA, it's simple and runs as follows.
152+
153+
```bash
89154
$ sudo docker build --tag=ffmpeg .
90-
$ docker run ffmpeg -i https://files.coconut.co.s3.amazonaws.com/test.mp4 -f webm -c:v libvpx -c:a libvorbis - > /tmp/test.mp4
155+
$ sudo docker run ffmpeg -i https://files.coconut.co.s3.amazonaws.com/test.mp4 -f webm -c:v libvpx -c:a libvorbis - > test.mp4
91156
```
92157

93-
#### With CUDA
158+
#### With CUDA (Linux)
159+
If you use CUDA, Docker must be higher than 19.03.
160+
Install the driver and `nvidia-docker2` from [here](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-docker-ce).
161+
You can perform hardware acceleration by GPU by running the following.
94162
```bash
95-
$ git clone https://github.com/markus-perl/ffmpeg-build-script.git
96-
$ cd ffmpeg-build-script
97-
$ sudo docker build --tag=ffmpeg-cuda -f cuda-ubuntu.dockerfile .
98-
$ sudo docker run --gpus all ffmpeg-cuda -hwaccel cuvid -c:v h264_cuvid -i https://files.coconut.co.s3.amazonaws.com/test.mp4 -c:v hevc_nvenc -vf scale_npp=-1:1080 - > /tmp/test.mp4
163+
$ sudo docker build --tag=ffmpeg:cuda -f cuda-ubuntu.dockerfile .
164+
$ sudo docker run --gpus all ffmpeg-cuda -hwaccel cuvid -c:v h264_cuvid -i https://files.coconut.co.s3.amazonaws.com/test.mp4 -c:v hevc_nvenc -vf scale_npp=-1:1080 - > test.mp4
99165
```
100166

101-
### Common installation
167+
### Common build (macOS, Linux)
168+
169+
If you want to enable CUDA, please refer to [these](#Cuda-installation) and install the SDK.
170+
171+
If you want to enable Vaapi, please refer to [these](#Vaapi-installation) and install the driver.
102172

103173
```bash
104-
$ git clone https://github.com/markus-perl/ffmpeg-build-script.git
105-
$ cd ffmpeg-build-script
106-
$ ./build-ffmpeg --help
174+
$ ./build-ffmpeg --build
107175
```
108176

109-
### Cuda installation
177+
## Cuda installation
110178

111179
CUDA is a parallel computing platform developed by NVIDIA.
112180
To be able to compile ffmpeg with CUDA support, you first need a compatible NVIDIA GPU.
@@ -116,8 +184,19 @@ To be able to compile ffmpeg with CUDA support, you first need a compatible NVID
116184
or [this blog](https://www.pugetsystems.com/labs/hpc/How-To-Install-CUDA-10-1-on-Ubuntu-19-04-1405/)
117185
to setup the CUDA toolkit.
118186

119-
Usage
120-
------
187+
## Vaapi installation
188+
189+
You will need the libva driver, so please install it below.
190+
191+
```bash
192+
# Debian and Ubuntu
193+
$ sudo apt install libva-dev vainfo
194+
195+
# Fedora and CentOS
196+
$ sudo dnf install libva-devel libva-intel-driver libva-utils
197+
```
198+
199+
## Usage
121200

122201
```bash
123202
Usage: build-ffmpeg [OPTIONS]
@@ -126,7 +205,7 @@ Options:
126205
--version Display version information
127206
-b, --build Starts the build process
128207
-c, --cleanup Remove all working dirs
129-
-f, --full-static Complete static build of ffmpeg (eg. glibc, pthreads etc...) **not recommend**
208+
-f, --full-static Complete static build of ffmpeg (eg. glibc, pthreads etc...) **only Linux**
130209
Note: Because of the NSS (Name Service Switch), glibc does not recommend static links.
131210
```
132211

@@ -135,6 +214,7 @@ Options:
135214
See detail below: https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked_programs_need_some_shared_libraries_which_is_not_acceptable_for_me.__What_can_I_do.3F
136215

137216
- The libnpp in the CUDA SDK cannot be statically linked.
217+
- Vaapi cannot be statically linked.
138218

139219
Contact
140220
-------

0 commit comments

Comments
 (0)