compiling ffmpeg with nvec support fails to apply patch

Hi

Following the ‘FFMPEG with nvidia acceleration on ubuntu linux’ guide with the url:
http://developer.download.nvidia.com/compute/redist/ffmpeg/1511-patch/FFMPEG-with-NVIDIA-Acceleration-on-Ubuntu_UG_v01.pdf

When trying to apply patch “git apply -v …/ffmpeg_NVIDIA_gpu_acceleration.patch” it’s failing now… looks like new versions of ffmpeg include netcdf support that doesn’t match with the patch file.

You can see the diff with the -v flag in the git apply command… is it possible to get a new version of the patch file that take this issue?

Best Regards

Patricio Vidal

Hello,

I second this, have spent last couple days trying to get this patch applied…

have tried different driver versions, different cuda kits, etc, even tried different ffmpeg builds and same result…

Hi…

maybe this its gonna be on another post…but finally I could do it (build the ffmpeg with nvenc and nvresize)

First of all… the patch its applied despite the git messages (you could use patch -p1 < [patch File] instead).

The main problem it’s when you try to build the ffmpeg, it exit with errors trying to complile vf_nvresize.c with the message that closed it’s no member of avfilter

If this it’s the case you have to make some changes in the file avfilter.h inside the libavfilter folder, mostly you have to re enable this attribute (the last versions have this attributed disabled or deprecated)

first of all inside de AVFilterLink struct you have to declare the attribute (int closed;) like this

struct AVFilterLink {
AVFilterContext *src; ///< source filter
AVFilterPad *srcpad; ///< output pad on the source filter

AVFilterContext *dst;       ///< dest filter
AVFilterPad *dstpad;        ///< input pad on the dest filter

enum AVMediaType type;      ///< filter media type

/* These parameters apply only to video */
int w;                      ///< agreed upon image width
int h;                      ///< agreed upon image height
AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
/* These parameters apply only to audio */
uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
int sample_rate;            ///< samples per second

int format;                 ///< agreed upon media format

int closed;

and after you have to comment a line like this (attribute deprecated…after in the file)

/**

  • Set the closed field of a link.
  • @deprecated applications are not supposed to mess with links, they should
  • close the sinks.
    /
    /
    attribute_deprecated*/
    void avfilter_link_set_closed(AVFilterLink *link, int closed);

And now I can compile and it’s working perfectly (with nvenc and nvresize)

Thanks Patricio_Vidal ! ! !

after following your advice i too was able to compile ffmpeg with nvenc and nvresize

after appling patch using “patch p1 <”

and made corrections to avfilter.h

all is good now… :)

Patricio_Vidal, you probably saved my sanity. Thank you!

i have a lot of errors like undefined reference, i am using the nvenc sdk 6. what are used for you ?

Hi…

Sorry for the delay… but I had to compile again now with Ubuntu 16.04 LTS, using sdk 6.0 (new one) and everything works ok but you have to consider the following

When you apply the patch using patch -p1 <… now you have errors in the patching process in the configure, libavcodec/Makefile and libavcodec/nvenc.c files
The patching process generating .rej files for those ones and you have to check it and apply the patches manually, if you have problems or don’t know how to do it… let me know and i can send the files corrected to you… it’s not hard to apply manually the patches, only understand what .rej file means.

Be aware in the config.rej, you also have to add nvenc in confile…

— configure
+++ configure
@@ -276,6 +276,7 @@ External library support:
–enable-decklink enable Blackmagick DeckLink I/O support [no]
–enable-mmal enable decoding via MMAL [no]
–enable-nvenc enable NVIDIA NVENC support [no]

  • –enable-nvresize enable NVIDIA CUDA accelerated resizer [no]
    –enable-openal enable OpenAL 1.1 capture support [no]
    –enable-opencl enable OpenCL code
    –enable-opengl enable OpenGL rendering [no]

This rej file means that you have to add the line enable-nvresize in somwhere near the line 276 inside external line support (in the configure file). But if you checked the configure file you also have to add the enable-nvenc line because it didnt appear and thats the reason the automatic patch fail.

If you see an “-” in the start of the line means that you have to delete that line

And after making those changes you can compile again…and it’s works

Patricio_Vidal , Hello. Can you please send corrected files. I was struggling with that manual patching on Ubuntu 16.04 with 6.0.1 sdk and just gave up.

Hello,

May I also get patch for Ubuntu 16.04 and 6.0.1 sdk with current ffmpeg.git please ?

Problem solved, I was able to compile deb of ffmpeg with nvenc and hevc support using instruction from here: Question / Help - NVENC Support For Linux | OBS Forums

Hi all,

I have a question about how to install the ffmpeg with --enable-nvresize

It is necessary to instal CUDA for using the nvresize??

i was able to compile ffmpeg with --enable-nvenc, only installing the Nvidia SDK

Hello,

Yes you can do that but it will use CPU if you resize video… so which means you are using just nvenc for codec but not resize…
It is recommended to apply patch and use nvresize too…

Hello, thanks for your response.

I have a problem to apply the patch it seems out ofdate for the new ffmpeg.

I have read that you ask for something similar above. Do you get a new patch for the lastest ffmpeg on git?

Or maybe you have used another version of ffmpeg? If so could you tell me witch one?

If I can apply patch correctly I am going to be able to compile ffmpeg with the nvresize option without installing anything else that the SDK, am I correct? And without istalling CUDA

I’m also very interested in a patch for FFmpeg 3.1.1!

hd2,

If you want I can help you to compile it on your system… ( linux )

Me too, i’m interested by a patch for FFmpeg 3.1 ^^

Hi vampie,

any help is greatly appreciated!
FYI: I’m trying to bring nvidia-docker into the game aswell (GitHub - NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA GPUs) - so this might complicate the process ;).

My current system (Ubuntu 14.04):

+------------------------------------------------------+
| NVIDIA-SMI 352.93     Driver Version: 352.93         |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro K4000        Off  | 0000:04:00.0      On |                  N/A |
| 30%   28C    P8     9W /  87W |     46MiB /  3071MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

My current status:
I managed to build the container based on nvidia/cuda:7.5, including the ffmpeg-master branch from github.

“/usr/bin/ffmpeg -encoders | grep enc” shows:

ffmpeg version N-81216-g01f0598 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  configuration: --prefix=/usr --pkg-config-flags=--static --extra-cflags=-I/usr/include --extra-ldflags=-L/usr/lib --bindir=/usr/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-nvenc --extra-cflags=-I../cudautils --extra-ldflags=-L../cudautils --enable-libxvid --enable-nonfree --enable-libx265 --enable-libx264 --enable-nonfree --disable-sdl
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.100 / 57. 51.100
  libavformat    57. 44.100 / 57. 44.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 49.100 /  6. 49.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
 V..... h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... nvenc                NVIDIA NVENC H.264 encoder (codec h264)
 V..... nvenc_h264           NVIDIA NVENC H.264 encoder (codec h264)
 V..... nvenc_hevc           NVIDIA NVENC hevc encoder (codec hevc)
 V..... hevc_nvenc           NVIDIA NVENC hevc encoder (codec hevc)

So I thought, this should work. Unfortunately, when running “/usr/bin/ffmpeg -i /test/elephants-dream.webm -c:v hevc_nvenc -b:v 1M -y /test/webm_to_mp4_nvenc_hevc.mp4” I get the following ffmpeg error:

ffmpeg version N-81216-g01f0598 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  configuration: --prefix=/usr --pkg-config-flags=--static --extra-cflags=-I/usr/include --extra-ldflags=-L/usr/lib --bindir=/usr/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-nvenc --extra-cflags=-I../cudautils --extra-ldflags=-L../cudautils --enable-libxvid --enable-nonfree --enable-libx265 --enable-libx264 --enable-nonfree --disable-sdl
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.100 / 57. 51.100
  libavformat    57. 44.100 / 57. 44.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 49.100 /  6. 49.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from '/test/elephants-dream.webm':
  Metadata:
    encoder         : http://sourceforge.net/projects/yamka
    creation_time   : 2010-05-20 12:00:13
  Duration: 00:01:57.70, start: 0.000000, bitrate: 582 kb/s
    Stream #0:0(eng): Video: vp8, yuv420p, 540x360, SAR 1:1 DAR 3:2, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1(eng): Audio: vorbis, 44100 Hz, mono, fltp (default)
<b>[hevc_nvenc @ 0x2d15880] Failed to create nvenc instance: invalid version (15)</b>
Output #0, mp4, to '/test/webm_to_mp4_nvenc_hevc.mp4':
  Metadata:
    encoder         : http://sourceforge.net/projects/yamka
    Stream #0:0(eng): Unknown: none, SAR 1:1 DAR 0:0 (default)
    Metadata:
      encoder         : Lavc57.51.100 hevc_nvenc
    Stream #0:1(eng): Unknown: none (default)
    Metadata:
      encoder         : Lavc57.51.100 aac
Stream mapping:
  Stream #0:0 -> #0:0 (vp8 (native) -> hevc (hevc_nvenc))
  Stream #0:1 -> #0:1 (vorbis (native) -> aac (native))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Googling around for hours did not help. I still have no idea, WHICH version is actually invalid. Cuda? Nvidia Driver? ffmpeg? Combination of something? I already tried to compile with Video_Codec_SDK_7.0.1 and video-sdk-601 - same result/error.

Please let me know if you need more information on any topic. Thank you!

Hi,

i manage to patch it, only if i use this ffmpeg commit
commit b83c849e8797fbb972ebd7f2919e0f085061f37f

Hello,
Does anybody have a nvresize patch for ffmpeg 3.1 ?
Thanks!

Hello. I know that in FFMPEG 3.2 was appear NVcuvid technology that replaced nvresize. But I’m using FFmpeg 3.0, so I want to use NVresize :-)

The patch is successfully applies, but the code isn’t compile correctly:

libavfilter/vf_nvresize.c: In function 'filter_frame':
libavfilter/vf_nvresize.c:576: error: 'AVFilterLink' has no member named 'closed'
make: *** [libavfilter/vf_nvresize.o] Error 1

What did I need to fix in the patch?