Below sample works fine. FYR.
$ gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,format=RGBA,width=2048,height=1080 ! filesink location=a.yuv
$ ./test
#include <cstdlib>
#include <gst/gst.h>
#include <gst/gstinfo.h>
#include <gst/app/gstappsrc.h>
#include <glib-unix.h>
#include <dlfcn.h>
#include <cstring>
#include <iostream>
#include <sstream>
#include <thread>
using namespace std;
#define USE(x) ((void)(x))
static GstPipeline *gst_pipeline = nullptr;
static string launch_string;
static GstElement *appsrc_;
GstClockTime timestamp = 0;
static int w = 2048;
static int h = 1080;
static void *ptr = nullptr;
static gboolean feed_function(gpointer user_data) {
GstBuffer *buffer;
guint size;
GstFlowReturn ret;
GstMapInfo map = {0};
size = (w*h*4);
buffer = gst_buffer_new_allocate (NULL, size, NULL);
buffer->pts = timestamp;
gst_buffer_map (buffer, &map, GST_MAP_WRITE);
memcpy(map.data, ptr , size);
gst_buffer_unmap(buffer, &map);
g_signal_emit_by_name (appsrc_, "push-buffer", buffer, &ret);
gst_buffer_unref(buffer);
timestamp += 33333;
return G_SOURCE_CONTINUE;
}
int main(int argc, char** argv) {
USE(argc);
USE(argv);
gst_init (&argc, &argv);
GMainLoop *main_loop;
main_loop = g_main_loop_new (NULL, FALSE);
ostringstream launch_stream;
launch_stream
<< "appsrc name=mysource ! "
<< "video/x-raw,width="<< w <<",height="<< h <<",framerate=30/1,format=RGBA ! "
<< "nvvidconv ! video/x-raw(memory:NVMM),format=RGBA ! "
<< "nvoverlaysink ";
launch_string = launch_stream.str();
g_print("Using launch string: %s\n", launch_string.c_str());
GError *error = nullptr;
gst_pipeline = (GstPipeline*) gst_parse_launch(launch_string.c_str(), &error);
if (gst_pipeline == nullptr) {
g_print( "Failed to parse launch: %s\n", error->message);
return -1;
}
if(error) g_error_free(error);
appsrc_ = gst_bin_get_by_name(GST_BIN(gst_pipeline), "mysource");
gst_app_src_set_stream_type(GST_APP_SRC(appsrc_), GST_APP_STREAM_TYPE_STREAM);
guint size;
size = (w*h*4);
FILE *fp = fopen ("/home/nvidia/a.yuv", "rb");
ptr = malloc(size);
fread(ptr, size, 1, fp);
fclose(fp);
gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING);
for (int i=0; i<150; i++) {
feed_function(nullptr);
usleep(33333);
}
gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(gst_pipeline));
g_main_loop_unref(main_loop);
free(ptr);
g_print("going to exit \n");
return 0;
}
A relative post https://devtalk.nvidia.com/default/topic/1026106/jetson-tx1/usage-of-nvbuffer-apis/post/5219225/#5219225
a.cpp (2.44 KB)