AVFrame to GstBuffer

I used the deepstream-appsrc-test sample from DeepStream sample apps in C, where the GStreamer pipeline uses a appsrc element. This deepstream sample takes data from raw video file and transform it to GstBuffer.
However, my goal is to take AVFrame from libav (ffmpeg) and transform it to GstBuffer, but I can not find any solution.

Here is part of code from the deepstream-appsrc-test pushing the buffers from video file to appsrc:

typedef struct _AppSrcData
GstElement *app_source;
long frame_size;
FILE *file;
gint appsrc_frame_num;
guint fps;
guint sourceid;
} AppSrcData;

static gboolean read_data (AppSrcData * data)
GstBuffer *buffer;
GstFlowReturn gstret;

size_t ret = 0;
GstMapInfo map;
buffer = gst_buffer_new_allocate (NULL, data->frame_size, NULL);

gst_buffer_map (buffer, &map, GST_MAP_WRITE);
// Read frame from raw video file.
ret = fread (map.data, 1, data->frame_size, data->file);
map.size = ret;

gst_buffer_unmap (buffer, &map);

// Push buffer to appsrc element.
gstret = gst_app_src_push_buffer ((GstAppSrc *) data->app_source, buffer);


return TRUE;

My question is, how to tranform data from AVFrame to GstBuffer, instead of video file to GstBuffer.

• DeepStream Version 5.0

Please refer to AVFrame data structure and API description from ffmpeg https://ffmpeg.org/doxygen/2.7/structAVFrame.html, the document of GstBuffer from Gsteamer https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c.
AppSrcData is the interface for appsrc to get data from outside the gstreamer pipeline. You can define and implement your own read_data() callback for get data from AVFrame. More information, please refer to appsrc (gstreamer.freedesktop.org) Basic tutorial 8: Short-cutting the pipeline (gstreamer.freedesktop.org)
There are also lot of 3rd party appsrc samples, e.g. GStreamer Streaming AppSrc Example (github.com)