Jump to content

Conversions - FFMPEG and NVENC - Missing bitrate parameter ?


Recommended Posts

Posted

Hi all,

I was trying to master the conversion capabilities of Emby to get a mobile friendly version of my 4K remuxes but it seems that, (on my server at least), any configuration I enter ends up with the same output file : a 3 mbps hevc file.

 

The problem

To give some more background, I'm on unraid, with an nvidia Turing chip that deals with all the transcoding stuff. So, hevc_nvenc is doing all the job here. My ideal output file would be between 4 to 8 mbps hevc file. Currently, despite having tried lots of configuration and different movies, I always end up with a roughly 3 mbps output file (see image attached).

In the logs, I do see the configuration I entered in the gui. In my last trial, I asked for a 30 mbps hevc/aac (from a 64mbps 4K remux)...

-c:v:0 hevc_nvenc -g:v:0 144 -maxrate:v:0 29616000 -bufsize:v:0 59232000 -keyint_min:v:0 144 -r:v:0 24

... which seems to be ignored by the nvidia encoder.

 

A possible solution

I did some research on the web and it seems that the nvidia encoder sets the default bitrate very low if not specified in the encoder parameters (-b:v). Furthermore, it needs dedicated parameters to better control the output which I do not see in the transcoding logs.

The following is working great (for me at least but it's a very common set of parameters) for a constant quality in VBR rate control :

-c:v:0 hevc_nvenc -b:v 0 -maxrate:v 6M -bufsize:v 8M \
-cq:v 24 -rc:v vbr_hq -rc-lookahead:v 32 \
 
-bf:v 3 -coder:v cabac -b_ref_mode:v middle \
-- or --
-spatial_aq:v 1 -aq-strength:v 15 -coder:v cabac \

-cq:v 24 being the "CRF qualify" that the user want to reach. Putting the desired bitrate in auto mode (-b:v 0) seems to be recommended in this mode. The last two lines cannot be used together : the first is for b-frame which is only possible on Turing chips and above, while the second is used to raise quality up.

For a more controlable bitrate, one can specify a target bitrate :

-c:v:0 hevc_nvenc -b:v 4M -maxrate:v 6M -bufsize:v 8M \
-rc:v vbr_hq -rc-lookahead:v 32 \

 

The runs

I ran those two versions and this is what I got a 3,7 and 4,4 Mbits video output :) 

 

12:05:49.344 12:05:49.375 elapsed=00:21:02.66 frame=172957 fps=137 q=17.0 Lsize= 3318717kB time=02:00:01.25 bitrate=3775.3kbits/s dup=118 drop=0 throttle=off speed= 5.7x
12:05:49.375 video:2976138kB audio:338270kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.129984%
 
14:52:08.675 14:52:08.704 elapsed=00:21:00.98 frame=172957 fps=137 q=14.0 Lsize= 3926368kB time=02:00:01.25 bitrate=4466.6kbits/s dup=118 drop=0 throttle=off speed=5.71x
14:52:08.704 video:3583790kB audio:338270kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.109845%

 

My Question

Is it possible on 4.7.5 to add those parameters myself and still benefit from the conversion tool ?
At least, if I could add the -b:v flag I think that could help a lot... I'm not sure if the Parameter Adjustment  from the Diagnostic Options would work here ?
The best solution would be of course to update Emby and add something that would allow to add those parameters but that's the least of your priority :D 

 

Some references that help me along the way :

parameters discussion : https://superuser.com/questions/1296374/best-settings-for-ffmpeg-with-nvenc

b-frame subject: https://superuser.com/questions/1630601/why-using-b-frames-does-not-reduce-the-size-of-my-video-using-ffmpeg-and-nvenc

 

Thanks

Capture d’écran 2022-07-26 à 10.45.55.png

Posted

Hi there, can you please provide a complete ffmpeg log example ? Thanks !

Posted (edited)

Hi @Luke,

Thanks for stepping in.

Logs attached

  • Original KO = Missing -b:v flag while converting
  • Custom Command OK = Using Diagnostic Options, a first tentative to add that flag and a couple more during conversion... WIP.
  • Transcoding = Example (same movie, target bitrate) of a live transcoding. -b:v flag is present in the encoder's parameters.

 

Some additional questions for you and your team if you have the time :

  1. Why the transcoding log level is always set to verbose ? Even If Info is shown as default in the list, even if I reset it to Info in the GUI, it always fallback immediately to Verbose like nothing was saved at all. Even uninstalling/reinstalling the plugin and restarting emby does not change anything. Can I force it in an xml config file or some other way ?
  2. What are those Skipping NAL unit 63 messages while transcoding ? Should I worry ?
  3. When converting a movie, the first time the process is ran, the input file is obviously the main mkv. If I want another version, it uses the output from the first run as input for the second, even if the main mkv is selected in the gui. Any idea why this behavior occurs ?

 

Thanks  for looking into it !

Original KO - ffmpeg-transcode-864288a8-c8e1-4a17-b88e-d31ffe1fad8a_1.txt Custom Command OK - ffmpeg-transcode-c24d0856-e8e7-4c1d-920f-9a3b88a1e00f_1.txt Transcoding - ffmpeg-transcode-f23bb189-ecac-48aa-b0e7-59bb3463560b_1.txt

Edited by nSGecko
Typos
Posted

They might be a little too verbose but we parse the log data for realtime info display in Emby Server, , so most of it we need. 

Skipping nal unit - probably nothing to worry about. It generally indicates something that ffmpeg does not yet know how to decode.

Quote
  1. When converting a movie, the first time the process is ran, the input file is obviously the main mkv. If I want another version, it uses the output from the first run as input for the second, even if the main mkv is selected in the gui. Any idea why this behavior occurs ?

I'm having a hard time visualizing. Can we please look at a specific example ?Thanks.

Posted

Thanks for your reply.

Indeed, I'm able to activate the full trace log level, but Info automatically goes back to Verbose.

 

12 hours ago, Luke said:

I'm having a hard time visualizing. Can we please look at a specific example ?Thanks.

Ok, let's say I have 4 versions of a movie and I want a fifth. I select the version I want as input : Blu-ray, which is my full Blu-ray version (see image attached). Then I launch the conversion process and in the logs, I discover that it took another version to work with :

/bin/ffmpeg -loglevel +timing -y -print_graphs_file "/config/logs/ffmpeg-transcode-dd0f8a90-0237-4f02-aaed-43a222112c70_1graph.txt" -copyts -start_at_zero -f mp4 -c:v:0 hevc -hwaccel:v:0 cuda -hwaccel_device:v:0 0 -hwaccel_output_format:v:0 cuda -i "/media/movie/Kaamelott The First Chapter (2021)/Kaamelott The First Chapter (2021) - Rip.mp4" -map 0:0 -map 0:1 -sn -c:v:0 h264_nvenc -b:v:0 7615475 -g:v:0 144 -maxrate:v:0 7615475 -bufsize:v:0 15230950 -keyint_min:v:0 144 -r:v:0 24 -profile:v:0 high -c:a:0 copy -metadata:s:a:0 language=fre -disposition:a:0 default -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 "/ram/73/127/dd0f8a90-0237-4f02-aaed-43a222112c70.mkv"

Is that done on purpose ?

 

btw, using the h264 as the output codec, I just found out that the -b-v flag is added as parameter ;)

 

Capture d’écran 2022-07-28 à 09.37.00.png

Posted
12 hours ago, nSGecko said:

Thanks for your reply.

Indeed, I'm able to activate the full trace log level, but Info automatically goes back to Verbose.

 

Ok, let's say I have 4 versions of a movie and I want a fifth. I select the version I want as input : Blu-ray, which is my full Blu-ray version (see image attached). Then I launch the conversion process and in the logs, I discover that it took another version to work with :

/bin/ffmpeg -loglevel +timing -y -print_graphs_file "/config/logs/ffmpeg-transcode-dd0f8a90-0237-4f02-aaed-43a222112c70_1graph.txt" -copyts -start_at_zero -f mp4 -c:v:0 hevc -hwaccel:v:0 cuda -hwaccel_device:v:0 0 -hwaccel_output_format:v:0 cuda -i "/media/movie/Kaamelott The First Chapter (2021)/Kaamelott The First Chapter (2021) - Rip.mp4" -map 0:0 -map 0:1 -sn -c:v:0 h264_nvenc -b:v:0 7615475 -g:v:0 144 -maxrate:v:0 7615475 -bufsize:v:0 15230950 -keyint_min:v:0 144 -r:v:0 24 -profile:v:0 high -c:a:0 copy -metadata:s:a:0 language=fre -disposition:a:0 default -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 "/ram/73/127/dd0f8a90-0237-4f02-aaed-43a222112c70.mkv"

Is that done on purpose ?

 

btw, using the h264 as the output codec, I just found out that the -b-v flag is added as parameter ;)

 

Capture d’écran 2022-07-28 à 09.37.00.png

OK we'll take a look at this. Thanks for reporting.

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
×
×
  • Create New...