Skip to content

Nvenc encoder #259 Support - #983

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 7, 2017 •

Copy link
Copy Markdown
Contributor

sgothel and others added 27 commits November 7, 2017 14:15
Patch for HandBrake#974
moving to FFMPEG 3.4 from LIBAV 12.2.

All patches have been moved to subfolder 'old' since they do not apply cleanly anymore.
Work has to be performed to validate whether patches are still required.

The re-ordering of to be linked modules was required to solve
statically linked dependencies. See libhb/module.defs etc.
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.
@sgothel sgothel changed the title Nvenc encoder Nvenc encoder #259 Support Nov 7, 2017
@sgothel

sgothel commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

Encoding to h265-nvenc gives me (similar with h264-nvenc) an error code in the end despite proper results/artifacts, see below.

Working a bit on the fine details and will also change the type defines to 'FF_NVENC' specific one from the Handbrake view, since this code path is specific.

[15:22:24] work: average encoding speed for job is 73.192154 fps
[15:22:24] vfr: lost time: 0 (0 frames)
[15:22:24] vfr: gained time: 0 (0 frames) (0 not accounted for)
[15:22:24] stream: 13925 good frames, 0 errors (0%)
[15:22:25] dca-decoder done: 54389 frames, 0 decoder errors
[15:22:25] dca-decoder done: 54398 frames, 0 decoder errors
[15:22:25] h264-decoder done: 13923 frames, 0 decoder errors
[15:22:25] sync: got 13923 frames, 13923 expected
[15:22:25] sync: framerate min 23.981 fps, max 23.981 fps, avg 23.976 fps
[15:22:25] mux: track 0, 13923 frames, 424518533 bytes, 5848.32 kbps, fifo 512
[15:22:25] mux: track 1, 54389 frames, 69617920 bytes, 959.08 kbps, fifo 2048
[15:22:25] mux: track 2, 54398 frames, 55703552 bytes, 767.39 kbps, fifo 2048
[15:22:25] mux: track 3, 274 frames, 3123889 bytes, 43.04 kbps, fifo 16
[15:22:25] libhb: work result = 4

Comment thread libhb/common.h
#define HB_VCODEC_FFMPEG_VP8 0x0000040
#define HB_VCODEC_FFMPEG_VP9 0x0000080
#define HB_VCODEC_FFMPEG_VP9 0x0000050
#define HB_VCODEC_FFMPEG_H264 0x0000070

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.

I don't have time to do a full review at the moment. But noticed this during a quick scan.

This should be HB_VCODEC_NVENC_H264 and HB_VCODEC_NVENC_H265. "FFMPEG" is too generic. FFMPEG_VP9 is a bad example to follow unfortunately, it should have been LIBVPX_VP9 or some such.

Comment thread libhb/encavcodec.c
} break;
case AV_CODEC_ID_H264:
{
codec = avcodec_find_encoder_by_name("h264_nvenc");

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.

Although not strictly necessary at this time, this should be:

case AV_CODEC_ID_H264:
{
    if (job->vcodec == HB_VCODEC_NVENC_H264)
    {
        codec = avcodec_find_encoder_by_name("h264_nvenc");
    }
    else
    {
        hb_error("encavcodecInit: unsupported encoder!");
        ret = 1;
        goto done;
    }
} break;

In the future, there will be other h.264 encoders that use this path.

@sr55 sr55 assigned sr55 and sgothel and unassigned sr55 Nov 8, 2017
@sr55
sr55 self-requested a review November 8, 2017 21:25
@sr55 sr55 added this to the 1.2.0 milestone Nov 8, 2017
Comment thread libhb/encavcodec.c
if( w->codec_param == AV_CODEC_ID_HEVC ) {
av_dict_set( &av_opts, "spatial_aq", "1", 0 ); // oops, nvenc_hevc.c uses an underscore
} else {
av_dict_set( &av_opts, "spatial-aq", "1", 0 ); // oops, nvenc_h264.c uses a dash

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.

We should be able to bring these options though the extra arguments string, split that and feed those to the encoder. Having full control over the encoder is defiantly preferable.

Comment thread libhb/common.h
/******************************************************************************
* hb_job_t: settings to be filled by the UI
* Update win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs when changing this struct
* Update win/CS/HandBrake.ApplicationServices/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs when changing this struct

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.

Something odd happened with this commend. It was incorrect. HandBrake.Interop is gone. Correct path is: HandBrake.ApplicationServices\Interop\HbLib

@sgothel sgothel closed this Dec 26, 2017
@sgothel
sgothel deleted the nvenc-encoder branch December 26, 2017 01:46
sgothel added a commit to sgothel/HandBrake that referenced this pull request Dec 26, 2017
@sr55 'Something odd happened with this comment. It was incorrect. HandBrake.Interop is gone. Correct path is: HandBrake.ApplicationServices\Interop\HbLib'
HandBrake#983 (comment)
@bradleysepos bradleysepos removed this from the 1.2.0 milestone Jan 15, 2018
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.

5 participants