Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-26 Thread Ali KIZIL
Philip Langdale philipl at overt.org writes:

 
 On Wed, 25 Mar 2015 21:52:54 + (UTC)
 Ali KIZIL alikizil at gmail.com wrote:
 
  
  The update broken the general usage:
  
  ./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc -preset
  hp -fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k
  -bufsize 48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -
pix_fmt
  yuv420p - acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k
  -flush_packets 0 - packetsize 188 -y -f mpegts out.ts
  
  ./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc_h265 -
  preset hp -fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k 
-
  bufsize 48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -pix_fmt 
  yuv420p -acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k
  -flush_packets 0 -packetsize 188 -y -f mpegts out.ts
  
  FFmpeg stucks, does not work for both. 
  
  Before with nvenc work working fine with above commands. It looks
  like - g parameter, -muxrate, -flush_packtes stuck FFmpeg with this
  update. 
  
  Below line works:
  
  ./ffmpeg -loglevel verbose -i /root/bunny.mp4 -vcodec nvenc_h265
  -preset hp -r 50  -y -f mpegts out.ts
 
 Yes - it's because I tried to share the class instance between the two
 encoders, which doesn't work. I'm about to push a fix. Thanks for the
 heads up.
 
 --phil
 

It works fine now Phil. One more comment:

I have a GTX 980. It can encode upto 30-33 fps for 4K 60fps YUV Raw 
input file using nvenc_h265 avcodec with FFmpeg. First a side, It looked 
to me like lack of performance of card. However; after I split the video 
with crop filter into 2:

/opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i 
/Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v 
crop=in_w:in_h/2:0:0 -r 50 -g 50 -preset hp -f hevc top.hevc

/opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i 
/Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v 
crop=in_w:in_h/2:0:in_h/2 -r 50 -g 50 -preset hp -f hevc bottom.hevc

When I run them at the same time, both can be encoded with 50 fps. I 
tried to joing output files with padding but FFmpeg needs re-encoding 
and it makes no sense.

Do you have any comment or idea to use full performance of the card over 
a single ffmpeg nvenc_h265 instance ?

Additional note: GTX cards can suport up to 2 HEVC encoding at the same 
time (as limitation.). 



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-26 Thread Philip Langdale

On 2015-03-26 04:30, Ali KIZIL wrote:


It works fine now Phil. One more comment:

I have a GTX 980. It can encode upto 30-33 fps for 4K 60fps YUV Raw
input file using nvenc_h265 avcodec with FFmpeg. First a side, It 
looked
to me like lack of performance of card. However; after I split the 
video

with crop filter into 2:

/opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i
/Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v
crop=in_w:in_h/2:0:0 -r 50 -g 50 -preset hp -f hevc top.hevc

/opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i
/Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v
crop=in_w:in_h/2:0:in_h/2 -r 50 -g 50 -preset hp -f hevc bottom.hevc

When I run them at the same time, both can be encoded with 50 fps. I
tried to joing output files with padding but FFmpeg needs re-encoding
and it makes no sense.

Do you have any comment or idea to use full performance of the card 
over

a single ffmpeg nvenc_h265 instance ?

Additional note: GTX cards can suport up to 2 HEVC encoding at the same
time (as limitation.).


I honestly don't know. The hardware performance may not scale linearly 
with
frame size, so you might see a disproportionate slowdown past a certain 
size,

perhaps reflecting the need to use multiple buffers, etc.

Do you see any evidence that you're CPU bound? That might happen if our 
buffer

management is too inefficient, but I'd be surprised.

--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-26 Thread Ali KIZIL
Philip Langdale philipl at overt.org writes:

 
 On 2015-03-26 04:30, Ali KIZIL wrote:
  
  It works fine now Phil. One more comment:
  
  I have a GTX 980. It can encode upto 30-33 fps for 4K 60fps YUV Raw
  input file using nvenc_h265 avcodec with FFmpeg. First a side, It 
  looked
  to me like lack of performance of card. However; after I split the 
  video
  with crop filter into 2:
  
  /opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i
  /Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v
  crop=in_w:in_h/2:0:0 -r 50 -g 50 -preset hp -f hevc top.hevc
  
  /opt/ffmpeghw/bin/ffmpeg -video_size 3840x2160 -framerate 50 -i
  /Projects/YUV/soccer.yuv -vcodec nvenc_h265 -an -filter:v
  crop=in_w:in_h/2:0:in_h/2 -r 50 -g 50 -preset hp -f hevc 
bottom.hevc
  
  When I run them at the same time, both can be encoded with 50 fps. I
  tried to joing output files with padding but FFmpeg needs re-
encoding
  and it makes no sense.
  
  Do you have any comment or idea to use full performance of the card 
  over
  a single ffmpeg nvenc_h265 instance ?
  
  Additional note: GTX cards can suport up to 2 HEVC encoding at the 
same
  time (as limitation.).
 
 I honestly don't know. The hardware performance may not scale linearly 
 with
 frame size, so you might see a disproportionate slowdown past a 
certain 
 size,
 perhaps reflecting the need to use multiple buffers, etc.
 
 Do you see any evidence that you're CPU bound? That might happen if 
our 
 buffer
 management is too inefficient, but I'd be surprised.
 
 --phil
 

CPU is fine. I have 2 x Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz on 
server and Mem Total 49413456 kB, MemFree: 32030320 kB. So, mem is not 
an issue also. Here is top output on run:

top - 23:39:18 up 1 day, 21 min,  2 users,  load average: 0.08, 0.03, 
0.05
Tasks: 371 total,   3 running, 368 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu1  :  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu2  :  0.3 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu4  :  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu6  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu7  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu8  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu9  :  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu10 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu11 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu12 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu13 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu14 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu15 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu16 : 29.1 us, 20.3 sy,  0.0 ni, 50.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu17 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu18 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu19 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu20 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu21 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu22 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu23 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu24 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu25 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu26 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu27 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu28 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu29 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu30 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
%Cpu31 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 st
KiB Mem:  49413456 total, 19607392 used, 29806064 free,   106188 buffers
KiB Swap: 50282492 total,0 used, 50282492 free. 16826488 cached 
Mem

  PID USER  PR  NIVIRTRESSHR S  %CPU %MEM TIME+ 
COMMAND
 9563 root  20   0 70.432g 2.003g 1.948g R  49.2  4.3   0:08.02 
ffmpeg
  735 root  20   0   0  0  0 S   0.3  0.0   5:49.83 
blackmagic
 9600 root  20   0   22240   1844   1112 R   0.3  0.0   0:00.02 top
1 root  20   0   33696   2960   1472 S   0.0  0.0   0:08.37 

Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-25 Thread Philip Langdale
On Wed, 25 Mar 2015 21:52:54 + (UTC)
Ali KIZIL aliki...@gmail.com wrote:

 
 The update broken the general usage:
 
 ./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc -preset
 hp -fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k
 -bufsize 48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -pix_fmt
 yuv420p - acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k
 -flush_packets 0 - packetsize 188 -y -f mpegts out.ts
 
 ./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc_h265 -
 preset hp -fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k -
 bufsize 48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -pix_fmt 
 yuv420p -acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k
 -flush_packets 0 -packetsize 188 -y -f mpegts out.ts
 
 FFmpeg stucks, does not work for both. 
 
 Before with nvenc work working fine with above commands. It looks
 like - g parameter, -muxrate, -flush_packtes stuck FFmpeg with this
 update. 
 
 Below line works:
 
 ./ffmpeg -loglevel verbose -i /root/bunny.mp4 -vcodec nvenc_h265
 -preset hp -r 50  -y -f mpegts out.ts

Yes - it's because I tried to share the class instance between the two
encoders, which doesn't work. I'm about to push a fix. Thanks for the
heads up.

--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-25 Thread Ali KIZIL
Philip Langdale philipl at overt.org writes:

 
 On Tue, 24 Mar 2015 09:54:13 +0100
 Timo Rothenpieler timo at rothenpieler.org wrote:
 
  Yes, I did exactly that in my implementation:
  
  https://github.com/BtbN/FFmpeg/commits/nvenc
  
  The code i wrote there is completely untested(Except that h264 still 
  works), because i don't have any compatible hardware, so the one you 
  tested is clearly the one that should be prefered.
  
  Dropping SDK 5 support is fine with me, as long as it's not
  backported to 2.6. The primary gain from supporting the old SDK is
  that it works with much older nvidia driver versions.
  
  I'll submit the patch that drops the old API support, so you can
  rebase your patch on top of it.
  
  Looks good to merge otherwise.
  
 
 I've taken your logic to check the SM version - I had been
 wondering how old hardware should be detected and excluded.
 
 I've also noticed that the profile handling code is completely broken 
-
 you can't set a profile using -profile:v - it appears we're handling
 this in an incorrect way - but I'm not sure what correct is. libx264
 has its own profile option which appears to be necessary but then I
 don't understand what sets avctx-profile.
 
 Anyway, that's a separate problem we can solve independently of h.265.
 
 Thanks!
 
 --phil
 

The update broken the general usage:

./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc -preset hp 
-fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k -bufsize 
48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -pix_fmt yuv420p -
acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k -flush_packets 0 -
packetsize 188 -y -f mpegts out.ts

./ffmpeg -loglevel info -re -i /root/bunny.mp4 -vcodec nvenc_h265 -
preset hp -fflags +genpts -vb 24000k -minrate 24000k -maxrate 24000k -
bufsize 48000k -muxrate 26000k -cbr 1 -2pass 0 -r 50 -g 100 -pix_fmt 
yuv420p -acodec aac -strict -2 -ac 2 -ar 48000 -ab 256k -flush_packets 0 
-packetsize 188 -y -f mpegts out.ts

FFmpeg stucks, does not work for both. 

Before with nvenc work working fine with above commands. It looks like -
g parameter, -muxrate, -flush_packtes stuck FFmpeg with this update. 

Below line works:

./ffmpeg -loglevel verbose -i /root/bunny.mp4 -vcodec nvenc_h265 -preset 
hp -r 50  -y -f mpegts out.ts




___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-25 Thread Michael Niedermayer
On Mon, Mar 23, 2015 at 09:41:25PM -0700, Philip Langdale wrote:
 Sufficiently new nvenc hardware (GM20x or later) has support for H.265
 encoding. This works the same as the H.264 encoder except the
 codec parameters are different.
 
 Due to the fact that common codec parameters are not shareable, there's
 quite a bit of conditional logic you'd wish we could do without, but
 such is life.
 
 Note that this feature requires the 5.0 SDK or newer to compile. I'm not
 sure what we gain from supporting the older SDKs, so I'm inclined to
 make this unconditional and remove the  5 support that currently exists.
 
 Signed-off-by: Philip Langdale phil...@overt.org

theres a comment on github about this:
see:
https://github.com/FFmpeg/FFmpeg/commit/21175d8586d368f5f0b2ed0edda22f8f1c108330#commitcomment-10400533

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-24 Thread Philip Langdale
On Tue, 24 Mar 2015 09:54:13 +0100
Timo Rothenpieler t...@rothenpieler.org wrote:

 Yes, I did exactly that in my implementation:
 
 https://github.com/BtbN/FFmpeg/commits/nvenc
 
 The code i wrote there is completely untested(Except that h264 still 
 works), because i don't have any compatible hardware, so the one you 
 tested is clearly the one that should be prefered.
 
 Dropping SDK 5 support is fine with me, as long as it's not
 backported to 2.6. The primary gain from supporting the old SDK is
 that it works with much older nvidia driver versions.
 
 I'll submit the patch that drops the old API support, so you can
 rebase your patch on top of it.
 
 Looks good to merge otherwise.
 

I've taken your logic to check the SM version - I had been
wondering how old hardware should be detected and excluded.

I've also noticed that the profile handling code is completely broken -
you can't set a profile using -profile:v - it appears we're handling
this in an incorrect way - but I'm not sure what correct is. libx264
has its own profile option which appears to be necessary but then I
don't understand what sets avctx-profile.

Anyway, that's a separate problem we can solve independently of h.265.

Thanks!

--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-24 Thread Timo Rothenpieler

Am 24.03.2015 um 05:41 schrieb Philip Langdale:

Sufficiently new nvenc hardware (GM20x or later) has support for H.265
encoding. This works the same as the H.264 encoder except the
codec parameters are different.

Due to the fact that common codec parameters are not shareable, there's
quite a bit of conditional logic you'd wish we could do without, but
such is life.

Note that this feature requires the 5.0 SDK or newer to compile. I'm not
sure what we gain from supporting the older SDKs, so I'm inclined to
make this unconditional and remove the  5 support that currently exists.


Yes, I did exactly that in my implementation:

https://github.com/BtbN/FFmpeg/commits/nvenc

The code i wrote there is completely untested(Except that h264 still 
works), because i don't have any compatible hardware, so the one you 
tested is clearly the one that should be prefered.


Dropping SDK 5 support is fine with me, as long as it's not backported 
to 2.6. The primary gain from supporting the old SDK is that it works 
with much older nvidia driver versions.


I'll submit the patch that drops the old API support, so you can rebase 
your patch on top of it.


Looks good to merge otherwise.



signature.asc
Description: OpenPGP digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/nvenc: Add support for H.265 encoding

2015-03-23 Thread Philip Langdale
Sufficiently new nvenc hardware (GM20x or later) has support for H.265
encoding. This works the same as the H.264 encoder except the
codec parameters are different.

Due to the fact that common codec parameters are not shareable, there's
quite a bit of conditional logic you'd wish we could do without, but
such is life.

Note that this feature requires the 5.0 SDK or newer to compile. I'm not
sure what we gain from supporting the older SDKs, so I'm inclined to
make this unconditional and remove the  5 support that currently exists.

Signed-off-by: Philip Langdale phil...@overt.org
---
 libavcodec/Makefile|   2 +-
 libavcodec/allcodecs.c |   1 +
 libavcodec/nvenc.c | 133 ++---
 3 files changed, 117 insertions(+), 19 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1a0c734..0bdea7f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -89,6 +89,7 @@ OBJS-$(CONFIG_MPEGVIDEO)   += mpegvideo.o 
mpegvideodsp.o\
 OBJS-$(CONFIG_MPEGVIDEOENC)+= mpegvideo_enc.o mpeg12data.o  \
   motion_est.o ratecontrol.o\
   mpegvideoencdsp.o
+OBJS-$(CONFIG_NVENC)   += nvenc.o
 OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o
 OBJS-$(CONFIG_QPELDSP) += qpeldsp.o
 OBJS-$(CONFIG_QSV) += qsv.o
@@ -356,7 +357,6 @@ OBJS-$(CONFIG_MXPEG_DECODER)   += mxpegdec.o
 OBJS-$(CONFIG_NELLYMOSER_DECODER)  += nellymoserdec.o nellymoser.o
 OBJS-$(CONFIG_NELLYMOSER_ENCODER)  += nellymoserenc.o nellymoser.o
 OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o
-OBJS-$(CONFIG_NVENC_ENCODER)   += nvenc.o
 OBJS-$(CONFIG_ON2AVC_DECODER)  += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)+= opusdec.o opus.o opus_celt.o \
   opus_silk.o vorbis_data.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index bbf70a6..29bb3a4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -228,6 +228,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(MXPEG, mxpeg);
 REGISTER_DECODER(NUV,   nuv);
 REGISTER_ENCODER(NVENC, nvenc);
+REGISTER_ENCODER(NVENC_H265,nvenc_h265);
 REGISTER_DECODER(PAF_VIDEO, paf_video);
 REGISTER_ENCDEC (PAM,   pam);
 REGISTER_ENCDEC (PBM,   pbm);
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 22956b9..4e629d0 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -467,6 +467,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
 CUcontext cu_context_curr;
 CUresult cu_res;
 GUID encoder_preset = NV_ENC_PRESET_HQ_GUID;
+GUID codec;
 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
 int surfaceCount = 0;
 int i, num_mbs;
@@ -563,14 +564,27 @@ static av_cold int nvenc_encode_init(AVCodecContext 
*avctx)
 }
 }
 
-nv_status = p_nvenc-nvEncGetEncodePresetConfig(ctx-nvencoder, 
NV_ENC_CODEC_H264_GUID, encoder_preset, preset_config);
+switch (avctx-codec-id) {
+case AV_CODEC_ID_H264:
+codec = NV_ENC_CODEC_H264_GUID;
+break;
+case AV_CODEC_ID_H265:
+codec = NV_ENC_CODEC_HEVC_GUID;
+break;
+default:
+av_log(avctx, AV_LOG_ERROR, nvenc: Unknown codec name\n);
+res = AVERROR(EINVAL);
+goto error;
+}
+
+nv_status = p_nvenc-nvEncGetEncodePresetConfig(ctx-nvencoder, codec, 
encoder_preset, preset_config);
 if (nv_status != NV_ENC_SUCCESS) {
 av_log(avctx, AV_LOG_FATAL, GetEncodePresetConfig failed: 0x%x\n, 
(int)nv_status);
 res = AVERROR_EXTERNAL;
 goto error;
 }
 
-ctx-init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID;
+ctx-init_encode_params.encodeGUID = codec;
 ctx-init_encode_params.encodeHeight = avctx-height;
 ctx-init_encode_params.encodeWidth = avctx-width;
 
@@ -616,7 +630,15 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
 
 if (avctx-refs = 0) {
 /* 0 means let the hardware decide */
-ctx-encode_config.encodeCodecConfig.h264Config.maxNumRefFrames = 
avctx-refs;
+switch (avctx-codec-id) {
+case AV_CODEC_ID_H264:
+ctx-encode_config.encodeCodecConfig.h264Config.maxNumRefFrames = 
avctx-refs;
+break;
+case AV_CODEC_ID_H265:
+
ctx-encode_config.encodeCodecConfig.hevcConfig.maxNumRefFramesInDPB = 
avctx-refs;
+break;
+/* Earlier switch/case will return if unknown codec is passed. */
+}
 }
 
 if (avctx-gop_size  0) {
@@ -626,11 +648,27 @@ static av_cold int nvenc_encode_init(AVCodecContext 
*avctx)
 }
 
 ctx-encode_config.gopLength = avctx-gop_size;
-ctx-encode_config.encodeCodecConfig.h264Config.idrPeriod = 
avctx-gop_size;
+switch