1 Star 0 Fork 135

茶浓 / Camkit

forked from andyspider / Camkit 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

Camkit (Camera toolKit)

Camkit是一个摄像头相关的工具箱,使用C语言写成,包含了从:图像采集-->色彩转换-->H264编码-->RTP打包-->网络发送的全套接口。

可到项目附件中下载已编译好的二进制版本。

编译

Camkit采用cmake构建系统,编译之前请确认已经安装了cmake。

遵循以下步骤完成编译和安装:

```shell
cd Camkit_source_dir
mkdir build
cd build
cmake ../ -Dkey=value
make
make install
```

其中**-Dkey=value**是可以配置的选项,支持的选项如下:

1. DEBUG=ON|OFF,是否打开调试选项
2. PLAT=FSL|RPI|PC, 选择所使用的平台(Freescale IMX, Raspberry Pi或PC),具体见下文
3. CMAKE_TOOLCHAIN_FILE=cross_file,用于交叉编译,具体见下文

Camkit的视频采集采用标准的V4L接口,通常的USB摄像头均可以支持。

Camkit的色彩转换和H264编码支持三种平台,分别是是:

1. PC Desktop(采用ffmpeg编码,依赖于ffmpeg中的libavutil、libavcodec和libswscale库)
2. Raspberry Pi (采用GPU加速,依赖于vcos,vcsm, bcm_host, openmaxil等库)
3. Freescale I.MX6 (采用IPU和VPU硬编码,依赖于ipu和vpu)

PC平台编译安装

使用ffmpeg编码,Camkit可以在PC上使用,原则上应该是跨平台的,但由于作者的开发主要是在Linux上完成,其他平台未经测试,今后有时间再做移植。下面主要介绍如何在Linux上编译安装。

在Linux上编译安装非常简单,以Ubuntu为例,首先安装编译环境:

```
sudo apt-get install cmake libavcodec54 libavcodec-dev libswscale2 libswscale-dev libavutil52 libavutil-dev #库的版本号可有会有变化,请根据不同的系统做调整
```

然后遵循上面的构建步骤,使用如下命令构建和编译:

```
mkdir build
cd build
cmake ../
make 
make install
```

安装完成将在你的电脑上创建3种文件:1. cktool工具;2. libcamkit.so库,3.开发头文件。程序的默认安装路径为/usr/local,可通过在构建时添加-DCMAKE_INSTALL_PREFIX=where选项指定其他路径。

树莓派平台编译安装

要在树莓派上使用可以选择在PC上交叉编译,也可将源代码拷到树莓派上直接编译,这里介绍后一种方式。

首先用scp之类的工具将Camkit的源代码拷到树莓派上,进入源码目录。由于树莓派运行的也是Linux系统,原则上可以和PC上一样使用ffmpeg库,但是实际效果非常卡顿,每秒仅有1~2帧,cpu消耗90%左右,因此推荐使用针对树莓派的GPU加速方案,下面是编译说明。

使用GPU加速需要一些头文件和库,这些库一般都在/opt/vc/目录下,不需要另外安装。

编译过程非常简单,进入Camkit源码目录,使用如下命令编译安装:

``` 
mkdir build
cd build
cmake ../ -DPLAT=RPI
make 
make install
```

这样,Camkit就已经安装到你的树莓派上了,路径和PC上的相同。

飞思卡尔平台编译安装

待写

使用

Camkit的接口非常简单方便,每个子功能均遵循类似的接口。

```C
xxxHandle = xxx_open(xxParams);     // 打开xxx handle,例如: capture_open, convert_open...
...                     // 具体操作
xxx_close(xxxHandle);    // 关闭handle,例如capture_close, convert_close...
```

一般调用步骤如下:

```C
struct cap_handle *caphandle = NULL;    // capture操作符
struct cvt_handle *cvthandle = NULL;   // convert操作符
struct enc_handle *enchandle = NULL;   // encode操作符
struct pac_handle *pachandle = NULL;   // pack操作符
struct net_handle *nethandle = NULL;   // network操作符

struct cap_param capp;      // capture参数
struct cvt_param cvtp;      // convert参数
struct enc_param encp;      // encode参数
struct pac_param pacp;      // pack参数
struct net_param netp;      // network参数

// 设置各项参数
capp.xxx = xxx
...
cvtp.xxx = xxx;
...
encp.xxx = xxx;
...
pacp.xxx = xxx;
...
netp.xxx = xxx;
...

// 使用设置好的参数打开各项功能
caphandle = capture_open(capp);
cvthandle = convert_open(cvtp);
enchandle = encode_open(encp);
pachandle = pack_open(pacp);
nethandle = net_open(netp);
    
capture_start(caphandle);       // 开始capture
while(1)
{
    capture_get_data(caphandle, ...);    // 获取一帧图像
    
    convert_do(cvthandle, ...);    // 转换,YUV422=>YUV420, 如果你的摄像头直接支持采集YUV420数据则不需要这一步
    
    while (encode_get_headers(enchandle, ...) == 1)     // 获取h264头,PPS/SPS
    {
    ...
    }
    
    encode_do(enchandle, ...);      // 编码一帧图像
    
    pack_put(pachandle, ...);   // 将编码后的图像送给打包器
    while(pack_get(pachandle, ...) == 1)    // 获取一个打包后的RTP包
    {
        net_send(nethandle, ...);   // 将RTP包发送出去
    }
}
capture_stop(caphandle);        // 停止capture

// 关闭各项功能
net_close(nethandle);
pack_close(pachandle);
encode_close(enchandle);
convert_close(cvthandle);
capture_close(caphandle);
```

Note:

  1. 其中的每一个子功能都可以独立使用,例如只做采集,或者图像编码之后写入文件而不做打包和发送等等。
  2. 如果是使用官方的树莓派摄像头,则采集部分不可用,需要另外写代码,但后面的编码打包等功能均可正常使用。

PS: src目录有两个完整的例子,可以参考之。

实例--在树莓派上运行cktool查看实时录像

src/cktool.c是运用Camkit的一个工具,实现了Camkit支持的全部功能。

使用方法:

$cktool [options]

options:

  1. -? 显示帮助信息
  2. -d 是否显示调试信息,每一步操作都用一种符号打印表示。
  3. -s 设置步骤 0/1/3/7/15 (0:只做采集, 1:采集+转换, 3:采集+转换+编码(默认), 7:采集+转换+编码+打包, 15:采集+转换+编码+打包+发送)
  4. -i 设置打开的摄像头设备(默认/dev/video0)
  5. -o 设置写入的文件(配合-s选项可以写入各个阶段的数据,方便调试)
  6. -a 设置网络端的ip地址
  7. -p 设置网络端的端口号
  8. -c 设置采集图像格式: 0: YUYV(默认), 1: YUV420
  9. -w 设置视频宽 (640)
  10. -h 设置视频高 (480)
  11. -r 设置编码帧率 kbps (1000)
  12. -f 设置帧率 (15)
  13. -t 设置图像是否交织 (0)
  14. -g 设置编码的gop大小 (12)

假设我们要在树莓派上使用Camkit,将树莓派和PC连在同一个路由器上。

RPI(Camkit) <==> 路由器 <==> PC (VLC)

首先,按照上面的讲解完成编译、安装。

配置树莓派开启摄像头支持并分配gpu_memRaspbian系统通过sudo raspi-configArch系统参见Wiki

然后,在PC上用记事本打开video.sdp文件,修改ip地址为PC的ip地址,假设为192.168.1.2,设置端口,假设为8888。运行VLC播放器,打开demo/video.sdp文件。

最后,在树莓派上运行:

#cktool -s 15 -a 192.168.1.2 -p 8888 

至此,应该就可以在PC端的VLC窗口库看到树莓派的实时视频了。

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

Camkit是一个摄像头相关的工具箱,使用C语言写成,包含了从:图像采集-->色彩转换-->H264编码-->RTP打包-->网络发送的全套接口。 展开 收起
C
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/chanong/Camkit.git
git@gitee.com:chanong/Camkit.git
chanong
Camkit
Camkit
master

搜索帮助

14c37bed 8189591 565d56ea 8189591