Skip to content

Nvenc encoder - #971

Closed
sgothel wants to merge 27 commits into
HandBrake:masterfrom
sgothel:nvenc-encoder
Closed

sgothel wants to merge 27 commits into
HandBrake:masterfrom
sgothel:nvenc-encoder

Conversation

@sgothel

@sgothel sgothel commented Nov 1, 2017

Copy link
Copy Markdown
Contributor

cherry picked patches from my '259-add-nvenc-encoder' branch, see https://github.com/sgothel/HandBrake/commits/259-add-nvenc-encoder
applicable on official master branch

I have not picked @compninja28 patches regarding windows components
due to heavy collisions:

+++

NVENC: Remaining fixes for a 1st working draft on GNU/Linux (GTK)

Basically working:

h264_nvenc
hevc_nvenc
Possible optimization:
Even in constant quality mode, a user ceiling bit_rate might be desirable,
currently only the maximum is used like in VP8/9: w x h x fps

Remaining issues:

Muxer issue with h264_nvenc + MKV, ffprobe shows:

[h264 @ 0x55ae4dedacc0] sps_id 32 out of range
[h264 @ 0x55ae4dedacc0] Invalid nal size 1677734572
[h264 @ 0x55ae4dedacc0] missing picture in access unit with size 40644

Notable: This does not happen with hevc_nvenc

Tested:

GNU/Linux Debian 9
GeForce GTX 950
BD 1080p source, cropped alignment 8: Around 90fps h264 + hevc cq 28, profile main

MatthewLazarow and others added 23 commits November 1, 2017 02:45
Basically working:
- h264_nvenc
- hevc_nvenc
Possible optimization:
- Even in constant quality mode, a user ceiling bit_rate might be desirable,
  currently only the maximum is used like in VP8/9: w x h x fps

Remaining issues:
1) Muxer issue with h264_nvenc + MKV, ffprobe shows:

[h264 @ 0x55ae4dedacc0] sps_id 32 out of range
[h264 @ 0x55ae4dedacc0] Invalid nal size 1677734572
[h264 @ 0x55ae4dedacc0] missing picture in access unit with size 40644

   Notable: This does not happen with hevc_nvenc

Tested:
- GNU/Linux Debian 9
- GeForce GTX 950
- BD 1080p source, cropped: Around 70fps h264 + hevc
Adding 'rc-lookahead 32, init_qp 1, spatial_aq 1, aq-strength 8' for h264 and hevc
in case of VBR CQ mode, see
  <https://devtalk.nvidia.com/default/topic/1013152/video-technologies/crf-for-nvenc/post/5179877/#5179877>
and NVENC_VideoEncoder_API_ProgGuide.pdf v08 Chapter 8 p27, as well as Table 1 p33.
@sr55

sr55 commented Nov 1, 2017 •

Copy link
Copy Markdown
Contributor

We currently use libav and don't have the capacity to be changing that short term, so we'll need to look at integrating any required fixes into libav. (or porting patches until such time libav pick them up)

I can handle any Windows UI components, so don't need to worry about that.

@sgothel

sgothel commented Nov 2, 2017

Copy link
Copy Markdown
Contributor Author

Depends on feature request 'issue' #974

Comment thread libhb/encavcodec.c
av_dict_set( &av_opts, "cq", quality, 0 );

// further Advanced Quality Settings in Constant Quality Mode
av_dict_set( &av_opts, "init_qpP", "1", 0 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI's have an extra arguments box to allow strings to be passed through to configure the encoder. so we probably want to wire that in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can add those .. additionally. At the commented point these are for proper adaptive constant quality like x264

Comment thread contrib/ffmpeg/module.defs Outdated

# To build with nvenc:
# See <https://dwijaybane.wordpress.com/2017/07/19/ffmpeg-with-nvidia-acceleration-on-ubuntu-16-04-nvenc-sdk/>
# 1) Copy NVENC SDK's Video_Codec_SDK_8.0.14/Samples/common/inc/*.h to /usr/local/include/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See, this is where I got a bit confused. Those headers I downloaded were NOT GPL compatible. FFMpeg seems to inlclude the required headers in another folder to avoid needing the SDK for this reason. libav currently does not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this would be for libav right?

Comment thread contrib/ffmpeg/module.defs Outdated
# See <https://dwijaybane.wordpress.com/2017/07/19/ffmpeg-with-nvidia-acceleration-on-ubuntu-16-04-nvenc-sdk/>
# 1) Copy NVENC SDK's Video_Codec_SDK_8.0.14/Samples/common/inc/*.h to /usr/local/include/
# 2) Build cudautils
# wget http://developer.download.nvidia.com/compute/redist/ffmpeg/1511-patch/cudautils.zip

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these headers required for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are actually no more needed, since included in FFMPEG yup.
I copied these instruction earlier for myself .. should remove it.

@jstebbins

Copy link
Copy Markdown
Contributor

See, this is where I got a bit confused. Those headers I downloaded were NOT GPL compatible. FFMpeg seems to inlclude the required headers in another folder to avoid needing the SDK for this reason. libav currently does not.

There has been a somewhat heated discussion over this lately on the ffmpeg mailing list. The discussion was kicked off by the inclusion of external headers with the proposed AMD AMF patch. The thread below is the ongoing discussion after that patch was submitted.
https://ffmpeg.org/pipermail/ffmpeg-devel/2017-October/218834.html
https://ffmpeg.org/pipermail/ffmpeg-devel/2017-November/218932.html

The consensus seems to be that allowing this inclusion of external headers into the ffmpeg code base was a mistake. But it's not clear yet what the outcome will be.

@sgothel

sgothel commented Nov 4, 2017

Copy link
Copy Markdown
Contributor Author

@sr55 @jstebbins w/o having read above convo, AFAIK current state of the art and law is that simple declarations in headers w/o any algorithms is fine to be included (or re-written).
However, it might get tricky with fancy algos/macros or poetry (names) ..
As is .. it doesn't seem to be an issue and we are using FFMPEG's header inclusion of version 3.4 now.

…ad, header inclusion etc). FFMPEG 3.4 includes them all.
commit 0466852 moving to ffmpeg 3.4
enabled it's libx264 codec. Removed.
@sgothel

sgothel commented Nov 4, 2017

Copy link
Copy Markdown
Contributor Author

@sr55 @jstebbins reading a bit .. looks like the compromise indeed is to include basic headers and to dynamically link against system libraries. Good.

@sgothel

sgothel commented Nov 4, 2017

Copy link
Copy Markdown
Contributor Author

I am w/ Timo here (include MIT licensed headers).. sometimes I believe discussions simply get out of hand.
Sure, if one wants to maintain and create a micro package for these headers, go ahead .. and one can use them later. But enforcing ppl to work hard for some ideal world grandslam solution is ridiculous.
Might be the lately SJW trend inducing too much noise? cough cough
Bottom line .. stay focused on the task and technical merits, while favoring clean solutions if feasible.

https://ffmpeg.org/pipermail/ffmpeg-devel/2017-October/218896.html

@sgothel

sgothel commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

working on new branch on top of #981
and hence #974

@sgothel sgothel closed this Nov 7, 2017
@sgothel
sgothel deleted the nvenc-encoder branch November 7, 2017 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants