[FFmpeg-user] 2 pass encoding with hevc_nvenc
Sven C. Dack
sven.c.dack at sky.com
Sun Sep 4 13:18:16 EEST 2016
On 04/09/16 09:56, Marco Diletti wrote:
> Hello,
>
> i am trying to encode with a variable bitrate, 2 pass encoding, using
> the codec
> hevc_nvenv.
>
> ffmpeg -i infile.mkv -vcodec hevc_nvenc -preset slow -qmin 1 -qmax 50
> -b:v 4000k -c:a copy -f matroska outfile.mkv
>
> Theorically it shoulds use 2 pass encode, and it encodes with half
> speed respect to preset medium.
>
> My doubt is that ffmpeg do not iterate the encoding two times creating
> a logfile.
> ##SELECTION_END##
> If i use the option -pass 1, it creates a empty logfile.
>
> How 2 pass encoding of nvenc works ? Someone know the exact or the best
> command
> syntax in order to do it ?
>
> Sorry for the bad english. Thanks for your attention.
I don't think Nvidia supports true two-pass encoding with NVENC - and/or it
might be a bug. I do get an empty ffmpeg2pass-0.log, too.
NVENC does have a "vbr_2pass" in its options, but what it means is that it will
look ahead a number of frames for the rate control to make better decisions.
True two-pass encoding means to do two full passes over the data. Although what
NVENC does improves the quality is this far from the real thing. The naming of
the options is confusing and misleading...
If you have the latest ffmpeg version then there is now also an option
"-rc-lookahead <int>" where one can specify the exact number of frames NVENC
will look ahead. Here is an example command line:
$ ffmpeg -i in.avi -b:v 800k -qmin:v 10.0 -preset:v slow -profile:v main -rc:v
vbr_2pass -rc-lookahead:v 32 -c:v hevc_nvenc -f matroska -y out.mkv
The current maximum for the look-ahead is 32 frames.
By the way, I am seeing the same empty ffmpeg2pass-0.log file with libx265, too,
now. With libx264 is two-pass encoding working as intended:
$ ffmpeg -i in.avi -c:v libx264 -pass 1 -b:v 1000k -an -t 0:10 -f rawvideo -y
/dev/null
This produces two files "ffmpeg2pass-0.log" and "ffmpeg2pass-0.log.mbtree".
$ ffmpeg -i in.avi -c:v libx264 -pass 2 -b:v 1000k -t 0:10 -y out.mkv
This gives me a working video.
Doing the same with libx265 results in a single and empty file of
"ffmpeg2pass-0.log". libx265 however seems to be happy to take the pass logfile
from libx264 and produces a different output when compared to using an empty
pass logfile. NVENC seems unimpressed by either empty pass logfile or the ones
produced by libx264.
Sven
ffmpeg version N-81508-g99882d0 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.2.0 (GCC)
configuration: --prefix=/home/sven/av --enable-gpl --enable-version3
--enable-nonfree --arch=x86_64 --cpu=native --disable-debug --disable-shared
--enable-static --enable-libvorbis --enable-libopus --enable-libx264
--enable-libx265 --enable-opengl --enable-opencl --enable-vaapi --enable-vdpau
--enable-cuda --enable-cuvid --enable-nvenc --enable-libnpp
--extra-cflags='-I/home/sven/av/include -I/usr/local/cuda/include
-I/usr/local/Video_Codec_SDK_7.0.1/Samples/common/inc'
--extra-ldflags='-L/home/sven/av/lib -L/usr/local/cuda/lib64' --ar=gcc-ar
--nm=gcc-nm --ranlib=true
libavutil 55. 29.100 / 55. 29.100
libavcodec 57. 54.101 / 57. 54.101
libavformat 57. 48.101 / 57. 48.101
libavdevice 57. 0.102 / 57. 0.102
libavfilter 6. 58.100 / 6. 58.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
More information about the ffmpeg-user
mailing list