Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 7/9] avcodec/nvenc: add MV-HEVC encoding support
Date: Thu, 30 Jan 2025 17:17:55 -0300
Message-ID: <4284c116-7dcc-4e39-a31e-2309348f371f@gmail.com> (raw)
In-Reply-To: <20250130194124.21836-8-timo@rothenpieler.org>


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

On 1/30/2025 4:40 PM, Timo Rothenpieler wrote:
> From: Diego de Souza <ddesouza@nvidia.com>
> 
> Added support for MV-HEVC encoding for stereoscopic videos (2 views
> only). Compatible with the framepack filter when using the
> AV_STEREO3D_FRAMESEQUENCE format.
> 
> Signed-off-by: Diego de Souza <ddesouza@nvidia.com>
> ---
>   libavcodec/nvenc.c      | 49 +++++++++++++++++++++++++++++++++++++++++
>   libavcodec/nvenc.h      |  4 ++++
>   libavcodec/nvenc_hevc.c |  6 +++++
>   3 files changed, 59 insertions(+)
> 
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index 3403fa8996..a528f1ce93 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -35,6 +35,7 @@
>   #include "libavutil/mem.h"
>   #include "libavutil/pixdesc.h"
>   #include "libavutil/mathematics.h"
> +#include "libavutil/stereo3d.h"
>   #include "atsc_a53.h"
>   #include "codec_desc.h"
>   #include "encode.h"
> @@ -656,6 +657,14 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
>   
>       ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
>   
> +#ifdef NVENC_HAVE_MVHEVC
> +    ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_MVHEVC_ENCODE);
> +    if(ctx->multiview && ret <= 0) {
> +        av_log(avctx, AV_LOG_WARNING, "Multiview not supported by the device\n");
> +        return AVERROR(ENOSYS);
> +    }
> +#endif
> +
>       return 0;
>   }
>   
> @@ -1544,6 +1553,11 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
>       }
>   #endif
>   
> +#ifdef NVENC_HAVE_MVHEVC
> +    hevc->enableMVHEVC = ctx->multiview;
> +    hevc->outputHevc3DReferenceDisplayInfo = ctx->display_sei;
> +#endif
> +
>       return 0;
>   }
>   
> @@ -2469,6 +2483,9 @@ static int nvenc_set_timestamp(AVCodecContext *avctx,
>   
>       // This can be more than necessary, but we don't know the real reorder delay.
>       delay = FFMAX(ctx->encode_config.frameIntervalP - 1, 0);
> +#ifdef NVENC_HAVE_MVHEVC
> +    delay *= ctx->multiview + 1;
> +#endif
>       if (ctx->output_frame_num >= delay) {
>           pkt->dts = timestamp_queue_dequeue(ctx->timestamp_list);
>           ctx->output_frame_num++;
> @@ -2875,6 +2892,9 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
>       int res, res2;
>       int sei_count = 0;
>       int i;
> +#ifdef NVENC_HAVE_MVHEVC
> +    HEVC_3D_REFERENCE_DISPLAY_INFO ref_disp_info = { 0 };
> +#endif
>   
>       NvencContext *ctx = avctx->priv_data;
>       NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
> @@ -2952,6 +2972,35 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
>       if (res < 0)
>           return res;
>   
> +#ifdef NVENC_HAVE_MVHEVC
> +    if (ctx->multiview)
> +    {
> +        const AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_STEREO3D);
> +        if (sd)
> +        {
> +            const AVStereo3D *stereo = (const AVStereo3D*)sd->data;
> +            if (stereo->type == AV_STEREO3D_FRAMESEQUENCE) {

No brackets for single line blocks.

> +                ctx->next_view_id = (stereo->view == AV_STEREO3D_VIEW_LEFT) ? 0 : 1;
> +            } else {
> +                sd = NULL;
> +                av_log(avctx, AV_LOG_ERROR, "Stereo format %d not supported! Only AV_STEREO3D_FRAMESEQUENCE is supported!\n", stereo->type);
> +            }
> +        }
> +
> +        pic_params.codecPicParams.hevcPicParams.viewId = ctx->next_view_id;
> +        if (!sd)
> +            ctx->next_view_id ^= 1;
> +
> +        if (ctx->display_sei)
> +        {
> +            ref_disp_info.precRefDisplayWidth = 31;
> +            ref_disp_info.leftViewId[0] = 0;
> +            ref_disp_info.rightViewId[0] = 1;

There's AV_FRAME_DATA_VIEW_ID, which the native hevc decoder uses to 
export the view ids when the 3D reference display information SEI 
message is present in the bitstream.
It should be used here too.

> +            pic_params.codecPicParams.hevcPicParams.p3DReferenceDisplayInfo = &ref_disp_info;
> +        }
> +    }
> +#endif
> +
>       nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params);
>   
>       for (i = 0; i < sei_count; i++)
> diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
> index 6f7f8d4e7f..77aef3f188 100644
> --- a/libavcodec/nvenc.h
> +++ b/libavcodec/nvenc.h
> @@ -99,6 +99,7 @@ typedef void ID3D11Device;
>   #define NVENC_HAVE_422_SUPPORT
>   #define NVENC_HAVE_AV1_UHQ_TUNING
>   #define NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
> +#define NVENC_HAVE_MVHEVC
>   #endif
>   
>   typedef struct NvencSurface
> @@ -245,6 +246,7 @@ typedef struct NvencContext
>       void *nvencoder;
>   
>       uint32_t frame_idx_counter;
> +    uint32_t next_view_id;
>   
>       int preset;
>       int profile;
> @@ -291,6 +293,7 @@ typedef struct NvencContext
>       int single_slice_intra_refresh;
>       int constrained_encoding;
>       int udu_sei;
> +    int display_sei;
>       int timing_info;
>       int highbitdepth;
>       int max_slice_size;
> @@ -299,6 +302,7 @@ typedef struct NvencContext
>       int lookahead_level;
>       int unidir_b;
>       int split_encode_mode;
> +    int multiview;
>   } NvencContext;
>   
>   int ff_nvenc_encode_init(AVCodecContext *avctx);
> diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
> index 5696e14dd4..f821eaee50 100644
> --- a/libavcodec/nvenc_hevc.c
> +++ b/libavcodec/nvenc_hevc.c
> @@ -194,6 +194,12 @@ static const AVOption options[] = {
>                                                               OFFSET(extra_sei),    AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0, 1, VE },
>       { "udu_sei",      "Pass on user data unregistered SEI if available",
>                                                               OFFSET(udu_sei),      AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
> +#ifdef NVENC_HAVE_MVHEVC
> +    { "display_sei",  "Pass on 3D reference display information SEI message for MV-HEVC",
> +                                                            OFFSET(display_sei),  AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },

Shouldn't this SEI message always be present for stereoscopic MV-HEVC?

> +    { "mvhevc",       "Set to 1 to enable MV-HEVC. This feature currently supports only 2 views",

This should instead be a check for the AV_PROFILE_HEVC_MULTIVIEW_MAIN 
profile.

> +                                                            OFFSET(multiview),    AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
> +#endif
>       { "intra-refresh","Use Periodic Intra Refresh instead of IDR frames",
>                                                               OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
>       { "single-slice-intra-refresh", "Use single slice intra refresh",


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: 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".

  reply	other threads:[~2025-01-30 20:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30 19:40 [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec SDK 13.0 support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 1/9] avutil/hwcontext_cuda: add 4:2:2 pixel format support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 2/9] avcodec/nvdec: add 4:2:2 decoding and 10-bit support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cuviddec: add HEVC/H.264 4:2:2 and H.264 " Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 4/9] avcodec/nvenc: add 4:2:2 encoding " Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 5/9] avcodec/nvenc: add UHQ to AV1 for NVENC Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 6/9] avcodec/nvenc: add Temporal Filtering for AV1 and H.264 in NVENC Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/nvenc: add MV-HEVC encoding support Timo Rothenpieler
2025-01-30 20:17   ` James Almer [this message]
2025-01-30 23:23   ` [FFmpeg-devel] [PATCH v2 " Timo Rothenpieler
2025-01-31  3:26     ` James Almer
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/nvenc: use encoder level options for qmin/qmax Timo Rothenpieler
2025-01-31  6:16   ` Zhao Zhili
2025-01-31 13:20     ` Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 9/9] avcodec/nvenc: finalize SDK 13.0 support Timo Rothenpieler
2025-02-01 21:15 ` [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec " Timo Rothenpieler
2025-02-02 19:05   ` Timo Rothenpieler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4284c116-7dcc-4e39-a31e-2309348f371f@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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