How to use ResizeNv12 in AppEncLowLatency.cpp

Hi Nvidia,

I want to use ResizeNv12 in place of ScaleYUV420 API for resizing planar or interleaved yuv .
In AppEncLowLatency.cpp example code.

The ScaleYUV420 is giving jerk moment in final output .{ Video_Codec_SDK_8.2.16}

Issue with ScaleYUV420 :-
In high motion video the output video is jerky {.h264/.hevc}

SO want to try ResizeNv12 API instead ScaleYUV420 API in AppEncLowLatency.cpp example.

I have attached the input file with ffmpeg cmd to extract .yuv and feed to nvidia video sdk encoder.

  1. Encoded Input file
    https://drive.google.com/open?id=1vtraIOWlF01Q5p7_tgbAPgNXi71jc9ZN
  2. cmd to extract yuv
    ffmpeg.exe -y -i U4K_jurassic_world_fallen_kingdom_23M_hevc.ts -c:v rawvideo -pix_fmt yuv420p U4K_jurassic_world_fallen_kingdom_23M_hevc.yuv


Issue 2


How to integrate ResizeNv12 in AppEncLowLatency.cpp example code.

I have added the function as below.
Kindly guide me to how to call the ResizeNv12 with CopyToDeviceFrame API?

NvEncoderCuda::CopyToDeviceFrame(cuContext,
                        pHostFrame.get(),
                        0,
                        dpInputYPlane,
                        (uint32_t)inputYPlanePitch,
                        initializeParams.encodeWidth,
                        initializeParams.encodeHeight,
                        CU_MEMORYTYPE_HOST,
                        eFormat,
                        &chromaDevicePtrs[0],
                        (uint32_t)inputChromaPlanePitch,
                        (uint32_t)chromaDevicePtrs.size());
					
                   /* ScaleYUV420((unsigned char *)encoderInputFrame->inputPtr,
                        (unsigned char *)encoderInputFrame->inputPtr + encoderInputFrame->chromaOffsets[0],
                        (eFormat == NV_ENC_BUFFER_FORMAT_NV12) ? nullptr : (unsigned char *)encoderInputFrame->inputPtr + encoderInputFrame->chromaOffsets[1],
                        (int)encoderInputFrame->pitch,
                        (int)encoderInputFrame->chromaPitch,
                        enc.GetEncodeWidth(),
                        enc.GetEncodeHeight(),
                        (uint8_t*)dpInputYPlane,
                        (unsigned char *)chromaDevicePtrs[0],
                        (eFormat == NV_ENC_BUFFER_FORMAT_NV12) ? nullptr : (unsigned char *)chromaDevicePtrs[1],
                        (int)inputYPlanePitch,
                        (int)inputChromaPlanePitch,
                        initializeParams.encodeWidth,
                        initializeParams.encodeHeight,
                        (eFormat == NV_ENC_BUFFER_FORMAT_NV12) ? true : false);*/

					//void ResizeNv12(unsigned char *dpDstNv12, int nDstPitch, int nDstWidth, int nDstHeight, 
					//unsigned char *dpSrcNv12, int nSrcPitch, int nSrcWidth, int nSrcHeight, unsigned char* dpDstNv12UV)

					ResizeNv12((unsigned char *)encoderInputFrame->inputPtr,
						(int)encoderInputFrame->chromaPitch,
						enc.GetEncodeWidth(),
						enc.GetEncodeHeight(),
						(uint8_t*)dpInputYPlane,
						(int)inputYPlanePitch,
						initializeParams.encodeWidth,
						initializeParams.encodeHeight
					);

Hi meRaza,

How were you able to confirm that the jerky video was caused by ScaleYUV420?

Thanks,
Ryan Park

I have added code for software scaling and then passed scaled output to encoder, its working fine but if i use ScaleYUV420 function, Then i am able to observe Jerky video.

One pointer to add.
Recently i combine decoder and encoder example code as single process and store decoder output in buffer with cudamalloc , then their is no jerkyness in output video.

Decoder is launched with one thread and encoder is launch with another thread , in this case also i am using ScaleYUV420 in encoder side but their is know jerkyness in output video.

But if run encoder alone with ScaleYUV420 {Nvidia SDK provided} then jerkyness is observed. but if above case or software scaling {c-code} no jerkyness in output.

Seems ScaleYUV420 has some timing issue. cpu to gpu transfer.

Regards…
meRaza