1 Star 0 Fork 1

西北狼/v4l2_x264

forked from eyhxh/v4l2_x264 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <malloc.h>
#include "video_capture.h"
struct camera *cam;
pthread_t mythread;
void * capture_encode_thread(void* param) {
int count = 1;
for (;;) {
printf("\n\n-->this is the %dth frame\n", count);
if (count++ >= 100) // 采集100帧的数据
{
printf("------need to exit from thread------- \n");
break;
}
fd_set fds;
struct timeval tv;
int r;
FD_ZERO(&fds);
FD_SET(cam->fd, &fds);
/* Timeout. */
tv.tv_sec = 2;
tv.tv_usec = 0;
r = select(cam->fd + 1, &fds, NULL, NULL, &tv);
if (-1 == r) {
if (EINTR == errno)
continue;
errno_exit("select");
}
if (0 == r) {
fprintf(stderr, "select timeout\n");
exit(EXIT_FAILURE);
}
if (read_and_encode_frame(cam) != 1) {
fprintf(stderr, "read_fram fail in thread\n");
break;
}
}
return 0;
}
int main(int argc, char **argv) {
cam = (struct camera *) malloc(sizeof(struct camera));
if (!cam) {
printf("malloc camera failure!\n");
exit(1);
}
cam->device_name = "/dev/video0";
cam->buffers = NULL;
cam->width = 640;
cam->height = 480;
cam->display_depth = 5; /* RGB24 */
v4l2_init(cam);
if (0 != pthread_create(&mythread, NULL, capture_encode_thread, NULL)) {
fprintf(stderr, "thread create fail\n");
}
pthread_join(mythread, NULL);
printf("-----------end program------------");
v4l2_close(cam);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xibeilang524/v4l2_x264.git
git@gitee.com:xibeilang524/v4l2_x264.git
xibeilang524
v4l2_x264
v4l2_x264
master

搜索帮助