29 #include <sys/types.h> 40 #define FREENECT_FRAME_W 640 41 #define FREENECT_FRAME_H 480 54 fwrite(data, data_size, 1, fp);
57 void dump_rgb(FILE *fp,
void *data,
int data_size)
60 fwrite(data, data_size, 1, fp);
63 FILE *
open_dump(
char type,
double cur_time,
uint32_t timestamp,
int data_size,
const char *extension)
65 char *fn = malloc(strlen(
out_dir) + 50);
66 sprintf(fn,
"%c-%f-%u.%s", type, cur_time, timestamp, extension);
68 sprintf(fn,
"%s/%c-%f-%u.%s",
out_dir, type, cur_time, timestamp, extension);
69 FILE* fp = fopen(fn,
"wb");
71 printf(
"Error: Cannot open file [%s]\n", fn);
84 ffmpeg_opts =
"-aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k";
86 snprintf(cmd, 1024,
"ffmpeg -pix_fmt rgb24 -s %dx%d -f rawvideo " 87 "-i /dev/stdin %s %s",
91 fprintf(stderr,
"%s\n", cmd);
93 FILE* proc = popen(cmd,
"w");
95 printf(
"Error: Cannot run ffmpeg\n");
110 fp =
open_dump(type, cur_time, timestamp, data_size,
"pgm");
115 fp =
open_dump(type, cur_time, timestamp, data_size,
"ppm");
120 fp =
open_dump(type, cur_time, timestamp, data_size,
"dump");
121 fwrite(data, data_size, 1, fp);
130 fwrite(data, data_size, 1, stream);
138 uint16_t* end = data_ptr + data_size;
139 while (data_ptr < end) {
141 fwrite(((
char*)(&z)), 3, 1, stream);
171 fprintf(
index_fp,
"d-%f-%u\n", cur_time, timestamp);
181 fprintf(
index_fp,
"d-%f-%u\n", cur_time, timestamp);
198 printf(
"%s Mode: {%d, %d, {%d}, %d, %d, %d, %d, %d, %d, %d}\n", name,
209 printf(
"Error: Cannot get context\n");
217 printf(
"Error: Cannot get device\n");
244 FILE *fp = fopen(fn,
"r");
247 printf(
"Error: Index already exists, to avoid overwriting " 248 "use a different directory.\n");
251 fp = fopen(fn,
"wb");
253 printf(
"Error: Cannot open file [%s]\n", fn);
262 printf(
"Caught signal, cleaning up\n");
268 printf(
"Records the Kinect sensor data to a directory\nResult can be used as input to Fakenect\nUsage:\n");
269 printf(
" record [-h] [-ffmpeg] [-ffmpeg-opts <options>] " 270 "<target basename>\n");
274 int main(
int argc,
char **argv)
278 if (strcmp(argv[c],
"-ffmpeg")==0)
280 else if (strcmp(argv[c],
"-ffmpeg-opts")==0) {
283 }
else if (strcmp(argv[c],
"-h")==0)
298 char *index_fn = malloc(strlen(
out_dir) + 50);
299 sprintf(index_fn,
"%s-index.txt",
out_dir);
312 printf(
"Error: %s already exists, to avoid overwriting " 319 printf(
"Error: %s already exists, to avoid overwriting " 334 mkdir(
out_dir, S_IRWXU | S_IRWXG | S_IRWXO);
336 char *fn = malloc(strlen(
out_dir) + 50);
337 sprintf(fn,
"%s/INDEX.txt",
out_dir);
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)
void depth_cb(freenect_device *dev, void *depth, uint32_t timestamp)
void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp, void *data, int data_size)
int freenect_stop_video(freenect_device *dev)
void print_mode(const char *name, freenect_frame_mode mode)
void dump_ffmpeg_24(FILE *stream, uint32_t timestamp, void *data, int data_size)
void dump_rgb(FILE *fp, void *data, int data_size)
void init_ffmpeg_streams()
int8_t data_bits_per_pixel
void depth_cb_ffmpeg(freenect_device *dev, void *depth, uint32_t timestamp)
int freenect_start_depth(freenect_device *dev)
FILE * open_index(const char *fn)
int freenect_shutdown(freenect_context *ctx)
FILE * open_ffmpeg(char *output_filename)
int freenect_set_video_mode(freenect_device *dev, const freenect_frame_mode mode)
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
int freenect_start_video(freenect_device *dev)
volatile sig_atomic_t running
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
freenect_frame_mode freenect_get_current_depth_mode(freenect_device *dev)
int main(int argc, char **argv)
FILE * open_dump(char type, double cur_time, uint32_t timestamp, int data_size, const char *extension)
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
void dump(char type, uint32_t timestamp, void *data, int data_size)
void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
freenect_raw_tilt_state * freenect_get_tilt_state(freenect_device *dev)
int freenect_update_tilt_state(freenect_device *dev)
void dump_depth(FILE *fp, void *data, int data_size)
int freenect_close_device(freenect_device *dev)
int freenect_set_depth_mode(freenect_device *dev, const freenect_frame_mode mode)
freenect_frame_mode freenect_get_current_video_mode(freenect_device *dev)
int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)
void rgb_cb_ffmpeg(freenect_device *dev, void *rgb, uint32_t timestamp)
static freenect_context * ctx
Data from the tilt motor and accelerometer.
int8_t padding_bits_per_pixel
void signal_cleanup(int num)
int freenect_stop_depth(freenect_device *dev)
freenect_resolution resolution
void snapshot_accel(freenect_device *dev)
int freenect_process_events(freenect_context *ctx)
freenect_video_format video_format
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)