Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TCap v0.1
- // (C) Thomas Hargrove
- // http://toonarchive.com/tcap
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
- // Modified by Kevin 2004&2016
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <sys/mman.h>
- #include <errno.h>
- #include <libv4l1-videodev.h>
- #include "record.h"
- //#define WIDTH 640
- //#define HEIGHT 480
- #define p(x) printf("%d\n",x);
- #define E(x) printf("%s\n",x);
- static struct video_capability capability;
- static int fd = -1;
- static struct video_mbuf gb_buffers = { 2*WIDTH*HEIGHT*3, 0, {0,WIDTH*HEIGHT*3 }};
- static char *map = NULL;
- static struct video_mmap my_buf;
- struct video_channel vch;
- int main(int argc, char *argv[])
- {
- char my_video_dev[100] = "/dev/video0";
- // --------------------------------------------------------------------------
- // Get the v4l capture set up
- // --------------------------------------------------------------------------
- if (-1 == (fd = open(my_video_dev, O_RDWR))) {
- printf("Error opening device: %s\n", my_video_dev);
- goto err;
- }
- if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
- printf("Error: ioctl(fd,VIDIOCGCAP,&capability)\n");
- goto err;
- }
- vch.channel = 0;
- vch.norm = VIDEO_MODE_PAL;
- if(-1 == ioctl(fd, VIDIOCSCHAN,&vch)) {
- perror("Setting channel\n");
- goto err;
- }
- fcntl(fd,F_SETFD,FD_CLOEXEC);
- if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
- printf("Error: Error getting buffers\n");
- goto err;
- }
- map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
- if (map == NULL) {
- printf("Error: Mmap returned NULL\n");
- goto err;
- }
- // Set up out capture to use the correct resolution
- my_buf.width = WIDTH;
- my_buf.height = HEIGHT;
- my_buf.format = VIDEO_PALETTE_RGB24;
- // Tell the capture card to fill frame 0
- my_buf.frame = 0;
- if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
- printf("Error: Grabber chip can't sync (no station tuned in?)\n");
- goto err;
- }
- unsigned long freqlist[14]= {623250,45250,55250,62250,175250,182250,189250,196250,203250,210250,217250,224250};
- unsigned long freq;
- int chan;
- if (argc >= 1)
- {
- //freq = (freqlist[argv[1]]*16)/1000;
- //if ( -1 == ioctl(fd, VIDIOCSFREQ, freq) );
- //}else{
- //freq = (freqlist[0]*16)/1000;
- //if ( -1 == ioctl(fd, VIDIOCSFREQ, freq) );
- }
- int done=0;
- while ( done < RECORD )
- {
- my_buf.frame = 1;
- if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
- printf("Error: Grabber chip can't sync (no station tuned in?)\n");
- done=1;
- }
- my_buf.frame = 0;
- if (-1 == ioctl(fd, VIDIOCSYNC, &my_buf.frame)) {
- printf("Error on sync!\n");
- done=1;
- }
- record(map,"video-output");
- my_buf.frame = 0;
- if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
- printf("Error: Grabber chip can't sync (no station tuned in?)\n");
- done=1;
- }
- my_buf.frame = 1;
- if (-1 == ioctl(fd, VIDIOCSYNC, &my_buf.frame)) {
- printf("Error on sync!\n");
- done=1;
- }
- record(map,"video-output");
- done++;
- }
- // Return screen to text mode.
- err:
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment