Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
@ 2023-07-27  2:39 Водянников Александр
  2023-07-27 12:08 ` Timo Rothenpieler
  2023-08-13 17:36 ` Timo Rothenpieler
  0 siblings, 2 replies; 6+ messages in thread
From: Водянников Александр @ 2023-07-27  2:39 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0001-Add-NVENC-Maximum-encoded-slice-size-in-bytes-for-H264_H265-codecs.txt --]
[-- Type: text/plain, Size: 4152 bytes --]

From: Aleksoid <Aleksoid1978@mail.ru>
Date: Thu, 27 Jul 2023 12:26:23 +1000
Subject: [PATCH] Add NVENC "Maximum encoded slice size in bytes" for
 H.264/HEVC codecs.

Signed-off-by: Aleksoid <Aleksoid1978@mail.ru>
---
 libavcodec/nvenc.c      | 18 ++++++++++++++----
 libavcodec/nvenc.h      |  1 +
 libavcodec/nvenc_h264.c |  2 ++
 libavcodec/nvenc_hevc.c |  2 ++
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 0b6417674e..c82fcbfe1e 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1166,8 +1166,13 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
         || vui->videoFormat != 5
         || vui->videoFullRangeFlag != 0);
 
-    h264->sliceMode = 3;
-    h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
+    if (ctx->max_slice_size > 0) {
+        h264->sliceMode = 1;
+        h264->sliceModeData = ctx->max_slice_size;
+    } else {
+        h264->sliceMode = 3;
+        h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
+    }
 
     if (ctx->intra_refresh) {
         h264->enableIntraRefresh = 1;
@@ -1287,8 +1292,13 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
         || vui->videoFormat != 5
         || vui->videoFullRangeFlag != 0);
 
-    hevc->sliceMode = 3;
-    hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
+    if (ctx->max_slice_size > 0) {
+        hevc->sliceMode = 1;
+        hevc->sliceModeData = ctx->max_slice_size;
+    } else {
+        hevc->sliceMode = 3;
+        hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
+    }
 
     if (ctx->intra_refresh) {
         hevc->enableIntraRefresh = 1;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 3a4b456a41..cf0e8e5946 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -262,6 +262,7 @@ typedef struct NvencContext
     int udu_sei;
     int timing_info;
     int highbitdepth;
+    int max_slice_size;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index a99860998e..4440e49b25 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -206,6 +206,8 @@ static const AVOption options[] = {
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { "single-slice-intra-refresh", "Use single slice intra refresh",
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+    { "max_slice_size", "Maximum encoded slice size in bytes",
+                                                            OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
                                                             OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { NULL }
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index a02f277888..e606655e7e 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -187,6 +187,8 @@ static const AVOption options[] = {
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { "single-slice-intra-refresh", "Use single slice intra refresh",
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+    { "max_slice_size", "Maximum encoded slice size in bytes",
+                                                            OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
                                                             OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { NULL }
-- 
2.41.0.windows.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
  2023-07-27  2:39 [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs Водянников Александр
@ 2023-07-27 12:08 ` Timo Rothenpieler
  2023-07-27 13:22   ` Kieran Kunhya
  2023-08-13 17:36 ` Timo Rothenpieler
  1 sibling, 1 reply; 6+ messages in thread
From: Timo Rothenpieler @ 2023-07-27 12:08 UTC (permalink / raw)
  To: ffmpeg-devel

Looks sensible to me.
I'm curious, what is the use case for this mode?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
  2023-07-27 12:08 ` Timo Rothenpieler
@ 2023-07-27 13:22   ` Kieran Kunhya
  0 siblings, 0 replies; 6+ messages in thread
From: Kieran Kunhya @ 2023-07-27 13:22 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Thu, 27 Jul 2023 at 13:09, Timo Rothenpieler <timo@rothenpieler.org>
wrote:

> Looks sensible to me.
> I'm curious, what is the use case for this mode?
>

The classical use-case for this feature is to fit a slice in a UDP packet
for RTP streaming.

Kieran
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
  2023-07-27  2:39 [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs Водянников Александр
  2023-07-27 12:08 ` Timo Rothenpieler
@ 2023-08-13 17:36 ` Timo Rothenpieler
  2023-08-13 23:08   ` Kieran Kunhya
  1 sibling, 1 reply; 6+ messages in thread
From: Timo Rothenpieler @ 2023-08-13 17:36 UTC (permalink / raw)
  To: ffmpeg-devel

Did you actually get this to work?
I'm testing it right now, and at stupid low values like 10 bytes I get a 
working but heavily artifacted video.
If I set it to something like 2048 all I get is a full size video that 
VLC decodes to a black screen.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
  2023-08-13 17:36 ` Timo Rothenpieler
@ 2023-08-13 23:08   ` Kieran Kunhya
  2023-08-14 21:20     ` Timo Rothenpieler
  0 siblings, 1 reply; 6+ messages in thread
From: Kieran Kunhya @ 2023-08-13 23:08 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Sun, 13 Aug 2023 at 18:36, Timo Rothenpieler <timo@rothenpieler.org>
wrote:

> Did you actually get this to work?
> I'm testing it right now, and at stupid low values like 10 bytes I get a
> working but heavily artifacted video.
> If I set it to something like 2048 all I get is a full size video that
> VLC decodes to a black screen.


This could be a bug in hwaccel decode. Does it work in software decode?

Kieran
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs.
  2023-08-13 23:08   ` Kieran Kunhya
@ 2023-08-14 21:20     ` Timo Rothenpieler
  0 siblings, 0 replies; 6+ messages in thread
From: Timo Rothenpieler @ 2023-08-14 21:20 UTC (permalink / raw)
  To: ffmpeg-devel

On 14.08.2023 01:08, Kieran Kunhya wrote:
> On Sun, 13 Aug 2023 at 18:36, Timo Rothenpieler <timo@rothenpieler.org>
> wrote:
> 
>> Did you actually get this to work?
>> I'm testing it right now, and at stupid low values like 10 bytes I get a
>> working but heavily artifacted video.
>> If I set it to something like 2048 all I get is a full size video that
>> VLC decodes to a black screen.
> 
> 
> This could be a bug in hwaccel decode. Does it work in software decode?

Yeah, it works fine with software decode. At least in VLC.
Though surprisingly the bigger slice size limit looks significantly 
worse than the stupid low one of 10, it might have just ignored me?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-14 21:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27  2:39 [FFmpeg-devel] [PATCH] Add NVENC "Maximum encoded slice size in bytes" for H.264/HEVC codecs Водянников Александр
2023-07-27 12:08 ` Timo Rothenpieler
2023-07-27 13:22   ` Kieran Kunhya
2023-08-13 17:36 ` Timo Rothenpieler
2023-08-13 23:08   ` Kieran Kunhya
2023-08-14 21:20     ` Timo Rothenpieler

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git