有没有办法根据用户需求从gstreamer流中捕获屏幕截图?

问题描述 投票:0回答:2

所以我的情况是我有一个 gstreamer 管道(更准确地说是 Deepstream),它从 C++ 程序运行,我有一个检查用户命令的函数,并且我能够以这种方式暂停/恢复管道。我的问题是有没有办法同样从管道的视频流中获取屏幕截图?

c++ gstreamer nvidia-deepstream deepstream
2个回答
0
投票

如果您想检查视频是否通过管道,请在管道中使用“identity dump=1”元素。如果视频实际上在插入此标识元素的点通过,这将以十六进制转储方式显示帧。


0
投票

最简单的答案是在管道中的某个位置添加一个焊盘探针,并根据您的标志存储或忽略缓冲区。一个例子是这样的:

static GstPadProbeReturn 
pad_cb(GstPad *pad, GstPadProbeInfo *info, gpointer u_data){
    // for simplicity i am ignoring any safety checks here
    if(!SHOULD_SAVE_IMG) return GST_PAD_PROBE_OK;
    GstBuffer *buf = (GstBuffer *) info->data;
    GstMapInfo in_map;
    gst_buffer_map(buf, &map, GST_MAP_READ);
    
    unsigned char *buffer = (unsigned char *)in_map.info;
    //either use openCV to store image or if at this point the 
    //buffer is already encoded you could directly write this
    //to a file using standard C/C++ apis
    //...
    return GST_PAD_PROBE_OK;
}

选择上述方法,请注意缓冲区当前的位置和格式,如果使用 openCV 获取有关其深度的正确 Mat 类型,则可能需要进行一些思考,如果您正在运行 nvstreammux,则尤其如此,因为流将采用 NV12 格式。

其他替代方案的设置会稍微复杂一些。特别是,您可以利用 valve 元素及其 drop 属性与 tee 元素的组合。通过这种方式,只需在valve的水槽中放置一个简单的探头,您就可以轻松启用或禁用分支。示例管道如下所示。

/*
src -> ... -> tee -> valve -> nvjpegenc -> multifilesink
                  -> (your pipeline to display the video)
*/
static GstPadProbeReturn
valve_sink_pad_probe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data){
    gboolean is_drop;
    g_object_get(G_OBJECT(valve),
                "drop", &is_drop,
                NULL);
    //change only if different
    if(is_drop == SHOULD_SAVE_IMG){
        g_object_set(G_OBJECT(valve),
                    "drop",
                    !is_drop,
                    NULL);
        //flip value (only if is true) so 
        //that only the next time drop is
        //automatically set to true
        //achieving the "screenshot" effect
        SHOULD_SAVE_IMG = SHOULD_SAVE_IMG ? !SHOULD_SAVE_IMG : SHOULD_SAVE_IMG;
    }
    return GST_PAD_PROBE_OK;
}

事实上,您正在使用 Deepstream,在上述管道中,nvjpegenc 期望帧缓冲区采用 NV12 或 I420 格式,因此,如果流尚未采用该格式,则需要 nvstreammuxnvvideoconverter

© www.soinside.com 2019 - 2024. All rights reserved.