资源简介
Linux下通过v4l2技术采集USB摄像头的视频,然后通过x264编码器编码成视频储存起来
代码片段和文件信息
#include “cam.h“
#include “x264_encode.h“
#include “net.h“
int usTimer(long us)
{
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = us;
return select(0NULLNULLNULL&timeout);
}
int yuyv_to_yuv420p(const unsigned char *in unsigned char *out unsigned int width unsigned int height)
{
unsigned char *y = out;
unsigned char *u = out + width*height;
unsigned char *v = out + width*height + width*height/4;
unsigned int ij;
unsigned int base_h;
unsigned int is_y = 1 is_u = 1;
unsigned int y_index = 0 u_index = 0 v_index = 0;
unsigned long yuv422_length = 2 * width * height;
//序列为YU YV YU YV,一个yuv422帧的长度 width * height * 2 个字节
//丢弃偶数行 u v
for(i=0; i {
*(y+y_index) = *(in+i);
y_index++;
}
for(i=0; i {
base_h = i*width*2;
for(j=base_h+1; jse_h+width*2; j+=2)
{
if(is_u){
*(u+u_index) = *(in+j);
u_index++;
is_u = 0;
}
else{
*(v+v_index) = *(in+j);
v_index++;
is_u = 1;
}
}
}
return 1;
}
int open_cam()
{
struct v4l2_capability cap;
cam_fd = open(DEV_NAME O_RDWR | O_NONBLOCK 0); //非阻塞方式打开摄像头
if (cam_fd < 0)
{
perror(“open device failed!“);
return -1;
}
/*获取摄像头信息*/
if (ioctl(cam_fd VIDIOC_QUERYCAP &cap) < 0)
{
perror(“get info failed!“);
return -1;
}
printf(“Driver Name:%s\n Card Name:%s\n Bus info:%s\n version:%d\n capabilities:%x\n \n “ cap.driver cap.card cap.bus_infocap.versioncap.capabilities);
if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE)
{
printf(“Device %s: supports capture.\n“DEV_NAME);
}
if ((cap.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING)
{
printf(“Device %s: supports streaming.\n“DEV_NAME);
}
return 0;
}
int set_cap_frame()
{
struct v4l2_format fmt;
/*设置摄像头捕捉帧格式及分辨率*/
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = WIDTH;
fmt.fmt.pix.height = HEIGHT;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; //图像存储格式设为YUYV(YUV422)
if (ioctl(cam_fd VIDIOC_S_FMT &fmt) < 0)
{
perror(“set fmt failed!“);
return -1;
}
printf(“fmt.type:%d\n“fmt.type);
printf(“pix.pixelformat:%c%c%c%c\n“ \
fmt.fmt.pix.pixelformat & 0xFF\
(fmt.fmt.pix.pixelformat >> 8) & 0xFF \
(fmt.fmt.pix.pixelformat >> 16) & 0xFF\
(fmt.fmt.pix.pixelformat >> 24) & 0xFF);
printf(“pix.width:%d\n“fmt.fmt.pix.width);
printf(“pix.height:%d\n“fmt.fmt.pix.height);
printf(“pix.fiel
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-26 14:04 v4l2_h264\
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\UVC_record\
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\
文件 297 2016-07-27 14:20 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\Makefile
文件 34536 2016-07-27 11:17 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\avilib.c
文件 6258 2016-07-27 11:17 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\avilib.h
文件 50552 2016-07-27 14:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\avilib.o
文件 69072 2016-07-27 14:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\camera_MJPEG
文件 2349 2016-07-27 14:13 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\main.c
文件 19848 2016-07-27 14:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\main.o
文件 8844 2016-07-27 12:06 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\video_capture.c
文件 1357 2016-07-27 11:18 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\video_capture.h
文件 30080 2016-07-27 14:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_1\video_capture.o
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\
文件 350 2016-07-27 18:00 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\Makefile
文件 34536 2016-07-27 11:17 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\avilib.c
文件 6258 2016-07-27 11:17 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\avilib.h
文件 4012 2015-11-17 15:01 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\color.c
文件 2902 2015-11-17 15:01 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\color.h
文件 308 2016-07-27 14:59 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\for_MJPEG
文件 3644 2016-07-27 17:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\h264encoder.c
文件 573 2016-07-26 15:31 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\h264encoder.h
文件 5652 2015-11-17 15:01 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\huffman.h
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\include\
文件 40894 2016-07-26 15:20 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\include\x264.h
文件 245 2012-04-17 13:43 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\include\x264_config.h
目录 0 2019-03-26 14:04 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\lib\
文件 1026684 2012-04-29 15:42 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\lib\libx264.a
文件 1495 2016-07-27 18:24 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\main.c
文件 28788 2016-07-18 18:22 v4l2_h264\UVC_record_ubuntu\UVC_record\uvc_avilib_2\utils.c
............此处省略97个文件信息
- 上一篇:中科大软件学院考研复试
- 下一篇:简单的struts2增删改查
相关资源
- h264编码解码源代码
- linux 使用jrtplib收发h.264视频文件
- V4L2采集YUYV数据x264编码成H264视频
- X264编码H264视频
- h264转mp4 VC代码
- live555 RTSP RTCP RTP。live555类关系图,
- linux系统下基于QT的usb摄像头视频采集
- usb摄像头在ARM上的测试程序
- linux下关于Qt界面的摄像头v4l2操作源码
- Linux PC下UVC摄像头采集并用x264进行编
- USB摄像头拍照获取图片识别条形码
- 一个可以解码并实时播放H264的播放器
- A10-rtsph264_硬件编码.zip
- GB28181 代码Linux
- H264流媒体RTP打包源代码和相关资料
- 全志平台硬编硬解附带资料
- 使用DirectShow驱动H264/265格式输出的U
- H.264-AVC-ISO_IEC_14496-10
- aac+h264封装MP4
- 树莓派人脸识别USB摄像头
- h264+ffmpeg+opencv开发手册
- linux+QT下基于RTP协议的实时视频传输客
- v4l2采集+yuyv转yuv420p+h264编码+tcp传输
- qt+directshow usb摄像头及音频设备录制视
- h264_JM源码
- dolby杜比5.1测试视频
- 接收RTP包保存为h264文件
- H264+ffmpeg解码+VFW播放
- 播放mp4视频,有声音无图像,AVC(H
- H264编解码rtp发送
评论
共有 条评论