[gstreamer ]如何从 gstplugin 更改视频分辨率

[gstreamer ]How to change the video resolution from gstplugin

我正在编写一个 gstreamer 插件来在高清视频帧上渲染摄像机视频(高度=480,宽度=640,格式 UYVY)。在我的链函数 (gst_plugin_template_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)) 中,我可以看到 buf 大小为 480x640x2。我分配了一个相当于全高清的新缓冲区,并将此 UYVY 数据复制到新缓冲区之上并替换了现有缓冲区。但是输出视频还是height=480,width=640.

这是代码片段。

gst_plugin_template_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
  GstPluginTemplate *filter;
  GstMapInfo map;
  guchar *data;
  gint width = 640, height = 480;
  GstMemory *mem;
  int row = 0;

  filter = GST_PLUGIN_TEMPLATE (parent);
  gst_buffer_map (buf, &map, GST_MAP_READWRITE);


  mem = gst_allocator_alloc(NULL, 4147200, NULL); //1080*1920*2 (Full HD UYVY) = 4147200
  GstMapInfo info_out;
  gst_memory_map(mem, &info_out, GST_MAP_WRITE);


 for(int i = 0; i < 480 ; i++) {
    memcpy(info_out.data + row, map.data + row, 1280);
    row += 1280; //640*2
  }

  gst_buffer_replace_all_memory(buf, mem);

  gst_buffer_unmap (buf, &map);
  gst_memory_unmap(mem, &info_out);

  return gst_pad_push (filter->srcpad, buf);
}
 

您需要向下游发送一个新的 CAPS 事件。可能您想要 gst_event_new_caps() 并将其推入源板。但是请仔细检查您想要的文档。

感谢 Florian Zwoch 的支持。添加以下更改后,它现在可以正常工作了。

从 gst_my_filter_sink_event.

调用了自定义 gst_my_filter_setcaps(过滤器、上限)