资源简介
将mjpeg-streamer流,保存为视频文件。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “jpg.h“
#include “capture.h“
#include “h264encoder.h“
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
static char *video_name=“/dev/video0“;
static int video_fd = -1;
int h264_fd;
//static unsigned int number = 0;
//static unsigned long file_length;
//static unsigned char *file_name;
Encoder en;
uint8_t *h264_buf = NULL;
int count_flag = 1;
void open_video_device (void) //创建视频文件,打开摄像头。
{
struct stat st; //store the device information
//get the device information
if (-1 == stat(video_name&st))
{
fprintf(stderr “ Cannot identify ‘%s‘: %d %s\n“
video_nameerrnostrerror(errno));
exit(EXIT_FAILURE);
}
// test the device is or isn‘t a special character file
// because the camera device is a charcter file on linux
if (!S_ISCHR(st.st_mode))//if it isn‘t character file enter if
{
fprintf(stderr“%s is no device \n“video_name);
exit(EXIT_FAILURE);
}
//open device on the read write and nonblock mode
if (-1 == (video_fd = open(video_nameO_RDWR | O_NONBLOCK0)))
{
fprintf(stderr“Cannot open ‘%s‘ : ‘%d‘%s \n“
video_nameerrnostrerror(errno));
exit(EXIT_FAILURE);
}
else
printf(“camera device is open OK ! camera name is %s \n“
video_name);
}
void query_video_device (void)
{
struct v4l2_capability cap;
/* It is used to identify kernel devices compatible with this specification and to abtain information about driver and hardware capabilities*/
if (-1 == ioctl (video_fd VIDIOC_QUERYCAP&cap)) /* 获取设备支持的操作 */
{
perror(“VIDIOC_QUERYCAP:“);
exit (EXIT_FAILURE);
}
//其中域 capabilities 代表设备支持的操作模式,
//常见的值有 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING 表示是一个视频捕捉设备并且具有数据流控制模式;
//另外 driver 域需要和 struct video_device 中的 name 匹配。
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
fprintf(stderr “%s is no video capture device\n“video_name);
exit(EXIT_FAILURE);
}
else
{
printf(“%s is a video capture device!\n“video_name);
}
if (!(cap.capabilities & V4L2_CAP_READWRITE))
{
fprintf(stderr “%s does not support read i/o\n“video_name);
}
else
{
printf(“%s support read i/o !\n“video_name);
}
if (!(cap.capabilities & V4L2_CAP_STREAMING))
{
fprintf(stderr“%s does not support streaming i/o\n“video_name);
}
else
{
printf(“%s supports streaming i/o method!\n“video_name);
}
printf(“The driver name is %s\n“cap.driver);
printf(“The device name is %s\n“cap.card);
printf(“The device bus is %s\n“cap.bus_info);
}
void change_video_properties(void) // 设置特性
{
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
CLEAR(cropcap);
cropcap.type = V4L2_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1069831 2013-12-13 16:10 farsight_camera_arm\bin\cl_camera
文件 12408 2013-12-09 14:03 farsight_camera_arm\capture.c
文件 575 2013-12-02 11:45 farsight_camera_arm\capture.h
文件 40212 2013-12-13 16:10 farsight_camera_arm\capture.o
文件 3045 2013-12-01 16:14 farsight_camera_arm\h264encoder.c
文件 574 2012-11-13 20:51 farsight_camera_arm\h264encoder.h
文件 17104 2013-12-13 16:10 farsight_camera_arm\h264encoder.o
文件 1616 2013-11-23 16:02 farsight_camera_arm\include\jconfig.h
文件 12714 2009-11-20 16:01 farsight_camera_arm\include\jmorecfg.h
文件 48475 2009-11-16 19:44 farsight_camera_arm\include\jpeglib.h
文件 40915 2013-12-02 13:23 farsight_camera_arm\include\x264.h
文件 245 2012-04-17 13:43 farsight_camera_arm\include\x264_config.h
文件 3583 2013-12-02 09:42 farsight_camera_arm\jpg.c
文件 940 2013-12-13 16:10 farsight_camera_arm\jpg.h
文件 19024 2013-12-13 16:10 farsight_camera_arm\jpg.o
文件 1096477 2013-11-23 16:07 farsight_camera_arm\lib\libjpeg.so
文件 1115908 2012-11-15 15:27 farsight_camera_arm\lib\libx264.a
文件 1046287 2012-11-15 15:27 farsight_camera_arm\lib\libx264.so.120
文件 1115908 2012-11-15 15:27 farsight_camera_arm\lib\pkgconfig\libx264.a
文件 1046287 2012-11-15 15:27 farsight_camera_arm\lib\pkgconfig\libx264.so
文件 1046287 2012-11-15 15:27 farsight_camera_arm\lib\pkgconfig\libx264.so.120
文件 278 2012-11-15 15:27 farsight_camera_arm\lib\pkgconfig\x264.pc
文件 1533 2013-12-02 11:37 farsight_camera_arm\main.c
文件 5624 2013-12-13 16:10 farsight_camera_arm\main.o
文件 315 2013-12-02 13:34 farsight_camera_arm\Makefile
文件 34381 2013-11-26 21:00 farsight_camera_arm\tags
目录 0 2013-12-18 18:41 farsight_camera_arm\lib\pkgconfig
目录 0 2013-12-18 18:41 farsight_camera_arm\bin
目录 0 2013-12-18 18:41 farsight_camera_arm\include
目录 0 2013-12-18 18:41 farsight_camera_arm\lib
............此处省略4个文件信息
评论
共有 条评论