资源简介
在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模拟器安装文档
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- JM阅读笔记(学习H264)
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- h264 ip核,经过asic验证
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- delphi摄像头拍照
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
评论
共有 条评论