- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 C 应用程序(在 Linux 下),它接收原始 h.264 流,并应使用 gstreamer API 可视化该流。我是 GStreamer 的新手,所以也许我犯了巨大的愚蠢错误或忽略了众所周知的东西,对此感到抱歉。
我得到了一个原始的 h264 视频(我知道它与我需要的格式完全相同)并开发了一个播放它的应用程序。它可以在拉模式下正确地与 appsrc 配合使用(当调用需要数据时,我从文件中获取新数据并执行推送缓冲区)。
现在我正在尝试做完全相同的事情,但是在推送模式下,这基本上是因为我没有视频,而是流。因此,我的代码中有一个方法,每次新数据(以 uint8_t
缓冲区的形式)到达时都会调用该方法,这是我的视频源。
我用谷歌搜索了我的问题并查看了 documentation ,但我没有发现适合我的用例的简单代码片段,即使它看起来非常简单。我知道我必须初始化管道和 appsrc,然后只有在有新数据时才推送缓冲区。
嗯,我开发了两种方法:用于管道/appsrc初始化的init_stream()
和用于在可用时发送数据的populate_app(void *inBuf, size_t len)
。它编译并正确运行,但没有视频:
struct _App
{
GstAppSrc *appsrc;
GstPipeline *pipeline;
GstElement *h264parse;
GstElement *mfw_vpudecoder;
GstElement *mfw_v4lsin;
GMainLoop *loop;
};
typedef struct _App App;
App s_app;
App *app = &s_app;
static gboolean bus_message (GstBus * bus, GstMessage * message, App * app)
{
GST_DEBUG ("got message %s", gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:
g_error ("received error");
g_main_loop_quit (app->loop);
break;
case GST_MESSAGE_EOS:
g_main_loop_quit (app->loop);
break;
default:
break;
}
return TRUE;
}
int init_stream()
{
GstBus *bus;
gst_init (NULL, NULL);
fprintf(stderr, "gst_init done\n");
/* create a mainloop to get messages */
app->loop = g_main_loop_new (NULL, TRUE);
fprintf(stderr, "app loop initialized\n");
app->pipeline = gst_parse_launch("appsrc name=mysource ! h264parse ! mfw_vpudecoder ! mfw_v4lsin", NULL);
app->appsrc = gst_bin_get_by_name (GST_BIN(app->pipeline), "mysource");
gst_app_src_set_stream_type(app->appsrc, GST_APP_STREAM_TYPE_STREAM);
gst_app_src_set_emit_signals(app->appsrc, TRUE);
fprintf(stderr, "Pipeline and appsrc initialized\n");
/* Create Bus from pipeline */
bus = gst_pipeline_get_bus(app->pipeline);
fprintf(stderr, "bus created\n");
/* add watch for messages */
gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
gst_object_unref(bus);
fprintf(stderr, "bus_add_watch done\n");
GstCaps* video_caps = gst_caps_new_simple ("video/x-h264",
"width", G_TYPE_INT, 800,
"height", G_TYPE_INT, 480,
"framerate", GST_TYPE_FRACTION, 25,
1, NULL);
gst_app_src_set_caps(GST_APP_SRC(app->appsrc), video_caps);
/* go to playing and wait in a mainloop. */
gst_element_set_state ((GstElement*) app->pipeline, GST_STATE_PLAYING);
fprintf(stderr, "gst_element_set_state play\n");
/* this mainloop is stopped when we receive an error or EOS */
g_main_loop_run (app->loop);
fprintf(stderr, "g_main_loop_run called\n");
gst_element_set_state ((GstElement*) app->pipeline, GST_STATE_NULL);
fprintf(stderr, "gst_element_set_state GST_STATE_NULL\n");
/* free the file */
// g_mapped_file_unref (app->file);
gst_object_unref (bus);
g_main_loop_unref (app->loop);
return 0;
}
void populateApp(void *inBuf , size_t len) {
guint8 *_buffer = (guint8*) inBuf;
GstFlowReturn ret;
GstBuffer *buffer = gst_buffer_new();
GstCaps* video_caps = gst_caps_new_simple ("video/x-h264",
"width", G_TYPE_INT, 800,
"height", G_TYPE_INT, 480,
"framerate", GST_TYPE_FRACTION, 25,
1, NULL);
gst_buffer_set_caps(buffer, video_caps);
GST_BUFFER_DATA (buffer) = _buffer;
GST_BUFFER_SIZE (buffer) = len;
// g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
ret = gst_app_src_push_buffer(GST_APP_SRC(app->appsrc), buffer);
gst_buffer_unref (buffer);
}
如前所述,我是 GStreamer 的新手,因此有很多来自互联网的剪切和粘贴代码,但恕我直言,它应该可以工作。您发现任何问题吗?
最佳答案
目前尚不清楚如何调用 populateApp,但是当您有数据要推送到管道时,您需要重复调用它。这可以在与 g_main_loop_run 阻止的线程不同的线程中完成,或者您可以重组程序以避免使用 GMainLoop。
关于stream - Gstreamer - appsrc 推送模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17861041/
我正在尝试使用 gstreamer appsrc 通过网络播放视频流。 我在这里找到了很好的例子。 gstreamer appsrc test application http://amarghosh
我正在尝试学习 gstreamer appsrc 插件来从我编写的传输流解复用器播放 AV(我知道插件已经可用,我想自己做来学习)。我已经从 MPEG 传输流中提取了音频和视频基本流;现在我必须将它推
我正在开发一个 C 应用程序(在 Linux 下),它接收原始 h.264 流,并应使用 gstreamer API 可视化该流。我是 GStreamer 的新手,所以也许我犯了巨大的愚蠢错误或忽略了
我正在尝试将 GStreamer appsrc 设置为视频源,但到目前为止,即使是一个微不足道的程序也根本无法运行并且会产生随机崩溃或挂起。你能帮忙发现问题吗?最少的崩溃代码: import gst,
我想将音频缓冲区写入文件。 问题是文件始终为空或应用程序立即停止并显示内部数据流错误。 例子是: https://gist.github.com/nzjrs/725122/16ceee88aafae3
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我是 GStreamer 的新手,以下是我面临的问题 流水线 1 v4l2src device=/dev/video241 !视频/x-h264,高度=720,宽度=1280,帧率=30/1! tvc
这将是我第一次在 C 程序中使用 Gstreamer。我只使用过管道。我正在尝试编写一个程序,该程序将流存储在缓冲区中,使用 OpenCv 编辑流并使用带有 appsrc 的管道来查看流。我收到错误:
我正在尝试使用 GStreamer 呈现文本。文本是我想为视频源的每一帧更新的时间戳。然后,时间戳将覆盖在从 v4l2src 捕获的视频流上。 问题是只有第一个时间戳显示在显示输出中。管道继续运行,调
我正在尝试显示从 UDP 套接字接收到的数据(该数据已经标记为通过 AppSink 的回调) 这是我的代码,应该显示收到的数据: 静态无效gst_native_receive_video_data(J
我的源码主要来自http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-data-spoof.html
我有如下层次结构: 源流水线 GstElement 管道(有一个 videotestsrc 和 appsink) 用于推送样本的 GstAppSrc 指针数组 GstRTSP服务器 GstRTSPMe
我正在使用 GStreamer 构建我的第一个应用程序,我的任务是从互联网获取流,使用 CUDA 对其进行修改(更改像素)以并行计算帧,并输出修改后的流。 为简单起见,目前我使用MP4视频读写磁盘,不
我正在开发一个接受 Opencv 帧(源自 opencv camera Api)的应用程序,并在将它们编码为 H264 帧后尝试将这些帧发送到网络中。 对于这个项目,我被要求通过硬件执行编码。 我使用
我正在尝试使用 gstreamer 和icecast 流式传输计算机生成的视频,但我无法让 gstreamer appsrc 工作。如果我使用 xvimagesink 作为接收器,我的应用程序将按预期
我正在使用 appsrc 使用我自己的数据源实现 gstreamer 媒体播放器。一切正常,除了一件事: 当流到达它的末尾时,回调发出 "end-of-stream" 信号。信号发送函数 g_sign
我正在尝试通过 rtmp 流式传输我的网络摄像头。我尝试通过以下管道流式传输数据: gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, heigh
我正在尝试打开一个 mp4 视频,对其进行解码并将其发送到 appsink。然后从 appsrc 接收它并将其保存在 mp4 文件中。 我确信我设置的上限是错误的。 const gchar *vide
我是一名优秀的程序员,十分优秀!