GSTREAMER X264enc无效缓冲区大小C
我一直在尝试使用此GSTREAMER C代码(我的系统在Ubuntu 20.04上运行,使用GSTREAMER 1.16.2和GCC 9.4.0):
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
// gst-launch-1.0 videotestsrc pattern=ball ! 'video/x-raw, format=(string)I420, width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! \
// ! queue ! nvvideoconvert ! nvv4l2h264enc bitrate=1000000 ! rtph264pay ! udpsink host=192.168.0.1 port=5000
int
main (int argc, char *argv[])
{
GstElement *pipeline, *source, *filter, *queue, *converter, *encoder, *payer, *sink;
GstBus *bus;
GstMessage *msg;
GstCaps *filtercaps;
GstStateChangeReturn ret;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
source = gst_element_factory_make ("filesrc", "source");
filter = gst_element_factory_make ("capsfilter","filter");
queue = gst_element_factory_make ("queue","queue");
converter = gst_element_factory_make ("videoconvert","converter");
encoder = gst_element_factory_make ("x264enc","encoder");
payer = gst_element_factory_make ("rtph264pay","payer");
sink = gst_element_factory_make ("udpsink", "sink");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("maxim-pipeline");
if (!pipeline || !source || !filter || !queue || !converter || !encoder || !payer || !sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, filter, queue, converter, encoder, payer, sink, NULL);
if (!gst_element_link_many (source,filter,queue,NULL)){
g_printerr ("Source->filter->queue problem\n");
gst_object_unref (pipeline);
return -1;
}
if (!gst_element_link_many (queue,converter,encoder,NULL)){
g_printerr ("Queue->converter->encoder problem\n");
gst_object_unref (pipeline);
return -1;
}
if (!gst_element_link_many(encoder,payer,sink,NULL)){
g_printerr ("Encoder->payer->sink problem\n");
gst_object_unref (pipeline);
return -1;
}
/* Modify the properties */
g_object_set (source, "location", "/home/thmsd/Videos/test.mkv", NULL);
g_object_set (encoder, "bitrate", 2000000, NULL);
g_object_set (sink, "host","192.168.0.1", NULL);
g_object_set (sink, "port",5000, NULL);
g_object_set (sink, "sync", "FALSE", NULL);
filtercaps = gst_caps_new_simple ("video/x-raw",
"format",G_TYPE_STRING,"I420",
"width", G_TYPE_INT, 1920,
"height", G_TYPE_INT, 1080,
"framerate",GST_TYPE_FRACTION,30,1,
NULL);
g_object_set (filter, "caps", filtercaps, NULL);
gst_caps_unref (filtercaps);
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return -1;
}
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg =
gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n",
GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n",
debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
但是发生以下错误,实际上是指X264enc,并且BTW此代码是编辑,编辑,编辑的,首先,它兼容了Jetson,并具有NVV4L2H264ENC:
我要流式传输的测试视频具有以下属性:
I've been trying to use this gstreamer c code(my system is running on ubuntu 20.04 with GStreamer 1.16.2 and gcc 9.4.0):
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
// gst-launch-1.0 videotestsrc pattern=ball ! 'video/x-raw, format=(string)I420, width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! \
// ! queue ! nvvideoconvert ! nvv4l2h264enc bitrate=1000000 ! rtph264pay ! udpsink host=192.168.0.1 port=5000
int
main (int argc, char *argv[])
{
GstElement *pipeline, *source, *filter, *queue, *converter, *encoder, *payer, *sink;
GstBus *bus;
GstMessage *msg;
GstCaps *filtercaps;
GstStateChangeReturn ret;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
source = gst_element_factory_make ("filesrc", "source");
filter = gst_element_factory_make ("capsfilter","filter");
queue = gst_element_factory_make ("queue","queue");
converter = gst_element_factory_make ("videoconvert","converter");
encoder = gst_element_factory_make ("x264enc","encoder");
payer = gst_element_factory_make ("rtph264pay","payer");
sink = gst_element_factory_make ("udpsink", "sink");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("maxim-pipeline");
if (!pipeline || !source || !filter || !queue || !converter || !encoder || !payer || !sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, filter, queue, converter, encoder, payer, sink, NULL);
if (!gst_element_link_many (source,filter,queue,NULL)){
g_printerr ("Source->filter->queue problem\n");
gst_object_unref (pipeline);
return -1;
}
if (!gst_element_link_many (queue,converter,encoder,NULL)){
g_printerr ("Queue->converter->encoder problem\n");
gst_object_unref (pipeline);
return -1;
}
if (!gst_element_link_many(encoder,payer,sink,NULL)){
g_printerr ("Encoder->payer->sink problem\n");
gst_object_unref (pipeline);
return -1;
}
/* Modify the properties */
g_object_set (source, "location", "/home/thmsd/Videos/test.mkv", NULL);
g_object_set (encoder, "bitrate", 2000000, NULL);
g_object_set (sink, "host","192.168.0.1", NULL);
g_object_set (sink, "port",5000, NULL);
g_object_set (sink, "sync", "FALSE", NULL);
filtercaps = gst_caps_new_simple ("video/x-raw",
"format",G_TYPE_STRING,"I420",
"width", G_TYPE_INT, 1920,
"height", G_TYPE_INT, 1080,
"framerate",GST_TYPE_FRACTION,30,1,
NULL);
g_object_set (filter, "caps", filtercaps, NULL);
gst_caps_unref (filtercaps);
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return -1;
}
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg =
gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n",
GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n",
debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
But the following error happens which is actually referring to x264enc, and btw this code is edited, at first it was jetson compatible and had nvv4l2h264enc:
The test video that I'm trying to stream has the following properties:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要注意的是,Gstreamer布尔值未用首都键入,因此请使用
true
和false
或仅使用0和1。x264enc在Jetson上可能不会那么快。您可以尝试以下操作:
这是我在Jetson上成功测试的内容(AGX Xavier运行L4T R32.6.1)。
您将适应文件源和接收器地址/端口,并将其另存为test_transcode_mkv_to_rtph264.c,然后构建以下:
and Test Streaming:
如果接收器已安装了GSTREAMER,则应使用以下内容显示:
用于以下内容:用于以下内容: VLC,您可能必须创建一个SDP文件。
编辑:对于非NVIDIA情况,您可以尝试:
First note that gstreamer booleans are not typed with capitals, so use
true
andfalse
or just use 0 and 1.x264enc may not be that fast on Jetson. You may try the following :
This is what I've successfully tested on Jetson (AGX Xavier running L4T R32.6.1).
You would adapt to your file source and receiver address/port, and save as test_transcode_MKV_to_RTPH264.c then build with:
and test streaming:
Then if receiver has gstreamer installed, you should be able to display with something like:
For receiving RTPH264 with FFMPEG or VLC, you may have to create a SDP file.
EDIT: for non-NVIDIA case, you may try: