Announcement

Collapse
No announcement yet.

Using NVIDIA's NVENC On Linux With FFmpeg

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

  • phoronix
    started a topic Using NVIDIA's NVENC On Linux With FFmpeg

    Using NVIDIA's NVENC On Linux With FFmpeg

    Phoronix: Using NVIDIA's NVENC On Linux With FFmpeg

    With the new NVIDIA 346 Linux driver series NVENC support was made available for accelerated video encoding support under Linux...

    http://www.phoronix.com/vr.php?view=MTg0NTY

  • sdack
    replied
    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".

    Leave a comment:


  • sdack
    replied
    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"

    Leave a comment:


  • sdack
    replied
    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.

    Leave a comment:


  • Nille
    replied
    You can also try nvenc_hevc for h265. But i see a difference. On Windows i have more pixel formats [Supported pixel formats: yuv420p nv12 yuv444p] and i can set a profile etc. Im Using the latest git code.

    Code:
    Encoder nvenc [NVIDIA NVENC h264 encoder]:
        General capabilities: delay
        Threading capabilities: none
        Supported pixel formats: yuv420p nv12 yuv444p
    nvenc AVOptions:
      -preset            <string>     E..V.... Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, lossless, losslesshp, default) (default "medium")
      -profile           <string>     E..V.... Set the encoding profile (high, main, baseline or high444p) (default "main")
      -level             <string>     E..V.... Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1) (default "auto")
      -tier              <string>     E..V.... Set the encoding tier (main or high) (default "main")
      -cbr               <boolean>    E..V.... Use cbr encoding mode (default false)
      -2pass             <boolean>    E..V.... Use 2pass encoding mode (default auto)
      -gpu               <int>        E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from 0 to INT_MAX) (default 0)
      -delay             <int>        E..V.... Delays frame output by the given amount of frames. (from 0 to INT_MAX) (default INT_MAX)
    Code:
    Encoder nvenc_hevc [NVIDIA NVENC hevc encoder]:
        General capabilities: delay
        Threading capabilities: none
        Supported pixel formats: yuv420p nv12 yuv444p
    nvenc_hevc AVOptions:
      -preset            <string>     E..V.... Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, lossless, losslesshp, default) (default "medium")
      -profile           <string>     E..V.... Set the encoding profile (high, main, baseline or high444p) (default "main")
      -level             <string>     E..V.... Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1) (default "auto")
      -tier              <string>     E..V.... Set the encoding tier (main or high) (default "main")
      -cbr               <boolean>    E..V.... Use cbr encoding mode (default false)
      -2pass             <boolean>    E..V.... Use 2pass encoding mode (default auto)
      -gpu               <int>        E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from 0 to INT_MAX) (default 0)
      -delay             <int>        E..V.... Delays frame output by the given amount of frames. (from 0 to INT_MAX) (default INT_MAX)

    Leave a comment:


  • cacasodo
    replied
    Interesting. I'll play around with some of the options later on as well. Here is what the ffmpeg help states about the switches we have access to:

    Code:
    [[email protected] ~]$ ffmpeg -h encoder=nvenc
    ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
      built with gcc 5.3.1 (GCC) 20151207 (Red Hat 5.3.1-2)
    ..
    Encoder nvenc [Nvidia NVENC h264 encoder]:
        Threading capabilities: no
        Supported pixel formats: nv12
    nvenc AVOptions:
      -preset            <string>     E..V.... Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default) (default "hq")
      -cbr               <int>        E..V.... Use cbr encoding mode (from 0 to 1) (default 0)
      -2pass             <int>        E..V.... Use 2pass cbr encoding mode (low latency mode only) (from -1 to 1) (default -1)
      -gpu               <int>        E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from 0 to INT_MAX) (default 0)

    Leave a comment:


  • Nille
    replied
    i download a uhd sample right now and see if it is a big impact (ofc there is a impact)

    EDIT: So UHD 3840x2160 are encoded with hevc with around 27 fps and with h264 33fps. I can test it also with quicksync
    Uh, but the quality is low. I test it with another preset slow = horrible
    EDIT2: hq looks better but still low. ok the source file is over 1GB and the output has only 30MB. He goes to 2000 kbit for both per default. Without the Preset the encoding is a bit faster, around 40fps with uhd

    PS: qsv is not starting but eat up one core without progress
    Last edited by Nille; 05-25-2016, 04:13 PM.

    Leave a comment:


  • cacasodo
    replied
    Hi Nille,
    I should have made it more clear that my source is a much larger 2.7K video from a GoPro, not the 1080P content that you're transcoding.

    That being said, I'll try a 1080P render to see what I get.
    'sodo

    Leave a comment:


  • Nille
    replied
    i get much much more fps with my 960. I have Encoded a 1080p with over 200 fps.

    Code:
    ffmpeg -i "input(1080p).mp4" -map 0 -loglevel repeat+verbose -c copy -c:v nvenc -preset slow -movflags +faststart "output-nvenc.mp4"
    And the same wile with hevc/h265 around 90 fps

    Code:
    ffmpeg -i "input(1080p).mp4" -map 0 -loglevel repeat+verbose -c copy -c:v nvenc_hevc -preset slow -movflags +faststart "output-nvenc_hevc.mp4"
    Each one that is interested in a ffmpeg build for windows with it, can use this scrips to build it. https://github.com/jb-alvarado/media-autobuild_suite This Download everything needed an build some a/v tools from git.

    i would provide my builds but due to all the included stuff its not distributable.
    Last edited by Nille; 05-25-2016, 01:56 PM.

    Leave a comment:


  • cacasodo
    replied
    This thread was helpful to me in getting FFmpeg compiled on Fedora 22. I posted initial results of the CPU offload from a 2.7K source video and FPS increase by using nvenc over libx264. Impressive.
    Last edited by cacasodo; 05-25-2016, 02:02 PM.

    Leave a comment:

Working...
X