linux下webcam进行录像, gstreamer架构

本文档展示了如何在Linux环境下使用Gstreamer框架进行摄像头录像。通过Gstreamer的不同组件,如v4l2src、ffmpegcolorspace、theoraenc和filesink,创建了一个从摄像头捕获视频,进行颜色空间转换,编码并保存到文件的管道。代码中包含了错误处理、视频帧率设置和文件输出位置的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

author: CarlsonLee(carlsonlee.freec@hotmail.com), 本代码是freecamera的一部分,freecamera源代码存在:http://gitorious.org/freecamera

#include <glib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <gst/app/gstappsrc.h>
#include <gst/app/gstappbuffer.h>

#include "cam_midware.h"
#include "cam_global.h"
#include "cam_display.h"
#include "cam_files.h"
#include "color_space.h"
#include "review_data.h"
#include "cam_ui.h"
#include "cam_utils.h"
#include "cam_err.h"

#define SKIP_FRAMES 10
static struct tag_CAM_MW_DATA
{
    gint               camera_status;
    GMainLoop*      video_cap_loop;
    char*            filename;
    gint             skip_frames;
    GMutex*            mutex;
}cam_video_data;

static gboolean video_bus_call (GstBus     *bus,
                       GstMessage *msg,
                       gpointer    data)
{
    GMainLoop *loop = (GMainLoop *) data;

    bus = bus;
    switch (GST_MESSAGE_TYPE (msg))
    {
    case GST_MESSAGE_EOS:
        g_main_loop_quit (loop);
        break;
    case GST_MESSAGE_ERROR:
        {
            gchar *debug;
            GError *error;
            gst_message_parse_error (msg, &error, &debug);
            g_print ("Error**##: %s, %s/n", error->message, debug);
            g_free (debug);
            g_error_free (error);
            g_main_loop_quit (loop);
        }
        break;
    default:
        break;
    }
    return TRUE;
}

static gboolean link_video_cap_src(GstElement *src, GstElement *sink)
{
    gboolean link_ok = FALSE;
    GstCaps *caps;
      guint width = cam_global_data.cam_res.video_res[cam_global_data.cam_res.video_res_cur].width;
    guint height = cam_global_data.cam_res.video_res[cam_global_data.cam_res.video_res_cur].height;
    caps = gst_caps_new_simple ("video/x-raw-yuv",
            "width", G_TYPE_INT, width,
            "height", G_TYPE_INT, height, NULL);
    link_ok = gst_element_link_filtered (src, sink, caps);
    gst_caps_unref (caps);
    return link_ok;
}

static gboolean link_video_cap_pp(GstElement *src, GstElement *sink)
{
    gboolean link_ok = FALSE;
    GstCaps *caps;
 
      guint width = cam_global_data.cam_res.video_res[cam_global_data.cam_res.video_res_cur].width;
      guint height

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值