资源简介
在LinuxPC下使用UVC摄像头采集视频,并用X264压缩成H264格式。这个只是一个初级的程序,只是实现了功能
代码片段和文件信息
/* include head_files*/
#include
#include
#include
#include
#include
#include //low_level i/o
#include
#include
#include
#include
#include
#include
#include
#include
#include //for videodev2.h
#include
#include “capture.h“
//****************changed by zzy***************************
#include “h264encoder.h“
//*********************************************************
struct buffer{
void * start;
size_t length;
};
static char * video_name = “/dev/video0“;
static int video_fd = -1;
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
static unsigned int number = 0;
//*************************changed by zzy*****************
Encoder en;
uint8_t *h264_buf = NULL;
//***********************add by zzy***********************
int count_flag = 1;
int file_fd;
int h264_fd;
void process_video_image(const void * punsigned int size)
{
int write_size;
int h264_length = 0;
h264_buf = (uint8_t *) malloc(sizeof(uint8_t) * 320 * 240 * 3); // 设置缓冲区
//**********************changed by zzy***************************
//**********************进行H264编码yuv的大小为320*240*2************************
//encode_frame(p320*240*2);
h264_length = compress_frame(&en -1 (uint8_t *)p h264_buf);
//**********************changed by zzy****************************
//**********************写yuv文件*********************************
write_size=write(file_fdpsize);
printf(“write_size = %d\n“write_size);
//**********************写h264文件*********************************
if (h264_length > 0) {
write_size=write(h264_fdh264_bufh264_length);
printf(“write_size = %d\n“write_size);
}
free(h264_buf);
}
int read_video_frame (void)
{
struct v4l2_buffer buf;
unsigned int size;
CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
size = buffers[buf.index].length;
//********************change by zzy**********************************
printf(“buffers.length=%dcount_flag = %d\n“buffers[buf.index].lengthcount_flag);
count_flag++;
if (-1 == ioctl(video_fdVIDIOC_DQBUF&buf))
{
perror(“VIDIOC_DQBUF:“);
exit(EXIT_FAILURE);
return 0;
}
assert (buf.index < n_buffers);
process_video_image (buffers[buf.index].startsize);
if (-1 == ioctl(video_fdVIDIOC_QBUF&buf))
{
perror(“VIDIOC_QBUF:“);
exit(EXIT_FAILURE);
}
return 1;
}
void read_video_loop(void)
{
unsigned int count ;
//****************************change by zzy*******************************
//count = 20;
count = 20;
while(count-- > 0)
{
for (;;)
{
fd_set fds;
struct timeval tv;
int r;
FD_ZERO(&fds);
FD_SET(video_fd&fds);
//timeout = 2sec
tv.tv_sec = 5;
tv.tv_usec = 0;
r = select(video_fd+1&fdsNULLNULL&tv);
if (-1 == r)
{
- 上一篇:WCS Socket 通讯源码
- 下一篇:NetApp模拟器安装文档
相关资源
- USB摄像头拍照获取图片识别条形码
- 一个可以解码并实时播放H264的播放器
- CCM手机摄像头培训资料.ppt
- opencv 、directshow捕获摄像头实时播放
- QT+ffmpeg+多摄像头+实时Ubuntu直接可用(
- ZYNQ开发全过程概览
- Shell Programming in Unix Linux and OS X(4th)
- DELL Md3600F linux配置多路径_rac
- Linux笔记 liunx入门教程
- LINUX内核总结PPT课件(修改版)
- BT软件开发完整版
- 精通Linux_第2版清晰完整pdf
- lv_pc_simulator.rar
- Zabbix分布式监控配置使用手册v3
- BCM2837- 树莓派3B 芯片手册.pdf
- rpm-4.11.2
- 老男孩Linux运维笔记高清版,实用有价
- OV7725OV7670MT9D111MT9M111等摄像头采集数据
- 2016海康威视摄像头监控web端+插件 亲
- 山东大学linux实验.zip
- Advanced Tool Kit软件(FSL_ATK_TOOL_WINS_ST
- Linux 目录结构及文件基本操作
- 安装、配置、编译Linux内核
- Linux Device Drivers 3rd(中文版-很好)
- gcc-g77-3.4.6-3.i386.rpm
- 嵌入式LINUX课程设计
- 奥比中光深度摄像头NiViewer.exe
- Sed & Awk 2nd edition
- seLinux详解
- 庞丽萍-操作系统原理与Linux系统实验
评论
共有 条评论