[FFmpeg-devel] ffmpeg nvenc

ahu ahu at nvidia.com
Thu Dec 18 06:35:05 CET 2014


On 12/17/2014 10:20 PM, compn wrote:> On Wed, 17 Dec 2014 09:34:56 +0000
 > Agatha Hu <ahu at nvidia.com> wrote:
 >> We've almost finished the license part in our patch and plan to
 >> commit to ffmpeg community, but we found ffmpeg add Timo's nvenc
 >> patch days ago, so our patch is incompatible with the TOT version.
 >> Should we (1)Add libnvenc on TOT branch but without changing Timo's
 >> work or (2)Change nvenc on TOT branch like an incremental patch on
 >> Timo's work. In fact I would prefer (1), as it requires less work.
 >
 > probably (1) for now. that way we can see the differences between the
 > implementations. sometimes two implementations allow us to find bugs.
 >
 > if the license situation is "fixed", then later on it might be possible
 > for timo to work on the nvidia nvenc and there wont be so much code
 > duplication.
 >
 > its happened before (mpeg decoding, prores, h264 encoders, mpeg4
 > decoders) so its nothing new for ffmpeg to have multiple
 > implementations. although there might be some devs complaining about
 > it :)
 >
 > i dont speak for the project, so better wait for more replies.
 >
 > please post an updated patch with the license fixes when possible.
 >
 > -compn

On 12/18/2014 12:55 AM, Anshul wrote:
 > In my opinion we should try diff of both solution and review the first
 > one in respect to second, though it would take more effort in review.
 > Side note: I do have request please quote the reason(pros and cons) for
 > your opinion of choice.
 > because decision based on number of opinion does not benefits the
 > project, but only benefits number of developer (feeling).
 >
 > -Anshul
 >

Ok thanks for the advice. I attached the libnvenc patch without changing 
Timo's work.
There's a README.txt, explaining the patch structure and system 
requirement.

Agatha Hu


-------------- next part --------------
NVIDIA NVENC - Patch to support H.264 encoding on NVENC through FFmpeg

[Overview]

    This patch allows FFmpeg, when compiled with specific flags,
    to use NVIDIA NVENC hardware to perform GPU-accelerated encoding to
    industry standard H.264 on supported NVIDIA GPUs.
	Before building this patch, you must install the NVIDIA NVENC SDK
	(https://developer.nvidia.com/nvidia-video-codec-sdk) and latest
	NVIDIA R346 driver(http://www.nvidia.com/).
	
    The standard flow is as follows:

    /--------------FFmpeg-----------------\
    FFmpeg frontend -> libnvenc -> nvencoder -> NVENC DLL/SO -> NVENC HW
          (1)            (2)          (3)          (4)         (5)

    1. FFmpeg frontend is modified to know of "libnvenc"
    2. Implementation of a codec for encoding
    3. Implementation of encoding using NVENC SDK
    4. NVENC runtime on user's system, dynamically loaded
    5. NVENC hardware called by runtime

    NOTE:
    Currently, D3D-context is used for NVENC DLL on Windows, and
    CUDA-context is used for NVENC so on Linux. This can be changed
    to use CUDA-context for both if desired.

[Changes]
    configure
        * Add "libnvenc" external library
            - represents the new NVENC-specific code and enables compile
        * Add "--enable-libnvenc" config flag
            - enables the actual compilation of the NVENC code
        * Add licensing restrictions for building NVENC-enabled FFmpeg
            - cannot build with 'GPL' code enabled (i.e. "--enable-gpl")
        * Add build environment restrictions
            - must have NVENC SDK installed
            - must have OS support for dynamic library loading available

    ffmpeg.c
    libavformat/matroskaenc.c
    libavformat/movenc.c
        * Add support for using "libnvenc" wherever "libx264" is used
    
    libavcodec/Makefile
        * Add compile of "libnvenc" files when configured
        
    libavcodec/allcodecs.c
        * Add "libnvenc" as an available codec to choose during runtime

    libavcodec/libnvenc.c
        * NEW FILE: FFmpeg<->NVENC glue
        * Follows FFmpeg convention to implement a "libnvenc" codec
            - exposes capabilities of NVENC to FFmpeg
            - translates FFmpeg-specific params to more NVENC params
            - exports the encode functions callbacks to FFmpeg
            - function callbacks forward encoding calls to NVENC wrapper

    libavcodec/libnvenc.h
        * NEW FILE: NVENC wrapper header
        * Function declarations of NVENC wrapper that libnvenc.c uses
        * Avoid exposing unnecessary NVENC wrapper internals to FFmpeg

    libavcodec/nvencoder.c
    libavcodec/nvencoder.h
        * NEW FILE: NVENC wrapper implementation
        * Lightweight functions that wrap the NVENC SDK interfaces
            - Provides encoding implementation using NVENC SDK, CUDA SDK
            - Handles necessary book-keeping, boilerplate code, etc.
        * Multi-purpose
            - Serves to hide complexity from FFmpeg, make code modular
            - Serves to provide a more familiar interface to clients
                > simpler interface, similar to SW encoders
            - Serves as a simple example for using NVENC SDK
                > written in C, can be used in other customer projects

    nvencoder_utils.c
    nvencoder_utils.h
        * NEW FILE: Helper functions for NVENC wrapper
        * Utility functions for converting/mapping of encode parameters
            - parses string of x264 params and maps to NVENC, ex:
                > x264: level=3.0 , NVENC: level=NVENC_LEVEL_30
				
	doc/examples/libnvenc.c
		* NEW FILE: Simple libnvenc sample
		* A sample showing how to use libnvenc as video encoder with 
		* avcodec contexts as well as how to set up encoding options
	
	doc/examples/Makefile
        * Add compile of "libnvenc" files when configured

[Building]
    1. Setup build environment (see FFmpeg website)
    2. Apply the patch to FFmpeg source
    3. Run "configure" with libnvenc option:
        ./configure --prefix="/ffmpeg/build" --bindir="/ffmpeg/bin"
         --extra-cflags="-I/ffmpeg/build/include"
         --extra-ldflags="-L/ffmpeg/build/lib" --enable-libnvenc
    4. Build with "make" and "make install"
    
[Usage]
    1. Run FFmpeg as usual when transcoding:
        ./ffmpeg -i input.mp4 -v:profile baseline output.mp4
    2. Some outputs require a codec; replace "libx264" with "libnvenc":
        ./ffmpeg -i input.mp4 -vcodec libnvenc -f mpegts output.ts
		
[Encoding settings]
	1. Support native FFMPEG options and x264 options (-x264opt)
	2. libnvenc chooses rate control mode automatically. Default is CQP, 
	   if bitrate > 0, uses CBR; if bitrate > 0 and maxrate > 0, uses VBR,
	   if qp > 0, uses CQP.
	3. Default preset is NV_ENC_PRESET_DEFAULT_GUID, you can choose preset by:
	   NV_ENC_PRESET_HP_GUID                 : -preset fast
	   NV_ENC_PRESET_HQ_GUID                 : -preset slow 
	   NV_ENC_PRESET_LOW_LATENCY_HP_GUID     : -tune zerolatency -preset fast
	   NV_ENC_PRESET_LOW_LATENCY_HQ_GUID     : -tune zerolatency -preset slow 
	   NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID: -tune zerolatency 
    4. Definitions of other options can be found in libnvenc.c: 325~363
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-add-libnvenc-support.patch
Type: text/x-patch
Size: 86253 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141218/7d786004/attachment.bin>


More information about the ffmpeg-devel mailing list