Segmentation fault: Statically built FFmpeg with NVENC

I’m trying to build statically-linked FFmpeg with NVENC.
I successfully built it, but when I started encoding, Segmentation fault occurred.

The configuration options of FFmpeg are shown below:

$ PATH=$HOME/bin:$PATH PKG_CONFIG_PATH=$HOME/ffmpeg_build/lib/pkgconfig ./configure --prefix="$HOME/ffmpeg_build" --pkg-config-flags="--static" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib --static" --bindir="$HOME/bin" --enable-gpl --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-nvenc --enable-nonfree

I can finish encoding when I select normal h264 encoder (without NVENC):

$ ffmpeg -i input.mp4 -vcodec <b>h264</b> output.mp4  # Success!

But when I select NVENC, the job failed due to Segmentation fault:

$ ffmpeg -i input.mp4 -vcodec <b>h264_nvenc</b> output.mp4
ffmpeg version N-81477-g0c023d1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609
  configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags='-L/root/ffmpeg_build/lib --static' --bindir=/root/bin --enable-gpl --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-nvenc --enable-nonfree
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.100 / 57. 54.100
  libavformat    57. 48.100 / 57. 48.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 57.100 /  6. 57.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-02-08 18:56:45
  Duration: 00:01:30.00, start: 0.000000, bitrate: 3120 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 2925 kb/s, 24 fps, 24 tbr, 48 tbn, 48 tbc (default)
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2013-02-08 18:56:46
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
<b>Segmentation fault (core dumped)</b>

I tried “gdb” command but I couldn’t obtain any useful information:

(gdb) backtrace
#0  0x0000000000000000 in ?? ()
#1  0x00007f59ef33dfe9 in ?? ()
#2  0x00007ffc0000000a in ?? ()
#3  0x0000000000000010 in ?? ()
#4  0x0000000000800000 in ?? ()
#5  0x00000000035c7190 in ?? ()
#6  0x0000000001687805 in ?? ()
#7  0x000000000165ce05 in ?? ()
#8  0x000000000165af14 in ?? ()
#9  0x000000000165c769 in ?? ()
#10 0x00000000015f99a7 in ?? ()
#11 0x000000000165af14 in ?? ()
#12 0x00000000015f9dd2 in ?? ()
#13 0x00000000015f99fe in ?? ()
#14 0x0000000000462fa1 in ?? ()
#15 0x0000000000a9fc7a in ?? ()
#16 0x000000000048f1dd in ?? ()
#17 0x0000000000494ec9 in ?? ()
#18 0x000000000047709f in ?? ()
#19 0x00000000015cf2d6 in ?? ()
#20 0x00000000015cf4ca in ?? ()
#21 0x0000000000477739 in ?? ()

But I guess this Segmentation fault was caused by libcuda.so because when I removed libcuda.so, FFmpeg said:

$ ffmpeg -i input.mp4 -vcodec <b>h264_nvenc</b> output.mp4
ffmpeg version N-81477-g0c023d1 Copyright (c) 2000-2016 the FFmpeg developers

# (Omitted)

    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2013-02-08 18:56:46
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
<b>[nvenc @ 0x2b65920] Cannot load libcuda.so</b>

Removing –extra-ldflags="–static" from configuration led to successful result even if NVENC was selected.
But I need completely static FFmpeg. I expect “ldd” command to return “not a dynamic executable” like below:

$ ldd ffmpeg
        not a dynamic executable

Here are supplementary information about my environment:

  • OS : Ubuntu 16.04.1 LTS (kernel 4.4.0-34-generic, arch x86_64)
  • GPU : GeForce GTX 1060 (driver 367.44)
  • CUDA : CUDA Toolkit 8.0.27
  • FFmpeg : Recent version (cloned from Git)
  • NVENC SDK : NVIDIA Video Codec SDK 7.0.1

Unfortunately, the combinations of Ubuntu 14.04.5 LTS + GeForce GTX 960M, or CentOS 7.1 + GeForce GTX 960M reached the same consequence, too.

Are there any ways to build FFmpeg with NVENC statically?
I’ve spent more than 3 days on this problem. I’m waiting for your reply.

Thank you.

I don’t believe you’ll be able to eliminate the dependency on libcuda.so

If you want useful info from gdb backtrace, build with symbols.