Skip to content

Commit f2c416c

Browse files
committed
update dockerfile, readme
1 parent 7cffe42 commit f2c416c

File tree

5 files changed

+122
-31
lines changed

5 files changed

+122
-31
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ jobs:
8585
id: cuda_ubuntu_pull
8686
run: |
8787
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
88-
docker pull nvidia/cuda:11.1-runtime-ubuntu20.04
89-
- name: run if cuda_ubuntu_pull failed
88+
docker pull ubuntu:20.04
89+
- name: run if cuda_ubuntu_pull failed
9090
if: failure() && steps.cuda_ubuntu_pull.outcome == 'failure'
9191
run: |
9292
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
93-
docker pull nvidia/cuda:11.1-runtime-ubuntu20.04
94-
- name: build ffmpeg
93+
docker pull ubuntu:20.04
94+
- name: build ffmpeg
9595
run: |
96-
docker build -t ffmpeg:cuda -f cuda-ubuntu.dockerfile .
96+
docker build -t ffmpeg:cuda -f cuda.dockerfile .
9797
- name: test run ffmepg
9898
run: |
9999
docker run --rm ffmpeg:cuda -buildconf

README.md

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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,30 +48,43 @@ 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+
* `amf`: [Advanced Media Framework SDK](https://gpuopen.com/advanced-media-framework/). Optimal access to AMD GPUs for multimedia processing. Supported codecs in amf:
52+
* Encoders
53+
* H264 `h264_amf`
54+
* H265 `hevc_amf`
55+
* `vaapi`: [Video Acceleration API](https://trac.ffmpeg.org/wiki/Hardware/VAAPI). Supported codecs in vaapi:
56+
* Encoders
57+
* H264 `h264_vaapi`
58+
* H265 `hevc_vaapi`
59+
* Motion JPEG `mjpeg_vaapi`
60+
* MPEG2 video `mpeg2_vaapi`
61+
* VP8 `vp8_vaapi`
62+
* VP9 `vp9_vaapi`
63+
4964

5065
## Continuos Integration
5166
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.
5267

53-
Requirements MacOS
54-
------------
68+
69+
## Requirements
70+
### MacOS
5571

5672
* XCode 10.x or greater
5773

58-
Requirements Linux
59-
------------
74+
### Linux
75+
6076
* Debian >= Buster, Ubuntu => Focal Fossa, other Distributions might work too
61-
* build-essentials, curl, and Python3 is required installed:
77+
* build-essentials, curl, and Python3 is required installed
6278

63-
```
79+
```bash
6480
# Debian and Ubuntu
6581
$ sudo apt-get install build-essential curl python3
6682

6783
# Fedora
6884
$ sudo dnf install @development-tools curl python3
6985
```
7086

71-
Installation
72-
------------
87+
## Installation
7388

7489
### Quick install and run
7590

@@ -78,35 +93,90 @@ Open your command line and run (needs curl to be installed):
7893
```bash
7994
$ bash <(curl -s "https://raw.githubusercontent.com/markus-perl/ffmpeg-build-script/master/web-install.sh?v1")
8095
```
96+
8197
This command downloads the build script and automatically starts the build process.
8298

83-
### Run with Docker
99+
### Common installation
84100

85-
#### Default - Without CUDA
86101
```bash
87102
$ git clone https://github.com/markus-perl/ffmpeg-build-script.git
88103
$ cd ffmpeg-build-script
104+
$ ./build-ffmpeg --help
105+
```
106+
107+
### Build in Docker
108+
109+
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!
110+
111+
If you are running below kind of operating system and having Docker version 19.03 or higher, this is your best option.
112+
* Ubuntu >= 16.04 (16.04, 18.04, 20.04)
113+
* Centos >= 7 (7, 8)
114+
115+
1. Enable Docker BuildKit
116+
```bash
117+
$ export DOCKER_BUILDKIT=1
118+
```
119+
120+
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.
121+
```bash
122+
$ export DIST=centos
123+
$ export VER=8
124+
```
125+
126+
3. Start the docker build as follows.
127+
```bash
128+
$ sudo -E docker build --tag=ffmpeg:cuda -f cuda.dockerfile --build-arg DIST=$DIST VER=$VER .
129+
```
130+
131+
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`.
132+
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.
133+
134+
```bash
135+
$ sudo -E docker build --output type=local,dest=build -f export.dockerfile .
136+
$ ls build
137+
bin lib
138+
$ ls build/bin
139+
ffmpeg ffprobe
140+
$ ls build/lib
141+
libnppc.so.11 libnppicc.so.11 libnppidei.so.11 libnppig.so.11
142+
```
143+
144+
### Build in Docker (full static ver.)
145+
If you're running an operating system other than the one above, a completely static build may work.
146+
It's easy to do, just run the following command.
147+
```bash
148+
$ sudo -E docker build --tag=ffmpeg:cuda-static --output type=local,dest=build -f full-static.dockerfile .
149+
```
150+
151+
### Run with Docker
152+
You can also run the entire Docker if the above two fail.
153+
154+
#### Default - Without CUDA
155+
If you don't use CUDA, it's simple and runs as follows.
156+
157+
```bash
89158
$ 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
159+
$ sudo docker run ffmpeg -i https://files.coconut.co.s3.amazonaws.com/test.mp4 -f webm -c:v libvpx -c:a libvorbis - > test.mp4
91160
```
92161

93162
#### With CUDA
163+
If you use CUDA, Docker must be higher than 19.03.
164+
Install the driver and `nvidia-docker2` from [here](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-docker-ce).
165+
You can perform hardware acceleration by GPU by running the following.
94166
```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
167+
$ sudo docker build --tag=ffmpeg:cuda -f cuda-ubuntu.dockerfile .
168+
$ 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
99169
```
100170

101-
### Common installation
171+
### Common build
172+
173+
If you want to enable CUDA, please refer to [these](#Cuda-installation) and install the SDK.
102174

103175
```bash
104-
$ git clone https://github.com/markus-perl/ffmpeg-build-script.git
105-
$ cd ffmpeg-build-script
106-
$ ./build-ffmpeg --help
176+
$ ./build-ffmpeg --build
107177
```
108178

109-
### Cuda installation
179+
## Cuda installation
110180

111181
CUDA is a parallel computing platform developed by NVIDIA.
112182
To be able to compile ffmpeg with CUDA support, you first need a compatible NVIDIA GPU.

cuda-ubuntu.dockerfile renamed to cuda.dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM nvidia/cuda:11.1-devel-ubuntu20.04 AS build
1+
ARG DIST=ubuntu
2+
ARG VER=20.04
3+
4+
FROM nvidia/cuda:11.1-devel-${DIST}${VER} AS build
25

36
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
47

@@ -12,10 +15,16 @@ COPY ./build-ffmpeg /app/build-ffmpeg
1215

1316
RUN SKIPINSTALL=yes /app/build-ffmpeg --build
1417

15-
FROM nvidia/cuda:11.1-runtime-ubuntu20.04
1618

17-
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
19+
FROM ${DIST}:${VER}
20+
21+
# Copy libnpp
22+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppc.so.11 /lib/x86_64-linux-gnu/libnppc.so.11
23+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppig.so.11 /lib/x86_64-linux-gnu/libnppig.so.11
24+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppicc.so.11 /lib/x86_64-linux-gnu/libnppicc.so.11
25+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppidei.so.11 /lib/x86_64-linux-gnu/libnppidei.so.11
1826

27+
# Copy ffmpeg
1928
COPY --from=build /app/workspace/bin/ffmpeg /usr/bin/ffmpeg
2029
COPY --from=build /app/workspace/bin/ffprobe /usr/bin/ffprobe
2130

export.dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM scratch
2+
3+
# Copy libnpp
4+
COPY --from=ffmpeg:cuda /lib/x86_64-linux-gnu/libnppc.so.11 /lib/libnppc.so.11
5+
COPY --from=ffmpeg:cuda /lib/x86_64-linux-gnu/libnppig.so.11 /lib/libnppig.so.11
6+
COPY --from=ffmpeg:cuda /lib/x86_64-linux-gnu/libnppicc.so.11 /lib/libnppicc.so.11
7+
COPY --from=ffmpeg:cuda /lib/x86_64-linux-gnu/libnppidei.so.11 /lib/libnppidei.so.11
8+
9+
# Copy ffmpeg
10+
COPY --from=ffmpeg:cuda /usr/bin/ffmpeg /bin/ffmpeg
11+
COPY --from=ffmpeg:cuda /usr/bin/ffprobe /bin/ffprobe

full-static.dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ WORKDIR /app
1111
COPY ./build-ffmpeg /app/build-ffmpeg
1212

1313
RUN AUTOINSTALL=yes /app/build-ffmpeg --build --full-static
14+
1415
RUN ldd /app/workspace/bin/ffmpeg ; exit 0
1516
RUN ldd /app/workspace/bin/ffprobe ; exit 0
1617

1718
FROM scratch
1819

19-
COPY --from=build /app/workspace/bin/ffmpeg /usr/bin/ffmpeg
20-
COPY --from=build /app/workspace/bin/ffprobe /usr/bin/ffprobe
20+
COPY --from=build /app/workspace/bin/ffmpeg /ffmpeg
21+
COPY --from=build /app/workspace/bin/ffprobe /ffprobe
2122

2223
CMD ["--help"]
23-
ENTRYPOINT ["/usr/bin/ffmpeg"]
24+
ENTRYPOINT ["/ffmpeg"]

0 commit comments

Comments
 (0)