<div dir="ltr">Hi,
<br><br>Please help me find a solution to this issue:
<br><br>- I have YUV data file as input and I should output H264 file,
using hardware encoding supported by nvidia Jetson TX2 (omxh264enc).
<br>- I should use c/c++ to write my program.
<br>- I have already done the following line command and I obtain the h264 as output and I I have succeeded in playing it using vlc.
<br><br> gst-launch-1.0 filesrc blocksize=345600 location=Basketball.yuv
! 'video/x-raw, width=(int)640, height=(int)360, format=(string)I420,
framerate=(fraction)25/1' ! omxh264enc ! 'video/x-h264,
stream-format=(string)byte-stream' ! filesink
location=results_block_size_345600.h264
<br><br><br><br>-So now I should convert this command line to a code and replace the filesrc by an appsrc, but I obtain error when executing it:
<br><br> //gcc -Wall $(pkg-config --cflags gstreamer-1.0) YUV_to_H264.c -o yuvtoh264 $(pkg-config --libs gstreamer-1.0) -lgstapp-1.0
<br><br> #include <gst/gst.h><br> #include <stdio.h><br> #include <stdlib.h><br> #include <string.h><br> #include <gst/app/gstappsrc.h><br><br> #define WIDTH 640
<br> #define HEIGHT 360
<br> #define BUFFER_SIZE (WIDTH*HEIGHT*3/2)
<br><br> /* Structure to contain all our information */
<br> typedef struct _CustomData {
<br><br> GstElement *pipeline, *source, *encoder, *filter, *fsink;
<br> GMainLoop *loop;
<br> FILE *yuv_file;
<br><br> } CustomData;
<br><br> static void cb_need_data (GstElement *source, guint size, CustomData *data)
<br> {
<br> static GstClockTime timestamp = 0;
<br> char* data_pointer;
<br> //size_t read_bytes;
<br> GstBuffer *buffer;
<br> GstFlowReturn ret;
<br><br> data_pointer = (char*)malloc (BUFFER_SIZE);
<br> g_assert(data_pointer != NULL);
<br> fread(data_pointer, 1 , BUFFER_SIZE, data->yuv_file);
<br><br> buffer = gst_buffer_new_wrapped (data_pointer, BUFFER_SIZE);
<br> free(data_pointer);
<br>
<br> GST_BUFFER_PTS(buffer) = timestamp;
<br> GST_BUFFER_DTS(buffer) = timestamp;
<br> //GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 1);
<br> GST_BUFFER_DURATION(buffer) = GST_CLOCK_TIME_NONE;
<br> timestamp += GST_BUFFER_DURATION (buffer);
<br><br> g_signal_emit_by_name (source, "push-buffer", buffer, &ret);
<br> gst_buffer_unref (buffer);
<br><br> if (ret != GST_FLOW_OK) {
<br> g_main_loop_quit (data->loop);
<br> }
<br> }
<br><br> gint main (gint argc, gchar *argv[])
<br> {
<br> CustomData data;
<br> GstCaps *input_enc_caps, *output_enc_caps;
<br> GstStateChangeReturn state_ret;
<br> long yuv_file_size;
<br>
<br> /*Initialize cumstom data structure */
<br> memset (&data, 0, sizeof (data));
<br><br> /* Initialize GStreamer and create the mainloop */
<br> gst_init (&argc, &argv);
<br> data.loop = g_main_loop_new (NULL, FALSE);
<br><br> /* Create the elements */
<br> data.source = gst_element_factory_make ("appsrc", "myapp_source");
<br> data.encoder = gst_element_factory_make ("omxh264enc", "myapp_encoder");
<br> data.filter = gst_element_factory_make ("capsfilter", "myapp_filter");
<br> data.fsink = gst_element_factory_make ("filesink", "myapp_sink");
<br><br> /* Create the empty pipeline */
<br> data.pipeline = gst_pipeline_new ("myapp_pipeline");
<br><br> if (!data.pipeline || !data.source || !data.encoder || !data.filter
<br> || !data.fsink)
<br> {
<br> g_printerr ("Not all elements could be created.\n");
<br> return -1;
<br> }
<br><br> /* Get a pointer to the YUV input file*/
<br> data.yuv_file = fopen("/media/ubuntu/6634-3132/Basketball.yuv", "rb");
<br> g_assert(data.yuv_file != NULL);
<br><br> /* Obtain the YUV file size */
<br> fseek (data.yuv_file , 0 , SEEK_END);
<br> yuv_file_size = ftell (data.yuv_file);
<br> rewind (data.yuv_file);
<br> //printf("\n %ld);
<br><br> /* Configure source, filter and fsink */
<br> input_enc_caps = gst_caps_new_simple ("video/x-raw",
<br> "format", G_TYPE_STRING, "I420",
<br> "width", G_TYPE_INT, WIDTH,
<br> "height", G_TYPE_INT, HEIGHT,
<br> "framerate", GST_TYPE_FRACTION, 25, 1, NULL);
<br><br> output_enc_caps = gst_caps_new_simple ("video/x-h264",
<br> "stream-format", G_TYPE_STRING, "byte-stream", NULL);
<br><br> g_object_set (G_OBJECT (data.source), "caps", input_enc_caps,
<br> "stream-type", 2,
<br> "format", GST_FORMAT_BYTES,
<br> "size", (gint64)(yuv_file_size), NULL);
<br> g_signal_connect (data.source, "need-data", G_CALLBACK (cb_need_data), NULL);
<br><br> g_object_set (G_OBJECT (data.filter), "caps", output_enc_caps, NULL);
<br> g_object_set (G_OBJECT (data.fsink), "location",
<br> "/media/ubuntu/6634-3132/Basketball.h264", NULL);
<br><br> gst_caps_unref (input_enc_caps);
<br> gst_caps_unref (output_enc_caps);
<br>
<br> //gint64 out_size = gst_app_src_get_size(data.source);
<br> //g_print("%" G_GINT64_FORMAT, out_size);
<br><br> /* Link all elements that can be automatically linked*/
<br> gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.encoder,
<br> data.filter, data.fsink, NULL);
<br><br> if ((gst_element_link_many (data.source, data.encoder, data.filter,
<br> data.fsink, NULL)) != TRUE )
<br> {
<br> g_printerr ("Elements could not be linked.\n");
<br> gst_object_unref (data.pipeline);
<br> return -1;
<br> }
<br><br> /* Start playing the pipeline */
<br> state_ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
<br> //g_assert(state_ret == GST_STATE_CHANGE_ASYNC);
<br> if (state_ret == GST_STATE_CHANGE_FAILURE) {
<br> g_printerr ("Unable to set the pipeline to the playing state.\n");
<br> gst_object_unref (data.pipeline);
<br> return -1;
<br> }
<br><br> /* Set the MainLoop to run */
<br> g_main_loop_run (data.loop);
<br><br> /* clean up */
<br> fclose (data.yuv_file);
<br> gst_element_set_state (data.pipeline, GST_STATE_NULL);
<br> gst_object_unref (GST_OBJECT (data.pipeline));
<br> g_main_loop_unref (data.loop);
<br><br> return 0;
<br> }
<br><br>ERRORS :
<br>ubuntu@tegra-ubuntu:~/Desktop$ ./yuvtoh264
<br>Inside
NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB
and MjstreamingInside
NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB
and MjstreamingUnable to set the pipeline to the playing state.
<br><br>Thanks to help to resolve the isuue.
<br><br>Regards,
<br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><span style="background-color:rgb(11,83,148)"><i><font size="1"><span style="background-color:rgb(255,255,255)"><span><span style="background-color:rgb(255,255,255)"></span></span></span></font><span style="background-color:rgb(255,255,255)"><font size="1"><span style="font-family:comic sans ms,sans-serif"><span style="color:rgb(11,83,148)">AKRA Hanine.</span></span></font></span></i></span></div><div><span style="background-color:rgb(255,255,255)"><i><font size="1"><span style="font-family:comic sans ms,sans-serif"><span style="color:rgb(11,83,148)"><br></span></span></font></i></span></div><span style="background-color:rgb(11,83,148)"><i><font size="1"><span style="background-color:rgb(11,83,148)"><span></span></span></font></i></span><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>