forked from z4yx/SimpleRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
80 lines (78 loc) · 1.61 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include "picture_t.h"
#include "simplerecorder.h"
static int recording;
static char osd_string[20];
static void gen_osd_info()
{
time_t t = time(0);
strftime(osd_string, 20, "%Y-%m-%d %H:%M:%S",localtime(&t));
}
void stop_recording(int param)
{
recording = 0;
}
int main()
{
int i;
struct picture_t pic;
struct encoded_pic_t encoded_pic;
errno = 0;
if(!camera_init(&pic))
goto error_cam;
if(!encoder_init(&pic)){
fprintf(stderr,"failed to initialize encoder\n");
goto error_encoder;
}
if(!preview_init(&pic))
goto error_preview;
if(!output_init(&pic))
goto error_output;
if(!encoder_encode_headers(&encoded_pic))
goto error_output;
if(!output_write_headers(&encoded_pic))
goto error_output;
if(!camera_on())
goto error_cam_on;
if(signal(SIGINT, stop_recording) == SIG_ERR){
fprintf(stderr,"signal() failed\n");
goto error_signal;
}
printf("Press ctrl-c to stop recording...\n");
recording = 1;
for(i=0; recording; i++){
if(!camera_get_frame(&pic))
break;
gen_osd_info();
osd_print(&pic, osd_string);
if((i&7)==0) // i%8==0
preview_display(&pic);
if(!encoder_encode_frame(&pic, &encoded_pic))
break;
applog_flush();
if(!output_write_frame(&encoded_pic))
break;
}
printf("\nrecorded %d frames\n", i);
error_signal:
camera_off();
error_cam_on:
output_close();
error_output:
preview_close();
error_preview:
encoder_close();
error_encoder:
camera_close();
error_cam:
return 0;
}