Hi,
I have a project in which I have to stream a usb camera from Jetson Nano to another computer.
The thing is that i need to compress the video and encapsulate it in a custom transfer protocol so i can’t use rtsp or other communication protocol.
From what I have seen so far ( i’m a newbie) ,doing a GStreamer application could be a good way to do it.
What i would like is to get the compressed video directly after the encoder in order to process it with my own protocol.
Is it possible to do that with GstBuffer (gst_buffer_extract() looks good)" ? If yes, would these buffer be accepted as source for my decoder program?
Since you don’t need existing sink plugins in gstreamer, you can consider to use jetson_multiemdia_api. May refer to 12_camera_v4l2_cuda sample for capturing video frames through v4l2 into NvBuffer. And can apply this patch for encoding into h264 stream: TX2 Camera convert/encode using Multimedia API issue - #17 by DaneLLL
Hi,
Thanks for your fast reply !
I went with the 12_camera_v4l2_cuda sample and apllied the patch but i’m struggling to find what buffer contains the encoded stream and when it is filled.
Could you give me a hint on that ? :)
Hi,
Once encoded data is generated, enc_capture_dqbuf_thread_callback() is called. You can refer to write_encoder_output_frame() in 01_video_encoder for saving the stream data.
Ok thanks i got it.
Just on more question, i don’t see what is the difference between "v4l2_buffer * v4l2_buf " and “NvBuffer * buffer” from enc_capture_dqbuf_thread_callback().
I saw they had the same value in bytesused, do they both contain the encoded data?
Hi, NvBuffer * buffer is specific to be used at output plane in encoding. And capture plane in decoding. Please check the encoded stream in v4l2_buffer * v4l2_buf at capture plane.
Hi again,
As i said before i’m working on 12_camera_v4l2_cuda sample and applied the patch to encode into h264 stream.
I added a pipe to transfer the encoded stream to another program and it works fine but i would like to set the frame rate of the encoder.
I tried to use setFrameRate() and setInsertVuiEnabled() in encoder_initialise() but it doesn’t seem to work.
Here is my slightly modified encoder_initialise() :
static bool
encoder_initialize(context_t * ctx)
{
ctx->enc = NvVideoEncoder::createVideoEncoder("enc0");
if (ctx->enc == NULL)
ERROR_RETURN("Failed to create video encoder");
if(h264){ // h264
if (ctx->enc->setCapturePlaneFormat(V4L2_PIX_FMT_H264, ctx->cam_w,
ctx->cam_h, 2 * 1024 * 1024) < 0)
ERROR_RETURN("Failed to set up ENC capture plane format");
}else{ // h265
if (ctx->enc->setCapturePlaneFormat(V4L2_PIX_FMT_H265, ctx->cam_w,
ctx->cam_h, 2 * 1024 * 1024) < 0)
ERROR_RETURN("Failed to set up ENC capture plane format");
}
if (ctx->enc->setOutputPlaneFormat(V4L2_PIX_FMT_YUV420M, ctx->cam_w,
ctx->cam_h) < 0)
ERROR_RETURN("Failed to set up ENC output plane format");
if (ctx->enc->setBitrate(4<<20) < 0)
ERROR_RETURN("Failed to set up ENC bitrate");
if(h264){ //h264
if (ctx->enc->setProfile(V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) < 0)
ERROR_RETURN("Failed to set up ENC profile");
if (ctx->enc->setLevel(V4L2_MPEG_VIDEO_H264_LEVEL_5_0) < 0)
ERROR_RETURN("Failed to set up ENC level");
}else{ //h265
if (ctx->enc->setProfile(V4L2_MPEG_VIDEO_H265_PROFILE_MAIN) < 0)
ERROR_RETURN("Failed to set up ENC profile");
if (ctx->enc->setLevel(V4L2_MPEG_VIDEO_H265_LEVEL_4_0_MAIN_TIER) < 0)
ERROR_RETURN("Failed to set up ENC level");
}
if (ctx->enc->setRateControlMode(V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) < 0)
ERROR_RETURN("Failed to set up ENC rate control mode");
// HERE
if (ctx->enc->setInsertVuiEnabled (true) < 0)
ERROR_RETURN("Failed to set up ENC VUI");
if (ctx->enc->setFrameRate(15,1) < 0)
ERROR_RETURN("Failed to set up ENC framerate");
if (ctx->enc->output_plane.reqbufs(V4L2_MEMORY_DMABUF, OUTPLANE_BUFNUM))
ERROR_RETURN("Failed to set up ENC output plane");
if (ctx->enc->capture_plane.setupPlane(V4L2_MEMORY_MMAP, 6, true, false) < 0)
ERROR_RETURN("Failed to set up ENC capture plane");
ctx->enc->subscribeEvent(V4L2_EVENT_EOS,0,0);
return true;
}
What am i doing wrong here ?
Is there something else to modify ?
Thanks for your help :)