Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
cybermind

prboom+ -viddump GPU hardware encoding

Recommended Posts

Hi there, haven't found if somebody did that already before me.

I've managed to use NVIDIA hardware encoding for -viddump command. Hope this guide will be helpful to somebody.

Here is how:

(0). Ensure that your prboom+ configuration is able to run -viddump command properly (download oggenc2, mkvmerge etc)
1. Download latest ffmpeg here: https://www.ffmpeg.org
2. Place ffmpeg.exe to prboom+ directory.
3. Open your gl(pr)boom-plus.cfg configuration file.
4. Modify cap_videocommand line to this:

cap_videocommand          "ffmpeg -y -an  -f rawvideo -pixel_format rgb24 -video_size %wx%h -framerate %r -i - -c:v h264_nvenc -preset llhp -rc:v cbr -cq:v 16 -bf:v 3 -b:v 6M -maxrate:v 8M -profile:v main -bufsize:v 8M output.mp4"

(4.1). Customize it to your needs (e.g. change encoder to hevc_nvenc, increase bitrate, I'm not a big expert in ffmpeg encoding commands)

5. Save it.
6. Run your demo file: gl(pr)boom-plus.exe -viddump test.mp4 -timedemo demo.lmp

On my notebook (Asus TUF Gaming FX505DT, Ryzen 5 3550H, NVIDIA GTX 1650) hardware encoding takes more than 2 times less time compared to CPU encoding with x264.exe

Tested with glboom-plus.exe -timedemo lv23-208.lmp, 60 fps, 1280x720: GPU - 73.3 fps, CPU - 31.3 fps.

Share this post


Link to post

I'm curious if it works with AMD graphics. What to write in the codec setting instead of "-c:v h264_nvenc" ?

Share this post


Link to post

I have tried exactly your settings and even placed an ffmpeg.exe file in combination with its "requires" .dll files. However, I cannot export a file in this case. The only thing that happens here is that the demo is being played extremely fast as you can hear its music and sound effects syncing with it. Do you have a solution for that issue?

Share this post


Link to post
On 1/5/2020 at 10:29 PM, cybermind said:

Hi there, haven't found if somebody did that already before me.

I've managed to use NVIDIA hardware encoding for -viddump command. Hope this guide will be helpful to somebody.

Here is how:

(0). Ensure that your prboom+ configuration is able to run -viddump command properly (download oggenc2, mkvmerge etc)
1. Download latest ffmpeg here: https://www.ffmpeg.org
2. Place ffmpeg.exe to prboom+ directory.
3. Open your gl(pr)boom-plus.cfg configuration file.
4. Modify cap_videocommand line to this:


cap_videocommand          "ffmpeg -y -an  -f rawvideo -pixel_format rgb24 -video_size %wx%h -framerate %r -i - -c:v h264_nvenc -preset llhp -rc:v cbr -cq:v 16 -bf:v 3 -b:v 6M -maxrate:v 8M -profile:v main -bufsize:v 8M output.mp4"

(4.1). Customize it to your needs (e.g. change encoder to hevc_nvenc, increase bitrate, I'm not a big expert in ffmpeg encoding commands)

5. Save it.
6. Run your demo file: gl(pr)boom-plus.exe -viddump test.mp4 -timedemo demo.lmp

On my notebook (Asus TUF Gaming FX505DT, Ryzen 5 3550H, NVIDIA GTX 1650) hardware encoding takes more than 2 times less time compared to CPU encoding with x264.exe

Tested with glboom-plus.exe -timedemo lv23-208.lmp, 60 fps, 1280x720: GPU - 73.3 fps, CPU - 31.3 fps.

I've been using NVIDIA hardware encoding with FFMPEG as well.

cap_videocommand          "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %wx%h -r %r -i pipe:0 -g 480 -c:v hevc_nvenc -preset 1 -level:v 153 -rc:v 32 -rc-lookahead 30 -no-scenecut 1 -cq 28 output.mp4"

Here's the breakdown of the options I used.

-g 480:  Modified key-frame interval.  1 key frame every 8 seconds.

-preset 1:  slow. Although I can probably use the default of 2.

-level:v 153:  Constrains the encoder to not exceed certain values. Level 5.1 is the minimum required for 3840x2160@60fps.  The default main tier constrains the maximum bit-rate to 40M

-rc:v 32:  vbr_hq. Probably not needed and may make the encoder take slightly longer.  Doesn't affect speed at all when using PrBoom software renderer in 4k.

-rc-lookahead 30:  Causes the encoder to build a 1/2 second frame buffer to help smooth out bit-rate spikes. You may notice when starting a demo that it plays super fast for a few frames before slowing down for the rest of the run.

-no-scenecut 1:  When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false).  'Nuff said.

-cq 28:  Constant Quality Mode. The most important factor in determining overall quality.  Keeps the bit-rate somewhat constant while dynamically adjusting the Constant quantization parameter or -qp.  Setting -qp 28 would keep CQ constant while dynamically adjusting the bit-rate.  For streaming it's better to have smooth bit-rate. YouTube will re-encode whatever you feed it anyway, but I like to stream my videos from my private server as well.

 

You'll find I don't specify any kind of bit-rate. Constant Quality mode uses a lot of complex math to determine bit-rate.

 

The resulting output file will have a bit-rate of between 28M and 32M on average.  A one minute long test file came out to about 25MB. These are perfect for uploading to YouTube.  This gives the "YouTube compression algorithm" an excellent starting point to trans-code into a number of picture sizes and formats.  The most common format is VP9.  A 4k file will force YouTube to use VP9 by default and trans-code to about 27M. Eventually AV1 will replace VP9 when hardware decoders become more common.  AV1 promises even better bandwidth savings when it comes to ultra high definition.

 

Also, hevc_nvenc only works with GeForce 900 series or newer.  Playing a 4K HEVC file in VLC or MPC may cause it to appear corrupted or play out of sync.  It does for me on my laptop anyway.  It plays perfectly fine on my desktop.

 

A test encode in glboom-plus at 3840x2160 results in about 38 fps.  In prboom-plus with its advanced pixel smoothing filter maxed out results in about 3 fps.

 

For anyone interested I have made a scripted workflow to get consistent results.

DemoConversion.7z

Edited by L0l1nd3r : A note about youtube reencoding.

Share this post


Link to post
On 12/5/2020 at 10:15 AM, CrazyDoomguy said:

Where is ffmpeg.exe? Cant find in download file

You can start at ffmpeg.org. Current builds for windows can be found at https://www.gyan.dev/ffmpeg/builds/

Scroll down to the release section to find the current builds. I reccomend ffmpeg-release-essentials.7z.  Extract ffmpeg.exe into your prboom directory.

Share this post


Link to post
On 6/15/2020 at 10:22 AM, Dimon12321 said:

I'm curious if it works with AMD graphics. What to write in the codec setting instead of "-c:v h264_nvenc" ?

"-h encoder=h264" will describe all the possible encoders for the H.264 codec. For AMD, you'll want h264_amf

Share this post


Link to post

@chungy, wow! Thank you very much. Now, -viddump works at 55 fps instead of laggy 10-13.

I faced a different problem now. I want to upscale my video to 2160p to make YT compress it at higher bitrate than for 1080p.

What's wrong with this? 

Spoiler

 

GLBoom's config for encoding looks like this:

cap_videocommand          "ffmpeg -f rawvideo -pix_fmt rgb24 -r %r -s %wx%h -i - -c:v h264_amf -b:v 75M -y temp_v.nut"

 

image.png.6e999f4e23c388024f2c55544638b31c.png

 

Thanks!

UPD: looks like upscaling doesn't work using h264_amf at all. XMedia Recode just crashes if I try to process a video using H.264 AMD AMF as codec

Edited by Dimon12321

Share this post


Link to post
On 1/23/2021 at 4:07 AM, Dimon12321 said:

@chungy, wow! Thank you very much. Now, -viddump works at 55 fps instead of laggy 10-13.

I faced a different problem now. I want to upscale my video to 2160p to make YT compress it at higher bitrate than for 1080p.

What's wrong with this? 

  Reveal hidden contents

 

GLBoom's config for encoding looks like this:

cap_videocommand          "ffmpeg -f rawvideo -pix_fmt rgb24 -r %r -s %wx%h -i - -c:v h264_amf -b:v 75M -y temp_v.nut"

 

image.png.6e999f4e23c388024f2c55544638b31c.png

 

Thanks!

UPD: looks like upscaling doesn't work using h264_amf at all. XMedia Recode just crashes if I try to process a video using H.264 AMD AMF as codec

You do not want to upscale with ffmpeg at all actually. That's a waste of time. Check your video driver control panel for AMD Virtual Super Resolution or VSR. The NVIDIA equivalent is Dynamic Super Resolution. You'll want to enable 4k or 3840x2160 through there. Next pass this command through either prboom or glboom.

glboom-plus.exe -geom 3840x2160f -timedemo demoFile.lmp -viddump demoFile.mp4

I also recommend using hevc_amf if your GPU has an HEVC encoder. HEVC is AMD's h265 encoder and far more optimized for 4k. I think this line of code should work:

Copy and paste into the cap_videocommand line.

cap_videocommand "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %wx%h -r %r -i pipe:0 -b:v 28M -minrate:v 14M -maxrate:v 40M -c:v hevc_amf -quality 0 -rc:v cbr output.mp4"

If HEVC doesn't work you'll have to use h264.

cap_videocommand "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %wx%h -r %r -i pipe:0 -b:v 56M -minrate:v 28M -maxrate:v 80M -c:v h264_amf -profile high -quality 2 -rc:v cbr -coder:v cabac output.mp4

An average rate of 30M is more than enough to give YouTube the data it needs to trans-code to VP9. This also gives you a smaller file to upload. H264 requires twice the bitrate to look just as good, the downside is a bigger file.

The quality settings are set to their best.

Depending on your hardware, such a file may not appear to play properly. This is normal. Happens to me on my laptop, not on my desktop. HEVC is way more demanding than h264. An h264 file will play on just about anything.

If you use prboom-plus, expect a slideshow. The output will still be buttery smooth.

 

If you don't see any output files check the video_stderr.txt file. It should list any errors encountered by the encoder. Else you'll see a long list of encoder information.

I don't have any AMD hardware so I can't help anymore than this. Good luck and happy encoding.

Share this post


Link to post

@L0l1nd3r, thank you very much. I tried both encoders with different parameters, but none of them work.

HEVC just refuses to work, even if I don't specify any parameters at all (just input, lib, output). I copied the command you provided and here is the out of video_stderr:

Spoiler

  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, rawvideo, from 'pipe:0':
  Duration: N/A, start: 0.000000, bitrate: 5308416 kb/s
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 2560x1440, 5308416 kb/s, 60 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_amf))
[hevc_amf @ 00000000004a54c0] CreateComponent(AMFVideoEncoderHW_HEVC) failed with error 10
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

h264_amf won't work if I try to process a video which resolution is higher than 1080p. My GPU is Radeon R9 270.

Spoiler

Input #0, rawvideo, from 'pipe:0':
  Duration: N/A, start: 0.000000, bitrate: 5308416 kb/s
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 2560x1440, 5308416 kb/s, 60 tbr, 60 tbn, 60 tbc
Please use -profile:a or -profile:v, -profile is ambiguous
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_amf))
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (h264_amf) (avc1 / 0x31637661), yuv420p, 2560x1440, q=-1--1, 56000 kb/s, 60 fps, 15360 tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.54.100 h264_amf
[h264_amf @ 0000000000565b80] SubmitInput() failed with error 29
Video encoding failed
Conversion failed!

 

The best I can do is record a 1440p video if I turn on AMD VSR, set 1440p, and -viddump a video using libx264.

Edited by Dimon12321

Share this post


Link to post

@Dimon12321, yep, those errors can be a little cryptic. Took me a while to even get hevc_nvenc working. Some parameters just aren't compatible with the encoder hardware. Search around, I'm sure you'll find an answer. There's no end of examples.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×