Skip to content

Commit ca9cb1f

Browse files
committed
update vaapi
1 parent df7d688 commit ca9cb1f

File tree

6 files changed

+150
-48
lines changed

6 files changed

+150
-48
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ jobs:
7474
run: |
7575
docker run --rm ffmpeg:ubuntu -buildconf
7676
77-
build-cuda-docker:
78-
name: build in docker with cuda
77+
build-cuda-ubuntu-docker:
78+
name: build in ubuntu docker with cuda
7979
runs-on: ubuntu-20.04
8080
steps:
8181
- name: Checkout code
@@ -93,10 +93,34 @@ jobs:
9393
docker pull ubuntu:20.04
9494
- name: build ffmpeg
9595
run: |
96-
docker build -t ffmpeg:cuda -f cuda.dockerfile .
96+
docker build -t ffmpeg:cuda-ubuntu -f cuda-ubuntu.dockerfile .
9797
- name: test run ffmepg
9898
run: |
99-
docker run --rm ffmpeg:cuda -buildconf
99+
docker run --rm ffmpeg:cuda-ubuntu -buildconf
100+
101+
build-cuda-centos-docker:
102+
name: build in centos docker with cuda
103+
runs-on: ubuntu-20.04
104+
steps:
105+
- name: Checkout code
106+
uses: actions/checkout@v2
107+
108+
- name: pull base image
109+
id: cuda_centos_pull
110+
run: |
111+
docker pull nvidia/cuda:11.1-devel-centos8
112+
docker pull centos:8
113+
- name: run if cuda_centos_pull failed
114+
if: failure() && steps.cuda_centos_pull.outcome == 'failure'
115+
run: |
116+
docker pull nvidia/cuda:11.1-devel-centos8
117+
docker pull centos:8
118+
- name: build ffmpeg
119+
run: |
120+
docker build -t ffmpeg:cuda-centos -f cuda-centos.dockerfile .
121+
- name: test run ffmepg
122+
run: |
123+
docker run --rm ffmpeg:cuda-centos -buildconf
100124
101125
build-full-static:
102126
name: full static build in docker
@@ -106,11 +130,11 @@ jobs:
106130
uses: actions/checkout@v2
107131

108132
- name: pull base image
109-
id: cuda_ubuntu_centos_pull
133+
id: cuda_ubuntu_pull
110134
run: |
111135
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
112-
- name: run if cuda_ubuntu_centos_pull failed
113-
if: failure() && steps.cuda_ubuntu_centos_pull.outcome == 'failure'
136+
- name: run if cuda_ubuntu_pull failed
137+
if: failure() && steps.cuda_ubuntu_pull.outcome == 'failure'
114138
run: |
115139
docker pull nvidia/cuda:11.1-devel-ubuntu20.04
116140
- name: build ffmpeg

Dockerfile

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

33
RUN apt-get update \
4-
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python3 \
4+
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python3 i965-va-driver \
55
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
66
&& update-ca-certificates
77

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

1313
FROM ubuntu:20.04
1414

15+
# install va-driver
16+
RUN apt-get update \
17+
&& apt-get -y --no-install-recommends install libva-drm2 \
18+
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
19+
1520
COPY --from=build /app/workspace/bin/ffmpeg /usr/bin/ffmpeg
1621
COPY --from=build /app/workspace/bin/ffprobe /usr/bin/ffprobe
1722

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ because I don't have the resources and the time to maintain other systems.
5252
* Encoders
5353
* H264 `h264_amf`
5454
* H265 `hevc_amf`
55-
* `vaapi`: [Video Acceleration API](https://trac.ffmpeg.org/wiki/Hardware/VAAPI). Supported codecs in vaapi:
55+
* `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:
5656
* Encoders
5757
* H264 `h264_vaapi`
5858
* H265 `hevc_vaapi`
@@ -78,7 +78,7 @@ ffmpeg-build-script is rockstable. Every commit runs against Linux and MacOS wit
7878

7979
```bash
8080
# Debian and Ubuntu
81-
$ sudo apt-get install build-essential curl python3
81+
$ sudo apt install build-essential curl python3
8282

8383
# Fedora
8484
$ sudo dnf install @development-tools curl python3
@@ -125,7 +125,7 @@ $ export VER=8
125125

126126
3. Start the docker build as follows.
127127
```bash
128-
$ sudo -E docker build --tag=ffmpeg:cuda -f cuda.dockerfile --build-arg DIST=$DIST --build-arg VER=$VER .
128+
$ sudo -E docker build --tag=ffmpeg:cuda-$DIST -f cuda-$DIST.dockerfile --build-arg VER=$VER .
129129
```
130130

131131
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`.
@@ -186,8 +186,19 @@ To be able to compile ffmpeg with CUDA support, you first need a compatible NVID
186186
or [this blog](https://www.pugetsystems.com/labs/hpc/How-To-Install-CUDA-10-1-on-Ubuntu-19-04-1405/)
187187
to setup the CUDA toolkit.
188188

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

192203
```bash
193204
Usage: build-ffmpeg [OPTIONS]
@@ -205,6 +216,7 @@ Options:
205216
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
206217

207218
- The libnpp in the CUDA SDK cannot be statically linked.
219+
- Vaapi cannot be statically linked.
208220

209221
Contact
210222
-------

build-ffmpeg

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,25 @@ build () {
123123
return 0
124124
}
125125

126-
command_exists() {
126+
command_exists () {
127127
if ! [[ -x $(command -v "$1") ]]; then
128128
return 1
129129
fi
130130

131131
return 0
132132
}
133133

134+
library_exists () {
135+
if ! command_exists "ldconfig"; then
136+
return 1
137+
fi
138+
139+
if ! [ -n "$(ldconfig -p | grep "$1")" ]; then
140+
return 1
141+
fi
142+
143+
return 0
144+
}
134145

135146
build_done () {
136147
touch "$PACKAGES/$1.done"
@@ -550,7 +561,7 @@ CONFIGURE_OPTIONS+=("--enable-libsrt")
550561
##
551562

552563
if [[ "$OSTYPE" == "linux-gnu" ]]; then
553-
if command_exists nvcc ; then
564+
if command_exists "nvcc" ; then
554565
if build "nv-codec"; then
555566
download "https://github.com/FFmpeg/nv-codec-headers/releases/download/n11.0.10.0/nv-codec-headers-11.0.10.0.tar.gz"
556567
execute make PREFIX="${WORKSPACE}"
@@ -577,39 +588,46 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
577588
fi
578589
CONFIGURE_OPTIONS+=("--enable-amf")
579590

580-
if build "libpciaccess"; then
581-
download "https://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/archive/libpciaccess-0.16/libpciaccess-libpciaccess-0.16.tar.bz2" "libpciaccess-0.16.tar.bz2"
582-
execute autoreconf --force --verbose --install
583-
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static CFLAGS=-fPIC
584-
execute make -j $MJOBS
585-
execute make install
586-
build_done "libpciaccess"
587-
fi
591+
# Vaapi doesn't work well with static links ffmpeg.
592+
if [ -z "$LDEXEFLAGS" ]; then
593+
if library_exists "libdrm" ; then
594+
if build "libpciaccess"; then
595+
download "https://gitlab.freedesktop.org/xorg/lib/libpciaccess/-/archive/libpciaccess-0.16/libpciaccess-libpciaccess-0.16.tar.bz2" "libpciaccess-0.16.tar.bz2"
596+
execute autoreconf --force --verbose --install
597+
execute ./configure --prefix="${WORKSPACE}" --disable-static --enable-shared CFLAGS=-fPIC
598+
execute make -j $MJOBS
599+
execute make install
600+
build_done "libpciaccess"
601+
fi
588602

589-
if build "libdrm"; then
590-
download "https://gitlab.freedesktop.org/mesa/drm/-/archive/libdrm-2.4.102/drm-libdrm-2.4.102.tar.bz2" "libdrm-2.4.102.tar.bz2"
591-
execute meson --prefix="${WORKSPACE}" --libdir="${WORKSPACE}"/lib builddir/
592-
execute ninja -C builddir/ install
593-
build_done "libdrm"
594-
fi
603+
# https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/28
604+
# Since libdrm should not be statically linked, neither should libva or intel-vaapi-driver, on which it depends, be statically linked.
605+
# They should be installed as drivers in your host OS.
606+
if build "libdrm"; then
607+
download "https://gitlab.freedesktop.org/mesa/drm/-/archive/libdrm-2.4.102/drm-libdrm-2.4.102.tar.bz2" "libdrm-2.4.102.tar.bz2"
608+
execute meson --prefix="${WORKSPACE}" --libdir="${WORKSPACE}"/lib builddir/
609+
execute ninja -C builddir/ install
610+
build_done "libdrm"
611+
fi
595612

596-
if build "libva"; then
597-
download "https://github.com/intel/libva/releases/download/2.9.0/libva-2.9.0.tar.bz2"
598-
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
599-
execute make -j $MJOBS
600-
execute make install
601-
build_done "libva"
602-
fi
613+
if build "libva"; then
614+
download "https://github.com/intel/libva/releases/download/2.9.0/libva-2.9.0.tar.bz2"
615+
execute ./configure --prefix="${WORKSPACE}" --disable-static --enable-shared
616+
execute make -j $MJOBS
617+
execute make install
618+
build_done "libva"
619+
fi
603620

604-
if build "intel-vaapi-driver"; then
605-
download "https://github.com/intel/intel-vaapi-driver/releases/download/2.4.1/intel-vaapi-driver-2.4.1.tar.bz2"
606-
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
607-
execute make -j $MJOBS
608-
execute make install
609-
build_done "intel-vaapi-driver"
621+
if build "intel-vaapi-driver"; then
622+
download "https://github.com/intel/intel-vaapi-driver/releases/download/2.4.1/intel-vaapi-driver-2.4.1.tar.bz2"
623+
execute ./configure --prefix="${WORKSPACE}" --disable-static --enable-shared
624+
execute make -j $MJOBS
625+
execute make install
626+
build_done "intel-vaapi-driver"
627+
fi
628+
CONFIGURE_OPTIONS+=("--enable-vaapi")
629+
fi
610630
fi
611-
612-
CONFIGURE_OPTIONS+=("--enable-vaapi")
613631
fi
614632

615633

cuda-centos.dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG VER=8
2+
3+
FROM nvidia/cuda:11.1-devel-centos${VER} AS build
4+
5+
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
6+
7+
RUN yum groupinstall -y "Development Tools" \
8+
&& yum install -y kernel-devel kernel-headers curl python3 vaapi-driver-i965 \
9+
&& rm -rf /var/cache/yum/* \
10+
&& yum clean all
11+
12+
WORKDIR /app
13+
COPY ./build-ffmpeg /app/build-ffmpeg
14+
15+
RUN SKIPINSTALL=yes /app/build-ffmpeg --build
16+
17+
18+
FROM centos:${VER}
19+
20+
# install va-driver
21+
RUN yum install -y libva \
22+
&& rm -rf /var/cache/yum/* \
23+
&& yum clean all
24+
25+
# Copy libnpp
26+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppc.so.11 /lib/x86_64-linux-gnu/libnppc.so.11
27+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppig.so.11 /lib/x86_64-linux-gnu/libnppig.so.11
28+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppicc.so.11 /lib/x86_64-linux-gnu/libnppicc.so.11
29+
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppidei.so.11 /lib/x86_64-linux-gnu/libnppidei.so.11
30+
31+
# Copy ffmpeg
32+
COPY --from=build /app/workspace/bin/ffmpeg /usr/bin/ffmpeg
33+
COPY --from=build /app/workspace/bin/ffprobe /usr/bin/ffprobe
34+
35+
RUN ldd /usr/bin/ffmpeg ; exit 0
36+
RUN ldd /usr/bin/ffprobe ; exit 0
37+
38+
CMD ["--help"]
39+
ENTRYPOINT ["/usr/bin/ffmpeg"]

cuda.dockerfile renamed to cuda-ubuntu.dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
ARG DIST=ubuntu
21
ARG VER=20.04
32

4-
FROM nvidia/cuda:11.1-devel-${DIST}${VER} AS build
3+
FROM nvidia/cuda:11.1-devel-ubuntu${VER} AS build
54

65
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
76

87
RUN apt-get update \
9-
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python3 \
8+
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python3 i965-va-driver \
109
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
1110
&& update-ca-certificates
1211

@@ -16,7 +15,12 @@ COPY ./build-ffmpeg /app/build-ffmpeg
1615
RUN SKIPINSTALL=yes /app/build-ffmpeg --build
1716

1817

19-
FROM ${DIST}:${VER}
18+
FROM ubuntu:${VER}
19+
20+
# install va-driver
21+
RUN apt-get update \
22+
&& apt-get -y --no-install-recommends install libva-drm2 \
23+
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
2024

2125
# Copy libnpp
2226
COPY --from=build /usr/local/cuda-11.1/targets/x86_64-linux/lib/libnppc.so.11 /lib/x86_64-linux-gnu/libnppc.so.11

0 commit comments

Comments
 (0)