Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ffmpeg h264 nvenc 2-pass-encoding - (how) is it possible?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
DawgG
l33t
l33t


Joined: 17 Sep 2003
Posts: 752

PostPosted: Sat Nov 18, 2017 5:27 pm    Post subject: ffmpeg h264 nvenc 2-pass-encoding - (how) is it possible? Reply with quote

i'm trying to encode movies on my nvdia-gpu with ffmpeg and h264_nvenc, but no matter what options i set, the output-file is always the same.
i'd like to do it with 2-pass encoding, which seems to be possible according to
Code:
ffmpeg -h encoder=h264_nvenc
and some scarce documentation i could find; eg http://www.ffmpeg-archive.org/nvenc-2pass-td4671618.html
probably i'm setting some options/parameters wrong.

this (supposed 2-pass- encoding)
Code:
ffmpeg -analyzeduration 20000000 -probesize 20000000 -i /home/ice/vids/makemkv/Bridge-of-Spies-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -an -sn -c:v h264_nvenc -pixel_format yuv444p -preset slow -b:v 4500k -f matroska -y -2pass 1 -pass 1  -y bos-enc-2p-v4500k.mkv

ffmpeg -analyzeduration 20000000  -probesize 20000000  -i /home/ice/vids/makemkv/Bridge-of-Spies-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v h264_nvenc -pixel_format yuv444p -preset slow -c:s copy -b:v 4500k -f matroska -2pass 1 -pass 2 -c:a:0 copy -c:a:1 copy -y bos-enc-2p-v4500k.mkv

creates:
Code:
ls -s bos-enc-2p-v4500k.mkv
6016000 bos-enc-2p-v4500k.mkv


and this:
Code:
ffmpeg -analyzeduration 20000000  -probesize 20000000  -i /home/ice/vids/makemkv/Bridge-of-Spies-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v h264_nvenc -pixel_format yuv444p -preset slow -c:s copy -b:v 4500k -f matroska  -c:a:0 copy -c:a:1 copy -y bos-enc-1p-v4500k.mkv

creates:
Code:

ls -s bos-enc-1p-v4500k.mkv
6016000 bos-enc-1p-v4500k.mkv


2-pass without a preset but with bitrate creates a different - but not by much - file:
Code:
ffmpeg -analyzeduration 20000000 -probesize 20000000 -i /home/ice/vids/makemkv/Bridge-of-Spies-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -an -sn -c:v h264_nvenc -pixel_format yuv444p  -b:v 4500k -f matroska -y -2pass 1 -pass 1  -y bos-enc-2p-v4500k-nopreset.mkv

ffmpeg -analyzeduration 20000000  -probesize 20000000  -i /home/ice/vids/makemkv/Bridge-of-Spies-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v h264_nvenc -pixel_format yuv444p -c:s copy -b:v 4500k -f matroska -2pass 1 -pass 2 -c:a:0 copy -c:a:1 copy -y bos-enc-2p-v4500k-nopreset.mkv


Code:
ls -s bos-enc-2p-v4500k-nopreset.mkv
6023624 bos-enc-2p-v4500k-nopreset.mkv

also, when i start 2pass, an empty ffmpeg2pass-0.log is created. in the 2-pass command i tried using /dev/null as output instead of a filename for first pass, but the resulting file was the same.

does anybody know what's going on here or how to set all the params for nvenc correctly?
THX for your input!
_________________
DUMM KLICKT GUT.
Back to top
View user's profile Send private message
Ralphred
n00b
n00b


Joined: 31 Dec 2013
Posts: 19

PostPosted: Wed Nov 22, 2017 7:00 pm    Post subject: Reply with quote

The help file reads, to me anyway, that by setting
Code:
-preset slow
you have already implied -2pass.
Run two single passes manually, omitting -2pass and -pass switches, but switching -preset between slow and medium, and compare those (including runtime). If it's not handling the 2 pass process internally then the files should be practically identical.

The nvenc has some nice options, and if this doesn't pan out I'd just use -rc-lookahead 50, we're not dealing with live streams that need to be low latency, which would normally be what stops me using similar settings.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 5954
Location: Saint Amant, Acadiana

PostPosted: Wed Nov 22, 2017 7:16 pm    Post subject: Reply with quote

2-pass was beneficial when one had to squeeze the video to a CD, not exceeding 700 MB. What advantage has 2-pass nowadays when NAS and such are used to store videos?
_________________
Please learn how to denote units correctly!

Political Correctness is all about replacing imaginary injustice with real injustice.
Back to top
View user's profile Send private message
DawgG
l33t
l33t


Joined: 17 Sep 2003
Posts: 752

PostPosted: Thu Nov 30, 2017 2:44 pm    Post subject: Reply with quote

sorry for taking so long to answer, i had some work to do.

i want to use this for encoding blurays to mkv; filesize is not (much of) an issue, i want good quality but not files of 20GB size. with dvds cpu-encoding (
Code:
ffmpeg -c:v libx264 -preset veryslow -tune film
) is great, but for blurays my cpu is too slow/old (and the speed of nvenc/nvidia-gpu is tempting)

i tried many different combinations off ffmpeg-nvenc-options, but they were ignored or w/out effect.

compare this (preset slow):
Code:
time ffmpeg -analyzeduration 20000000  -probesize 20000000 -i st-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 -c:v h264_nvenc -pixel_format yuv444p  -preset slow -c:s copy -c:a:0 copy -c:a:1 copy -c:a:2 copy st-enc-preset-slow.mkv
frame=176036 fps=198 q=15.0 Lsize= 3505550kB time=02:02:22.14 bitrate=3911.3kbits/s speed=8.25x   
video:1690290kB audio:1720822kB subtitle:88152kB other streams:0kB global headers:0kB muxing overhead: 0.179609%

real    14m53,263s
user    52m25,681s
sys     0m18,526s


to this (preset fast):
Code:
time ffmpeg -analyzeduration 20000000  -probesize 20000000 -i st-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 -c:v h264_nvenc -pixel_format yuv444p  -preset fast -c:s copy -c:a:0 copy -c:a:1 copy -c:a:2 copy st-enc-preset-fast.mkv
video:1698333kB audio:1720822kB subtitle:88152kB other streams:0kB global headers:0kB muxing overhead: 0.179199%

real    14m34,529s
user    52m17,582s
sys     0m18,687s


same with numeric presets (some params require numeric args and some do not);
preset 1
Code:
time ffmpeg -analyzeduration 20000000  -probesize 20000000 -i st-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 -c:v h264_nvenc -pixel_format yuv444p  -preset 1 -c:s copy -c:a:0 copy -c:a:1 copy -c:a:2 copy st-enc-preset-1.mkv
video:1690290kB audio:1720822kB subtitle:88152kB other streams:0kB global headers:0kB muxing overhead: 0.179609%

real    14m36,837s
user    52m22,617s
sys     0m18,817s


preset 3
Code:
time ffmpeg -analyzeduration 20000000  -probesize 20000000 -i st-raw.mkv -vf "crop=1920:800:0:140" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 -c:v h264_nvenc -pixel_format yuv444p  -preset 3 -c:s copy -c:a:0 copy -c:a:1 copy -c:a:2 copy st-enc-preset-3.mkv
video:1698333kB audio:1720822kB subtitle:88152kB other streams:0kB global headers:0kB muxing overhead: 0.179199%

real    14m28,957s
user    52m12,574s
sys     0m18,812s


the resulting files:
Code:
ls -s st-enc-preset-*
3505552 st-enc-preset-1.mkv
3505552 st-enc-preset-slow.mkv

3513596 st-enc-preset-3.mkv
3513596 st-enc-preset-fast.mkv

not much difference and NO sign of two-pass, either.

from
Code:
ffmpeg -h encoder=h264_nvenc
h264_nvenc AVOptions:
  -preset            <int>        E..V.... Set the encoding preset (from 0 to 11) (default medium)
     default                      E..V....
     slow                         E..V.... hq 2 passes
     medium                       E..V.... hq 1 pass
     fast                         E..V.... hp 1 pass
 (...)


so (how) can the options be passed to nvenc? there must be many, but this remains totally opaque...
_________________
DUMM KLICKT GUT.
Back to top
View user's profile Send private message
Ralphred
n00b
n00b


Joined: 31 Dec 2013
Posts: 19

PostPosted: Sat Dec 09, 2017 4:57 am    Post subject: Reply with quote

Meh, you ran fast and not medium
Quote:
Code:
ffmpeg -h encoder=h264_nvenc
h264_nvenc AVOptions:
  -preset            <int>        E..V.... Set the encoding preset (from 0 to 11) (default medium)
     default                      E..V....
     slow                         E..V.... hq 2 passes
     medium                       E..V.... hq 1 pass
     fast                         E..V.... hp 1 pass
 (...)
I wanted to see the output when the only difference should be 1 or 2 passes, I dunno what other differences there will be between "hq" and "hp" with the lack of documentation we are dealing with.
I want to ask as well, what is the finished product like to watch, any artefacts on fast moving sections/panning shots in the film (car chases are great for this kind of evaluation).

I'll go into my thinking a bit, does the card have the ability to run two threads at once without affecting the other? If we had a dual core machine (like proper dual core, none of this HT nonsense) we could manually run a two pass in one go by starting the 1st pass 20 seconds before the 2nd, and dumping the pass log file to a fifo buffer no? If you have the ability to do this all inside your card, why bother developing/documenting options to export the file to be used for a 2nd pass, how far in front does the data in your fifo really need to be?
This is where my suggestion about the lookahead came from, if the encoder is looking 2 seconds ahead of the current encoding frame to pass tips back regarding needed changes in bit rate to maintain size/quality, how different is that really to a traditional 2 pass encode?
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 5954
Location: Saint Amant, Acadiana

PostPosted: Sat Dec 09, 2017 12:49 pm    Post subject: Reply with quote

Two-pass does not produce smaller files, it merely allows to predict the file size. Use the quality factor to adjust average bitrate and file size. Even better, use H.265 instead. You may want to use something with GUI, like Handbrake or Avidemux to learn about setting parameters.
_________________
Please learn how to denote units correctly!

Political Correctness is all about replacing imaginary injustice with real injustice.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum