Using GstBuffer to transport data?

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?

Thank you in advance!

Hi,
You can get the compressed stream in appsink. Please refer to this sample:
Latency issue: nvv4l2h265enc accumulates four images before releasing the first - #3 by DaneLLL

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 :)

Hi,
The information of framerate is in VUI and you can check by executing ffprobe:

$ ffprobe ~/out1.265
ffprobe version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, hevc, from '/home/nvidia/out1.265':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1920x1080, 10 fps, 10 tbr, 1200k tbn, 10 tbc

So you don’t see 15 fps after calling setInsertVuiEnabled() and setFrameRate()?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.