Encode frames using Nvenc v4l2

hi all,

i’m working on a special application on Jetson Nano which have the following data flow :

[camera]-----UYVY------>[VIC]----YUV420----->[NVENC]----H264---->[file]

so, as you can see, the camera gives me UYVY images, i transform it using VIC to be readable by the encoder.

but I’m struggling to transfer data to the encoder.

I’m using V4L2 ( and i’m not intend to use Gstreamer related to others constraints). so in my flow in use the NvBufferTransform to change the color format. but then i struggle to send data to the encoder, and there is no example thats doing that.

the buffer between camera and VIC, and the one between VIC and NVENC are DMA, to get best performance.

i really need some help here !

thanks in advance.

Have reference to 10_camera_recording. Get the sample code from below command.

sudo apt list -a nvidia-l4t-jetson-multimedia-api
sudo apt install nvidia-l4t-jetson-multimedia-api=32.xxxx

hi ShaneCCC,

thanks for the reply,

this example use libargus, i’m using V4L2, i already saw it ( as others examples ! ) so i don’t really understand why you redirected me on this example

to be more precise in what i’m trying to do, i just want to send the output DMA buffer form the vic, to the input of the NvEnc.
i thought it was just a FD to transmit… but obvouisly, seems to be more complicated… do i need to set multiple DMA buffers for the output of the VIC ?

OK, I think you can reference to 12_camera_v4l2_cuda for DMA buffer allocate and others sample code for VIC and encoder.

thanks for the reply,

i’ve done some modfication without proper resulte, according to the examples i am able to encode from the DMA, but i am clearly wrong in the dma buffer transmission between VIC and NvEnc.

apparently the “output plane” from the Nvenc is a circular buffer. in the other way, the VIC is just pushing the datas out on a single memory space ( using NvBufferTransform() ).

i think the purpose of my struggles is "only " to replace the read_video_filefunction from the example 01.
but i really don’t know how to handle this.

i have read all the examples, and docs related to the Jetson Linux API

Hi,
There is a patch demonstrating 12_camera_v4l2_cuda + NvVideoEncoder. Please take a look at
tegra multimedia samples not working properly - #11 by DaneLLL

hi DaneLLL,

thanks this help a lot !

i will try to integrate this in my code, to see if everything is OK. because there is a little problem, the patch seems to freeze a few moment after launching the app. the application is still working but the render is frozen.

i suspect something with the Jetpack version, but still, I’m not sure. (*I’m working on 4.4.1, with camera on MIPI CSI interface)

okay, i’ve sold the problem with the patch thats add the Nvencoder for 12_camera_v4l2_cuda sample, by adding a “printf” a the begining of the " if (fds[0].revents & POLLIN) { ".

might be a sync problem behind, so this is probably not the best solution

hi,

i have adapted the code to my usage but I’m still in error.

i can’t get any encoded file because it catch a “nullptr” BEFORE anything happens ( so before it reads the fd). i don’t know what i can do … i tryed several things…

i confirm that the fd is transfered …

what is the shared buffer ? may i have to use it ?

Hi,
Are you able to try with a USB camera? The patch is verified and should work fine. Maybe you can try with other kind of v4l2 source.

hi,

no i can’t try with USB camera.

as i said, the program works when I’ve added a simple “printf” inside the while loop.

problem solved !

this is due to the implicite code you’ve made on the patch about queuing dequeuing.

now it works fine. but i’m a little bit worried because i encode frames but when i’m reading it using VLC, the content is not fluid : some frames seems to be drop when encoded.

i use a SD card from Kingston : https://www.inmac-wstore.com/kingston-high-endurance-carte-memoire-flash-128-go-microsdxc-uhs-i/p7197303.htm (128 GB)
High Endurance microSD Card - Kingston Technology

is that possible that it is not enough to write each frames at 60 fps ? as it nearly read 45Mo/s ?

or is that the encoder ?

Hi,
Please run 00_video_decode to decode the h264 stream. Check if the h264 stream is valid. If you also observe non-fluid playback, it is very likely the source drops frames.

this is due to VLC, the decoder integrated seems to not be very efficient for more than 30FPS i run about 60 or 120 fps.

so for viewer :

1 > use the patch shared by DaneLLL
2 > decode with ffmpeg

issue closed