Created
July 31, 2015 16:12
-
-
Save danieltroger/5d68aeece70714a89008 to your computer and use it in GitHub Desktop.
Video recording thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
gcc -Wall -o preview -lgphoto2 config.c focus.c preview.c | |
*/ | |
#include <signal.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdarg.h> | |
#include <string.h> | |
#include <gphoto2/gphoto2.h> | |
#include <time.h> | |
#include "samples.h" | |
#include "context.c" | |
//int grabs = 0; | |
int ex = 0; | |
int moviecapt = 0; | |
void sig_handler(int signo) | |
{ | |
if (signo == SIGUSR1) | |
{ | |
printf("Capturing movie...\n"); | |
moviecapt = 2; | |
} | |
if (signo == SIGUSR2) | |
{ | |
moviecapt = 3; | |
} | |
if(signo == SIGINT) | |
{ | |
ex = 1; | |
} | |
} | |
int | |
main(int argc, char **argv) { | |
if (signal(SIGUSR1, sig_handler) == SIG_ERR) | |
{ printf("\ncan't catch SIGUSR1\n"); | |
return -1; | |
}if (signal(SIGUSR2, sig_handler) == SIG_ERR) | |
{ printf("\ncan't catch SIGUSR2\n"); | |
return -1; | |
}if (signal(SIGINT, sig_handler) == SIG_ERR) | |
{ printf("\ncan't catch SIGINT\n"); | |
return -1; | |
} | |
Camera *canon; | |
GPContext *canoncontext = sample_create_context(); | |
int i, retval,ret;//,maxtime; | |
i = 0; | |
//int rectime = 0; | |
//if(argc > 1){maxtime = atoi(argv[1]);}else{maxtime = 15;} | |
//gp_log_add_func(GP_LOG_ERROR, errordumper, NULL); | |
gp_camera_new(&canon); | |
printf("Camera init. Takes about 10 seconds.\n"); | |
retval = gp_camera_init(canon, canoncontext); | |
if (retval != GP_OK) { | |
printf(" Retval: %d\n", retval); | |
exit (1); | |
} | |
ret = set_config_value_string (canon, "output", "3", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to set output to PC+TFT: %d\n", ret); | |
} else | |
{ | |
fprintf (stdout, "Turned on camera display\n"); | |
} | |
sleep(1); | |
settoggle(canon,TRUE,canoncontext,"capture"); | |
printf("Enabled capture\n"); | |
usleep(50000); | |
settoggle(canon,TRUE,canoncontext,"viewfinder"); | |
printf("Should have enabled viewfinder\n"); | |
usleep(50000); | |
settoggle(canon,FALSE,canoncontext,"uilock"); | |
printf("Should have disabled uilock (1)\n"); | |
usleep(50000); | |
/*int ret; | |
ret = set_config_value_string (canon, "viewfinder", "1", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to set viewfinder to 1\n"); | |
} else | |
printf("Switched to LV\n");*/ | |
while(1){ | |
/*if(grabs == 1) | |
{ | |
printf("Capturing preview...\n"); | |
grabs = 0; | |
CameraFile *file; | |
char output_file[32] = "live.jpg"; | |
retval = gp_file_new(&file); | |
if (retval != GP_OK) | |
{ | |
fprintf(stderr,"gp_file_new: %d\n", retval); | |
exit(1); | |
} | |
camera_auto_focus (canon, canoncontext); | |
retval = gp_camera_capture_preview(canon, file, canoncontext); | |
if (retval != GP_OK) { | |
fprintf(stderr,"gp_camera_capture_preview(%d): %d (couldn't capture preview, are you in photo mode?)\n", i, retval); | |
unlink("live.jpg"); | |
} | |
retval = gp_file_save(file, output_file); | |
if (retval != GP_OK) { | |
fprintf(stderr,"gp_camera_capture_preview(%d): %d (couldn't save file)\n", i, retval); | |
unlink("live.jpg"); | |
} | |
gp_file_unref(file); | |
i++; | |
}*/ | |
if(moviecapt == 3) | |
{ | |
ret = set_config_value_string (canon, "output", "3", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to set output to PC+TFT: %d\n", ret); | |
} else | |
{ | |
fprintf (stdout, "Turned on camera display\n"); | |
} | |
ret = set_config_value_string (canon, "movierecordtarget", "None", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to stop recording: %d\n", ret); | |
} else | |
{ | |
fprintf (stdout, "Stopped recording...\n"); | |
moviecapt = 0; | |
} | |
} | |
if(moviecapt == 2) | |
{ | |
ret = set_config_value_string (canon, "output", "3", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to set output to PC+TFT: %d\n", ret); | |
} else | |
{ | |
fprintf (stdout, "Turned on camera display\n"); | |
} | |
settoggle(canon,TRUE,canoncontext,"viewfinder"); | |
printf("Should have enabled viewfinder\n"); | |
ret = set_config_value_string (canon, "movierecordtarget", "Card", canoncontext); | |
if (ret < GP_OK) { | |
fprintf (stderr, "Failed to start recording: %d\n", ret); | |
} else | |
{ | |
fprintf (stdout, "Recording...\n"); | |
moviecapt = 1; | |
} | |
} | |
usleep(50000); | |
if(ex == 1) {gp_camera_exit(canon, canoncontext); gp_camera_free (canon);return 0;} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment