Announcement

Collapse
No announcement yet.

Using NVIDIA's NVENC On Linux With FFmpeg

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #41
    I was in need of a fast encoder myself and now started using HEVC/H.265 with nvenc running on a GTX 960. Little did I know... not only is the quality good, the speed fast, but one can run two encoding processes in parallel!

    For some reason does the GTX960 allow to run two nvenc session simultaneously, thereby doubling the theoretical encoding speed. So now am I encoding two videos at a time, each at 200fp/s. An example:

    Code:
    $ find Videos/ -type f -name \*.avi -print | sed 's/.avi$//' |\
      xargs -n 1 [email protected] -P 2 ffmpeg -i "@.avi" -c:a aac -c:v hevc_nvenc "@.mp4"
    This will find all files with the ending .avi in the directory Videos/ and transcode them into HEVC/H265+AAC files with the ending .mp4. The noteworthy part here is the -P 2 to xargs, which starts up to two processes in parallel.

    Trying to start a third process results in an "out of memory error" and the Nvidia documentation (on their developers' website) states that a GTX960 can only run two sessions. Quadro cards supposedly can handle more than 2. This is some amazing encoding power.

    Comment


    • #42
      I've now managed to get even more speed from using an Nvidia GTX 960 for HEVC/H.265 encoding. Using ffmpeg 3.1.2 and Nvidia Video SDK 7.0.1 can one not only use two nvenc sessions in parallel for more speed, but it also allows to combine it with CUDA for faster image scaling on top of it. So instead of doing this:
      Code:
      ffmpeg -i input.avi \
            -c:a aac -b:a 128k \
            -s hd480 \
            -c:v hevc_nvenc -b:v 1024k \
            -y output.mp4
      Can one replace the "-s hd480" with a (somewhat complicated) filter and do:
      Code:
      ffmpeg -i input.avi \
            -c:a aac -b:a 128k \
            -filter:v “hwupload_cuda,scale_npp=w=852:h=480:format=nv12:interp_algo=lanczos,hwdownload,format=nv12” \
            -c:v hevc_nvenc -b:v 1024k \
            -y output.mp4
      This uploads each frame to the CUDA engine where it then scales these with the lanczos algorithm to a size of 852x480 pixels (same as hd480). The format "nv12" as well as "yupv420p" can be used here and needs to be specified in order for it to work. "nv12" seems to run a bit faster than "yuv420p" but both formats are recognized by the nvenc encoder.

      When I started with it was I encoding videos at a speed of 10-20 fp/s with libx264, just so I can upload them to mobile phones and tablets. Needless to say how pointless it seemed having to wait several hours for the encoding to finish just to be able to watch a 30min video on a mobile phone.

      Now, running two ffmpeg proccesses in parallel and using CUDA for scaling, am I encoding videos with a combined speed of 720 fp/s (2x360 fp/s) on a GTX 960.
      Code:
      find Videos/ -type f -name \*.avi -print | sed 's/.avi$//' | xargs -n 1 [email protected] -P 2 \
         ffmpeg -i "@.avi" \
            -c:a aac -b:a 128k \
            -filter:v “hwupload_cuda,scale_npp=w=852:h=480:format=nv12:interp_algo=lanczos,hwdownload,format=nv12” \
            -c:v hevc_nvenc -b:v 1024k \
            -y "@.mp4"

      Comment


      • #43
        Originally posted by sdack View Post
        ... The format "nv12" as well as "yupv420p" can be used here ...
        When I started with it was I encoding videos at a speed of 10-20 fp/s with libx264, just ...
        I wonder why I can no longer edit my post... It should say "yuv420p" and "libx265".

        Comment

        Working...
        X