本帖最后由 Linux- 于 2015-6-24 16:50 编辑
各位,大神。最近在做V4l2采集视频, 使用的摄像头是ov7670. Cubieboard2+DVK521拓展板子。使用发行版是: cb2 debian server
使用这里程序已经能通过V4l2 采集视频显示到VGA上面:
http://dl.cubieboard.org/parteners/waveshare/Source_Code/a20-cubieboard-dvk/Driver%20and%20API/API/camera_test_vga/
接下来想通过修改上面连接的代码,把采集到视频保存到一个 文件test.yuv. 程序已经改好, 修改记录如下, 详细代码文件字数限制了上传到附件,见附件:
在ubuntu 12.04 使用ffplay播放:
$ffplay -f rawvideo -video_size 320*240 test.yuv
播放绿屏
修改记录- diff --git a/test_camera.c b/test_camera.c
- index 63e13e6..363cc6b 100644
- --- a/test_camera.c
- +++ b/test_camera.c
- @@ -48,12 +48,12 @@
- #include "include/video/sunxi_disp_ioctl.h"//modify this
-
- //#define READ_NUM 5000
- -#define DISPLAY
- #define LCD_WIDTH 1024
- #define LCD_HEIGHT 768
-
- #define CLEAR(x) memset (&(x), 0, sizeof (x))
-
- +char *filename = "test.yuv\0";
- int count;
-
- struct buffer {
- @@ -71,7 +71,7 @@ static int fd = -1;
- struct buffer * buffers = NULL;
- static unsigned int n_buffers = 0;
-
- -FILE *file_fd;
- +FILE *fp;
- static unsigned long file_length;
- static unsigned char *file_name;
-
- @@ -381,6 +381,9 @@ enum v4l2_ctrl_type qc_ctrl[]=
- (V4L2_CID_BASE+31)
- };
-
- +static void process_image(const void * p, int size) {
- + fwrite(p, size, 1, fp);
- +}
- static int read_frame (void)
- {
- struct v4l2_buffer buf;
- @@ -402,11 +405,12 @@ static int read_frame (void)
- // printf ("buf.index dq is %d,\n",buf.index);
- // printf ("buf.m.offset = 0x%x\n",buf.m.offset);
- //disp_set_addr(320,240,&buf.m.offset);
- - disp_set_addr(disp_size.width, disp_size.height,&buf.m.offset);
- +// disp_set_addr(disp_size.width, disp_size.height,&buf.m.offset);
-
- //printf ("press ENTER to continue!\n");
- //getchar();
- //fwrite(buffers[buf.index].start, buffers[buf.index].length, 1, file_fd);
- + process_image(buffers[buf.index].start, buffers[buf.index].length);
-
-
-
- @@ -716,8 +720,8 @@ int main_test (void)
- //goto close;
- }
-
- - disp_size.width = fmt.fmt.pix.width;
- - disp_size.height = fmt.fmt.pix.height;
- +// disp_size.width = fmt.fmt.pix.width;
- + //disp_size.height = fmt.fmt.pix.height;
-
- // printf("%s %d\n",__FILE__,__LINE__);
- if(ioctl_test==1)
- @@ -829,11 +833,6 @@ int main_test (void)
- printf ("VIDIOC_QBUF failed\n");
- }
-
- -#ifdef DISPLAY
- - disp_int(disp_size.width,disp_size.height);
- - disp_start();
- -#endif
- -
- type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- if (-1 == ioctl (fd, VIDIOC_STREAMON, &type))
- @@ -846,10 +845,11 @@ int main_test (void)
- else
- printf ("VIDIOC_STREAMON ok\n");
-
- - count = read_num;
- + fp = fopen(filename, "wa+");
- + count = 100;
-
- -// while(count-->0)
- - while(1)
- + while(count-->0)
- +// while(1)
- {
- //gettimeofday(&time_test,&tz);
-
- @@ -876,16 +876,13 @@ int main_test (void)
- if (0 == r) {
- fprintf (stderr, "select timeout\n");
- exit (EXIT_FAILURE);
- - }
- + }
-
- -#ifdef DISPLAY
- - if(count==read_num-1)
- - disp_on();
- -#endif
- if (read_frame ())
- break;
- }
- }
- + fclose(fp);
-
- if(control_test==1)
- {
- @@ -987,10 +984,6 @@ unmap:
- printf ("munmap error");
- }
- }
- - disp_stop();
- - disp_quit();
- -
- -
-
- close (fd);
-
复制代码
|