Avidemux Forum

Avidemux => Windows => Topic started by: Videograbber on April 28, 2022, 10:22:58 AM

Title: NVENC HEVC problems
Post by: Videograbber on April 28, 2022, 10:22:58 AM
Hello developers!

There is no "reference frame" settings in NVENC HEVC , only B-Frame option exist. The other problem is the very low max bitrate settings in NVENC. NVENC NVIDIA cards can use from 200Mbit to 1200 Mbit bitrate, however in Avidemux only max 50 Mbit/s bitrate is allowed, which is too low for a 4K @ 60 FPS video.

Can you impelemnt frame number option and a much higher bitrate?

Thank you for your reply!
BEst regards!
Bye!
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 28, 2022, 03:33:57 PM
Are you sure you have tried the latest available nightly build? Sure, the maximum bitrate for NVENC encoders wasn't increased (both https://www.nvidia.com/en-us/geforce/guides/broadcasting-guide/ (https://www.nvidia.com/en-us/geforce/guides/broadcasting-guide/) and https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding_tiers_and_levels (https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding_tiers_and_levels) suggest that 50.000 kbps should be sufficient for 3840×2160@60 fps and Main profile), but the point is that one should use CQP rather than specifying bitrate.

Regarding hevc_nvenc FFmpeg encoder Avidemux wraps in its NVENC encoder plugin, it supports three reference frame modes for B-frames (none, each and middle) and Avidemux exposes all of them in the current NVENC HEVC encoder configuration GUI.
Title: Re: NVENC HEVC problems
Post by: Videograbber on April 28, 2022, 06:36:24 PM
Quote from: eumagga0x2a on April 28, 2022, 03:33:57 PMAre you sure you have tried the latest available nightly build? Sure, the maximum bitrate for NVENC encoders wasn't increased (both https://www.nvidia.com/en-us/geforce/guides/broadcasting-guide/ (https://www.nvidia.com/en-us/geforce/guides/broadcasting-guide/) and https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding_tiers_and_levels (https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding_tiers_and_levels) suggest that 50.000 kbps should be sufficient for 3840×2160@60 fps and Main profile), but the point is that one should use CQP rather than specifying bitrate.

Regarding hevc_nvenc FFmpeg encoder Avidemux wraps in its NVENC encoder plugin, it supports three reference frame modes for B-frames (none, each and middle) and Avidemux exposes all of them in the current NVENC HEVC encoder configuration GUI.

50 Mbit/s is minimum for broadcast standard in HD 1080p. If you are a cameraman of TV company, they ask you to provide them the simple 1080p material in 50Mbit/s, when you handle the video to the studio. If a cameraman record in 1080p under 50Mbit/s, than she/he will be fired from the TV company, because it is under the standard....

In 4K resolution, 100 MBit HEVC is sufficient for 25/30 Fps but for studio quality you need minimum 200Mbit/s for 50/60P video.

I have never seen such low bitrate restriction in any other transcoder softwares.

Regarding to NVENC, all famous encoders (Staxrip, Hybrid etc..) provide ref frame option and b frame options. There is no reference frame option in Avidemux, Avidemux have only B-frame option. NVENC allows 7 Reference frames and 5 B-frames. B-frames are not the same as Reference Frames.

An example:
(https://i.ibb.co/pRcFqvD/k-p.png)
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 28, 2022, 08:14:52 PM
Of course I know that the number of B-frames has nothing to do with the number of reference frames beyond the latter being greater than one. As I tried to explain, Avidemux uses (at best) what hevc_nvenc libavcodec encoder in the bundled FFmpeg libraries can offer*, we don't use the interfaces provided by the driver directly.

Increasing maximum bitrate in the configuration GUI code is not a problem, but if you need a higher bitrate than the GUI control allows right now, set the desired value via scritping and avoid opening the graphical configuration, e.g.

adm = Avidemux()
adm.videoCodec("ffNvEncHEVC", "preset=5", "profile=0", "rc_mode=5", "quality=10", "bitrate=100000", "max_bitrate=200000", "gopsize=60", "bframes=3", "b_ref_mode=2", "lookahead=8", "aq_strength=1", "spatial_aq=False", "temporal_aq=False"
, "weighted_pred=True")

You can pass these commands to the application manually (per copy and paste) via Avidemux scripting shell or by saving it as a text file with extension .py and placing it in %appdata%\avidemux\custom\ directory.

*) We need to switch to new presets, this is true. I plan to do this when FFmpeg gets upgraded to 5.x.
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 28, 2022, 08:54:03 PM
--> [ffNvEnc] Increase maximum bitrate supported by configuration dialog (https://github.com/mean00/avidemux2/commit/ef6e4ea20d141f654117c49fd3fca55f446a4595)
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 28, 2022, 08:57:24 PM
Quote from: eumagga0x2a on April 28, 2022, 08:14:52 PMYou can pass these commands to the application manually (per copy and paste) via Avidemux scripting shell or by saving it as a text file with extension .py and placing it in %appdata%\avidemux\custom\ directory.

Not just by placing alone but by restarting Avidemux and selecting the entry matching the filename of the script from the "Custom" menu, of course.
Title: Re: NVENC HEVC problems
Post by: Videograbber on April 29, 2022, 02:37:20 PM
Hello eumagga!%

Where/How can I write a mail/message to the developers of libavcodec ?
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 29, 2022, 06:31:11 PM
Nevermind, NVENC API supports multiple ref frames since version 9.1 and official builds use almost for sure a version >= 9.1, probably 11.x something. The field we need to set is in AVCodecContext, not in encoder-specific parameters. Patch implementing customizable number of ref frames in NVENC-based encoder plugins inbound.
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 29, 2022, 07:41:31 PM
Roughly implemented by [ffNvEnc] Add maximum number of reference frames to encoder configuration (https://github.com/mean00/avidemux2/commit/a379d2cab6be7d524b8c81e3a3f2df248633f006), please test a future nightly and report back as my NVIDIA graphics card doesn't support custom max. ref frames values and also cannot encode HEVC.

We'll probably get some angry support requests due to this change because in its current form, it invites the user to shoot oneself in the foot :-/
Title: Re: NVENC HEVC problems
Post by: Videograbber on April 30, 2022, 06:52:03 PM
Yes, I will try it out, as soon as you will release the new version.
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 30, 2022, 07:06:30 PM
I am not sure whether you clearly understand the difference between release and nightly, but without verification that it works as intended in nightlies, I will remove it prior to release. It won't be in the release then.

Refresh of nightly builds was requested, so please test when one becomes available.
Title: Re: NVENC HEVC problems
Post by: Videograbber on April 30, 2022, 07:42:37 PM
https://www.avidemux.org/nightly/
Quote from: eumagga0x2a on April 30, 2022, 07:06:30 PMI am not sure whether you clearly understand the difference between release and nightly, but without verification that it works as intended in nightlies, I will remove it prior to release. It won't be in the release then.

Refresh of nightly builds was requested, so please test when one becomes available.


The latest nightly is from April 27, 2022.
https://www.avidemux.org/nightly/

Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on April 30, 2022, 08:18:10 PM
Yes, there is nothing to test at the moment, but a refresh has been requested. It will happen when the maintainer has time to do it, and it would be great if you provide feedback once a new build is uploaded.

(If nothing gets uploaded for too long, I can provide upon request a private ZIP-packaged build — i.e. without installer, just extract and run — via WeTransfer, if you are fine with that.)
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 01, 2022, 04:02:36 PM
A fresh official MinGW build has been uploaded:

https://avidemux.org/nightly/win64/
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 02, 2022, 01:08:23 PM
Quote from: eumagga0x2a on May 01, 2022, 04:02:36 PMA fresh official MinGW build has been uploaded:

https://avidemux.org/nightly/win64/

Dear Eumagga!

I tested extensively the NVENC HEVC with the May 1st nightly version, and it worked well in much higher bitrates too.
 The only problem was when I set the "use B-frames as references" from middle to each. It resulted in errors. I  also noticed, when I selected MAIN10 to  activate 10 bit encoder, the result was only a 8bit file (according to mediainfo)

Can you implement the 10bit option too?


Thank you for your reply!
Best regards!

Bye!
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 02, 2022, 10:00:41 PM
Quote from: Videograbber on May 02, 2022, 01:08:23 PMI tested extensively the NVENC HEVC with the May 1st nightly version, and it worked well in much higher bitrates too.

Thanks, did you test with different (non-zero) values for the number of reference frames?

Quote from: Videograbber on May 02, 2022, 01:08:23 PMThe only problem was when I set the "use B-frames as references" from middle to each. It resulted in errors.

Please provide some details. Did encoder setup fail? Or did something happen later during the actual encoding process? In doubt please select a short span of a video, reproduce the error(s), close Avidemux and attach admlog.txt from %localappdata%\avidemux\ to your reply.

Quote from: Videograbber on May 02, 2022, 01:08:23 PMI also noticed, when I selected MAIN10 to  activate 10 bit encoder, the result was only a 8bit file (according to mediainfo)

Does your NVIDIA graphics card support 10-bit HEVC encoding? Even if it does, the input passed to encoder in Avidemux is always 8-bit, thus selecting the main10 profile doesn't bring any benefits. At best, it just wastes storage.

As libavcodec passes the bit depth of the input to hw encoder, I can imagine that the latter could override the specified profile if appropriate. In order to know for sure, it would be necessary to be able to pass 10-bit pictures to the encoder, which is currently impossible in Avidemux. Implementing support for passing high bit depth pictures from decoder through editor and the video filter chain would require massive changes when not a rewrite of a big part of the application.
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 03, 2022, 08:41:32 AM
"Did encoder setup fail? Or did something happen later during the actual encoding process? "

It encodes only the first beginning second of the video.



Encoding 8bit material in 10bit codec always increases the compression efficiency. Of course the original 8bit colors remain roughly the same quality, but the picture is cleaner at the same bitrate. Most transcoders offer 10bit encoding option in "MAIN 10" option. So if somebody select the MAIN10 option, than let it be really 10bit.
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 03, 2022, 06:39:25 PM
Quote from: Videograbber on May 03, 2022, 08:41:32 AMIt encodes only the first beginning second of the video.

Please reproduce this problem, close Avidemux and provide the resulting admlog.txt.

Quote from: Videograbber on May 03, 2022, 08:41:32 AMSo if somebody select the MAIN10 option, than let it be really 10bit.

I tried to explain why this may be impossible when feeding 8-bit pictures to the encoder, but please select main10 HEVC profile, encode a short video, close Avidemux and provide the resulting admlog.txt.
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 05, 2022, 11:49:51 AM
Quote from: eumagga0x2a on May 03, 2022, 06:39:25 PM
Quote from: Videograbber on May 03, 2022, 08:41:32 AMIt encodes only the first beginning second of the video.

Please reproduce this problem, close Avidemux and provide the resulting admlog.txt.

Quote from: Videograbber on May 03, 2022, 08:41:32 AMSo if somebody select the MAIN10 option, than let it be really 10bit.

I tried to explain why this may be impossible when feeding 8-bit pictures to the encoder, but please select main10 HEVC profile, encode a short video, close Avidemux and provide the resulting admlog.txt.

Hello Eumagga!

How can I create such admlog.txt?

Encoding 8 bit material with 10bit codecs increases the efficiency at the same bitrate, thus the quality. It is well proven by SSIM and PSNR tests and subjective visual examinations too. Thus it is no wonder that utmost all transcoder softwares which uses HW encoding also offer that option.
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 05, 2022, 06:02:22 PM
Quote from: Videograbber on May 05, 2022, 11:49:51 AMHow can I create such admlog.txt?

Avidemux creates this log file always when it runs (and overwrites the log file from the previous Avidemux session). I asked you to attach this log file to your reply once you have reproduced the error.
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 07, 2022, 04:02:26 PM
Quote from: eumagga0x2a on May 05, 2022, 06:02:22 PM
Quote from: Videograbber on May 05, 2022, 11:49:51 AMHow can I create such admlog.txt?

Avidemux creates this log file always when it runs (and overwrites the log file from the previous Avidemux session). I asked you to attach this log file to your reply once you have reproduced the error.

Where is the so-called admlog.txt exactly located?
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 07, 2022, 04:30:31 PM
Quote from: Videograbber on May 07, 2022, 04:02:26 PMWhere is the so-called admlog.txt exactly located?

Maybe my pretty precise description was confusing, but it is as it is:

Quote from: eumagga0x2a on May 02, 2022, 10:00:41 PMIn doubt please select a short span of a video, reproduce the error(s), close Avidemux and attach admlog.txt from %localappdata%\avidemux\ to your reply.

This means that you can either press the "Windows key" + R, paste the given location and press Return (or Enter) or paste this address into the location bar of Windows Explorer. "%localappdata% is an environment variable which Windows expands to whatever value this variable has on a particular system. In this sense, I already gave you the exact location.
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 08, 2022, 03:10:41 PM
Quote from: eumagga0x2a on May 07, 2022, 04:30:31 PM
Quote from: Videograbber on May 07, 2022, 04:02:26 PMWhere is the so-called admlog.txt exactly located?

Maybe my pretty precise description was confusing, but it is as it is:

Quote from: eumagga0x2a on May 02, 2022, 10:00:41 PMIn doubt please select a short span of a video, reproduce the error(s), close Avidemux and attach admlog.txt from %localappdata%\avidemux\ to your reply.

This means that you can either press the "Windows key" + R, paste the given location and press Return (or Enter) or paste this address into the location bar of Windows Explorer. "%localappdata% is an environment variable which Windows expands to whatever value this variable has on a particular system. In this sense, I already gave you the exact location.

Hello Eumagga!

Here is the admlog TXT file.
https://sendgb.com/JMRNHcIs30h

What is the reason of error, when I select the "use B-frames as references" option?
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 08, 2022, 04:01:54 PM
Thank you (providing the log as attachment to your reply would have been simpler for everyone, but it worked also the way you did it), the error was

[adm_lavLogCallback] 16:00:32-979 [lavc] Failed locking bitstream buffer: invalid param (8):
That was not what I expected to see, will need some time to understand it.

Was it with B-frame mode: each?

You maxed out lookahead, which was rejected by the driver and silently reduced to 28 — did you try to reduce it further to more moderate values?

For the future, it would help if you provide the project script (just the line specifying the video codec and its config) matching the configuration which resulted in particular admlog.txt.
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 08, 2022, 05:20:59 PM
Quote from: eumagga0x2a on May 08, 2022, 04:01:54 PMThank you (providing the log as attachment to your reply would have been simpler for everyone, but it worked also the way you did it), the error was

[adm_lavLogCallback] 16:00:32-979 [lavc] Failed locking bitstream buffer: invalid param (8):
That was not what I expected to see, will need some time to understand it.

Was it with B-frame mode: each?

You maxed out lookahead, which was rejected by the driver and silently reduced to 28 — did you try to reduce it further to more moderate values?

For the future, it would help if you provide the project script (just the line specifying the video codec and its config) matching the configuration which resulted in particular admlog.txt.

Yes, the B-rame mode was set to each.  In other NVENC HW -accelerated transcoders (like Staxrip or Hybrid)  I always use that  mode without problems.

In Avidemux you can not Max Lookahead, because the NVIDIA Card's real max number of Lookahead is 32 and not 31. (Staxrip and Hybrid use 32 as the max. lookahead without problems)

My NVENC-HEVC settings in pictures:

(https://i.ibb.co/w60fq1v/k-p.png)


(https://i.ibb.co/pXNvcky/k-p.png)
Title: Re: NVENC HEVC problems
Post by: Videograbber on May 13, 2022, 06:16:22 AM
Could you reconstruct the error on your machine too?
Title: Re: NVENC HEVC problems
Post by: eumagga0x2a on May 13, 2022, 09:05:54 AM
Yes, and many more since a few hours. Will need some time to sort issues found after graphics card switch.