Skip to content

FFmpeg nVidia Codec Build Support #253

@WesToleman

Description

@WesToleman

Building mpv with nVidia codec support (for --hwdec=nvdec) requires the FFmpeg NV codec headers which aren't included in the current project. I managed to build mpv with nVidia support by adding scripts to download the headers like the other dependencies.

I added the repo to do_clone_all, adapted copies of the ffmpeg scripts and added the new references to the build scripts. Is this the right approach? I haven't contributed to the mpv-build codebase before so I wanted to confirm that was the way to go before I submit a pull request.

Is this patch missing anything obvious?

diff --git a/.gitignore b/.gitignore
index 51cdca1..8d8e3f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 /ffmpeg
+/ffnvcodec
 /fribidi
 /libass
 /libplacebo
diff --git a/build b/build
index 830abf7..175523b 100755
--- a/build
+++ b/build
@@ -8,6 +8,8 @@ scripts/libplacebo-config
 scripts/libplacebo-build "$@"
 scripts/libass-config
 scripts/libass-build "$@"
+scripts/ffnvcodec-config
+scripts/ffnvcodec-build "$@"
 scripts/ffmpeg-config
 scripts/ffmpeg-build "$@"
 scripts/mpv-config
diff --git a/debian/rules b/debian/rules
index 0f845eb..775a4e8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -58,6 +58,12 @@ ffmpeg_config: libass_build libplacebo_build
 ffmpeg_build: ffmpeg_config
 	scripts/ffmpeg-build $(MFLAGS)
 
+ffnvcodec_config:
+	scripts/ffnvcodec-config
+
+ffnvcodec_build: ffnvcodec_config
+	scripts/ffnvcodec-build $(MFLAGS)
+
 libplacebo_config:
 	scripts/libplacebo-config
 
@@ -65,7 +71,7 @@ libplacebo_build: libplacebo_config
 	scripts/libplacebo-build $(NINJAFLAGS)
 
 # drop the local/ since it's package managed now
-override_dh_auto_configure: ffmpeg_build libass_build libplacebo_build
+override_dh_auto_configure: ffnvcodec_build ffmpeg_build libass_build libplacebo_build
 	scripts/mpv-config --prefix=/usr \
 		-Dopenal=enabled \
 		-Ddvbin=enabled \
diff --git a/scripts/ffnvcodec-build b/scripts/ffnvcodec-build
new file mode 100755
index 0000000..3e46d75
--- /dev/null
+++ b/scripts/ffnvcodec-build
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -e
+
+make -C ffnvcodec install "$@"
diff --git a/scripts/ffnvcodec-clean b/scripts/ffnvcodec-clean
new file mode 100755
index 0000000..c5a3b5c
--- /dev/null
+++ b/scripts/ffnvcodec-clean
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+rm -rf ffnvcodec_build
diff --git a/scripts/ffnvcodec-config b/scripts/ffnvcodec-config
new file mode 100755
index 0000000..031f166
--- /dev/null
+++ b/scripts/ffnvcodec-config
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+
+BUILD="$(pwd)"
+newline="
+"
+
+if test -f "$BUILD"/ffnvcodec_options ; then
+    IFS=$newline
+    set -- $(cat "$BUILD"/ffnvcodec_options) "$@"
+    unset -v IFS
+fi
+
+case "$PKG_CONFIG_PATH" in
+  '')
+    export PKG_CONFIG_PATH="$BUILD/build_libs/lib/pkgconfig"
+    ;;
+  *)
+    export PKG_CONFIG_PATH="$BUILD/build_libs/lib/pkgconfig:$PKG_CONFIG_PATH"
+    ;;
+esac
+
+echo Using ffnvcodec options: $OPTIONS "$@"
+
+make -C "$BUILD"/ffnvcodec PREFIX="$BUILD"/build_libs $OPTIONS "$@"
diff --git a/update b/update
index 7edc609..e2ca766 100755
--- a/update
+++ b/update
@@ -18,6 +18,7 @@ do_clone()
 do_clone_all()
 {
     do_clone "ffmpeg"     "https://github.com/FFmpeg/FFmpeg.git"
+    do_clone "ffnvcodec"  "https://github.com/FFmpeg/nv-codec-headers.git"
     #do_clone "fribidi"    "http://anongit.freedesktop.org/git/fribidi/fribidi.git"
     do_clone "libass"     "https://github.com/libass/libass.git"
     do_clone "libplacebo" "https://github.com/haasn/libplacebo.git"
@@ -48,7 +49,7 @@ do_releasetag()
 {
     local prefix=  # by default, don't use a prefix
     case "$1" in
-        ffmpeg) prefix=n;;  # e.g. n3.3.1
+        ffmpeg|ffnvcodec) prefix=n;;  # e.g. n3.3.1
         mpv|libplacebo)    prefix=v;;  # e.g. v0.26.0
     esac
 
@@ -86,6 +87,7 @@ checkout()
 
 # fallback targets: release/master/@foo if no config file
 checkout_ffmpeg=master
+checkout_ffnvcodec=master
 #checkout_fribidi=release
 checkout_libass=master
 checkout_libplacebo=master
@@ -97,6 +99,7 @@ checkout_all()
     set -ex
     do_clone_all
     checkout ffmpeg $checkout_ffmpeg
+    checkout ffnvcodec $checkout_ffnvcodec
     #$checkout fribidi $checkout_fribidi
     checkout libass $checkout_libass
     checkout libplacebo $checkout_libplacebo
@@ -121,6 +124,7 @@ shift
 case "$1" in
     --master)
         checkout_ffmpeg="master -"
+        checkout_ffnvcodec="master -"
         #checkout_fribidi="master -"
         checkout_libass="master -"
         checkout_libplacebo="master -"
diff --git a/use-ffnvcodec-custom b/use-ffnvcodec-custom
new file mode 100755
index 0000000..108d23e
--- /dev/null
+++ b/use-ffnvcodec-custom
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+export LC_ALL=C
+
+if [ -z "$1" ]; then
+    echo "Aborting. Please provide a commit hash or a tag/branch name."
+    exit 1
+fi
+
+scripts/switch-branch ffnvcodec "@$1"
diff --git a/use-ffnvcodec-master b/use-ffnvcodec-master
new file mode 100755
index 0000000..aee7be6
--- /dev/null
+++ b/use-ffnvcodec-master
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+export LC_ALL=C
+
+scripts/switch-branch ffnvcodec master
diff --git a/use-ffnvcodec-release b/use-ffnvcodec-release
new file mode 100755
index 0000000..942036f
--- /dev/null
+++ b/use-ffnvcodec-release
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+export LC_ALL=C
+
+scripts/switch-branch ffnvcodec release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions