Scripting issues with NVENC HEVC in version 2.7.8

Started by magicxcian, May 11, 2021, 12:59:37 AM

Previous topic - Next topic

magicxcian

I'm using Avidemux scripting to batch convert videos using NVENC HEVC encoder. Previously I had a script set up for Avidemux 2.7.6 which was working fine, using "ffNvEncHEVC" for the video codec name. However it no longer worked with Avidemux 2.7.8, giving a "No such encoder" error in the logs. After some digging, I modified my script to use "ffNvEnc" and updated parameters. Here's my script:

#PY  <- Needed to identify #
in_file = "C:\\path\\to\\input\\file"
out_file = "C:\\path\\to\\output\\file"
adm = Avidemux()
if not adm.loadVideo(in_file):
    raise("Cannot load " + in_file)
adm.setPostProc(3, 3, 0)
adm.videoCodec(
    "ffNvEnc",
    "preset=5",  # NV_FF_PRESET_HQ
    "profile=0",  # NV_FF_PROFILE_MAIN
    "rc_mode=1",  # NV_FF_RC_CONSTQP
    "quality=20",
    "bitrate=10000",  # not used in CQP mode
    "max_bitrate=20000",  # not used in CQP mode
    "gopsize=100",
    "bframes=4",
    "b_ref_mode=2",
    "lookahead=20",
    "aq_strength=8",
    "spatial_aq=True",
    "temporal_aq=False",
    "weighted_pred=True",
)
adm.audioClearTracks()
for i in range(adm.audioTotalTracksCount()):
    adm.setSourceTrackLanguage(i, "und")
    adm.audioAddTrack(i)
    adm.audioCodec(i, "copy")
    adm.audioSetDrc(0, 0)
    adm.audioSetShift(0, 0, 0)
adm.setContainer(
    "MP4",
    "muxerType=0",
    "optimize=1",
    "forceAspectRatio=False",
    "aspectRatio=1",
    "displayWidth=1280",
    "rotation=0",
    "clockfreq=0",
)
adm.save(out_file)

The problem is that this script will invoke the NVENC H.264 encoder by default. There is no way to specify HEVC since both the H.264 and HEVC videoEncoder plugins have the name "ffNvEnc" now, a name conflict.

If I use the Avidemux GUI to specify the "Nvidia HEVC" encoder and select File > Project Script > Save as Project, not only will it generate the ambiguous "ffNvEnc" name, but also any NVENC HEVC configuration specified in the GUI will not be reflected in the generated script.

As a workaround I have found that by removing the "C:\Program Files\Avidemux 2.7 VC++ 64bits\plugins\videoEncoders\libADM_ve_ffNvencH264.dll" file, we can force Avidemux to use the HEVC encoder since that will be the only one encoder with the name "ffNvEnc" once we have removed the H.264 encoder.

With this workaround, the script will work and use NVENC HEVC as desired. The video output looks fine but I get errors in the log, not sure if they are spurious:

[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-411 Dts>Pts, that can happen if there are holes in the source, fixating..
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-411 DTS=00:00:00,066
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-411 PTS=00:00:00,066
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-411 Cannot find a solution, expect problems
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-474 Dts>Pts, that can happen if there are holes in the source, fixating..
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-474 DTS=00:00:00,149
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-474 PTS=00:00:00,149
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-474 Cannot find a solution, expect problems
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-486 Dts>Pts, that can happen if there are holes in the source, fixating..
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-486 DTS=00:00:00,166
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-486 PTS=00:00:00,166
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-486 Using newDts=166664
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-537 Dts>Pts, that can happen if there are holes in the source, fixating..
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-537 DTS=00:00:00,233
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-537 PTS=00:00:00,233
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-537 Using newDts=233332
[ADM_coreVideoEncoder::getRealPtsFromInternal] 22:57:49-549 Dts>Pts, that can happen if there are holes in the source, fixating..
(etc.)

Version: Avidemux 2.7.8 - Release, running on Windows 10 x64 Version 20H2

magicxcian

DTS/PTS log issue seems to be related to an FFmpeg issue: https://trac.ffmpeg.org/ticket/7746

Seems like that issue was fixed a year ago though, so I'm not sure. In any case, the error no longer occurs if we set b_ref_mode=0 instead of 2 ("Use B-Frames as References" set to Disabled instead of Middle).

butterw


eumagga0x2a

The first issue was fixed on March 9 by [ffNvEnc] Resolve name clash between H264 and HEVC encoders created by 284b2af, the second on April 15 by [ffNvEnc] Fix insufficient encoder delay when B-frames are used for reference.

If you want to have just substantial stability and quality fixes without new features like FFmpeg upgrade, you might want to follow the support_2.7.8 branch, else please follow the git master. By all means, the last release is not the reference anymore.

magicxcian

Thanks for the replies. I updated to the latest nightly for win64 which resolved both issues.