GStreamer 截取RTSP 视频帧

需求:无人机配套的某些低成本摄像机没有拍照功能,只有RTSP视频流的推送,因此可以利用GStreamer框架将视频帧进行保存,来达到拍照的效果。

思路:

在需要拍照的航点,触发信号。在GstVideoReciver.cpp 绑定此信号并进行视频帧的保存。

视频帧保存代码(某大神写的,非原创):

void GstVideoReceiver::takeMyScreenshot(const QString &imageFile)
{
    //
    gpointer widget = NULL;
    GstSample *sample=NULL;
    GstMemory* memory;
    GstMapInfo info;

    if(!_videoSink){
        return;
    }
    g_object_get(G_OBJECT(_videoSink),"widget",&widget,NULL);
    if(!widget){
        gst_println("failed to get widget");
        return;
    }

    g_object_get(G_OBJECT(_videoSink),"last-sample",&sample,NULL);
    if(!sample){
        gst_println("failed to get sample!");
        return;
    }
    GstCaps* sample_caps = gst_sample_get_caps(sample);
    if(!sample_caps){
        gst_println("failed to get sample_caps!");
        return;
    }

    int outwidth,outheight;
    GstStructure *s = gst_caps_get_structure(sample_caps,0);
    gst_structure_get_int(s,"width",&outwidth);
    gst_structure_get_int(s,"height",&outheight);
    if(outwidth<=0||outheight<=0){
        gst_println("failed to get width or height");
        return;
    }
    memory = gst_buffer_get_memory(gst_sample_get_buffer(sample),0);
    if(!memory){
        gst_println("failed to get memory!");
        return;
    }
    gst_memory_map(memory,&info,GST_MAP_READ);
    QImage save_image(info.data,outwidth,outheight,QImage::Format_RGBA8888);
    if(save_image.isNull()){
        gst_println("failed to fromData!");
        return;
    }
    gst_println("save file:%s",qPrintable(imageFile));
    if(!save_image.save(imageFile)){
        gst_println("failed to save image!");
        return;
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

土拨鼠不是老鼠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值