Enlightenment CVS committal Author : tilman Project : misc Module : enthrall
Dir : misc/enthrall/src Modified Files: Makefile enthrall.c Added Files: rgb2yuv420.c rgb2yuv420.h theora.c theora.h Log Message: enthrall now produces a theora video from the captured frames. thanks to vincent for pointing me at his rgb2yuv420 code. =================================================================== RCS file: /cvs/e/misc/enthrall/src/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- Makefile 19 Dec 2004 12:45:55 -0000 1.1 +++ Makefile 20 Oct 2006 20:50:22 -0000 1.2 @@ -1,21 +1,28 @@ -# $Id: Makefile,v 1.1 2004/12/19 12:45:55 tsauerbeck Exp $ - BIN = enthrall -SRC = $(BIN:%=%.c) +SRC = enthrall.c theora.c rgb2yuv420.c OBJ = $(SRC:%.c=%.o) PREFIX = /usr/local -FLAGS = $(CFLAGS) \ - `ecore-config --cflags` `imlib2-config --cflags` -LIBS = `ecore-config --libs` `imlib2-config --libs` +LIBS = `ecore-config --libs-x` `imlib2-config --libs` \ + `pkg-config theora --libs` + +ECORE_CFLAGS = `ecore-config --cflags` +IMLIB_CFLAGS = `imlib2-config --cflags` +THEORA_CFLAGS = `pkg-config theora --cflags` all: $(BIN) $(BIN): $(OBJ) $(CC) $(LIBS) $(OBJ) -o $@ +enthrall.o: enthrall.c + $(CC) $(CFLAGS) $(ECORE_CFLAGS) $(IMLIB_CFLAGS) $(THEORA_CFLAGS) -c -o $@ $< + +theora.o: theora.c + $(CC) $(CFLAGS) $(THEORA_CFLAGS) -c -o $@ $< + .c.o: - $(CC) $(FLAGS) -c -o $@ $< + $(CC) $(CFLAGS) -c -o $@ $< install: $(BIN) install $(BIN) $(DESTDIR)$(PREFIX)/bin =================================================================== RCS file: /cvs/e/misc/enthrall/src/enthrall.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- enthrall.c 12 Oct 2006 18:29:28 -0000 1.11 +++ enthrall.c 20 Oct 2006 20:50:22 -0000 1.12 @@ -1,6 +1,4 @@ /* - * $Id: enthrall.c,v 1.11 2006/10/12 18:29:28 tilman Exp $ - * * Copyright (C) 2004-2006 Tilman Sauerbeck (tilman at code-monkey de) * * This program is free software; you can redistribute it and/or modify @@ -33,11 +31,13 @@ #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> -#include <dirent.h> #define _GNU_SOURCE #include <getopt.h> +#include "theora.h" +#include "rgb2yuv420.h" + #define VERSION "0.0.2" /* FIXME: should be configurable, but i'm too lazy to add the necessary @@ -55,10 +55,6 @@ typedef struct { Ecore_X_Display *disp; - int fps; - int quality; - char output_dir[PATH_MAX]; - struct { Ecore_X_Window id; int w, h; @@ -72,9 +68,12 @@ Imlib_Image prev_img; Ecore_X_Rectangle damage; bool damage_valid; - char last_written[PATH_MAX]; unsigned long frame_count; + + EnthrallTheora theora; + + uint8_t *y, *u, *v; } Enthrall; static int @@ -85,7 +84,7 @@ Bool b; int ptr_x = 0, ptr_y = 0, unused1; unsigned int unused2; - char buf[PATH_MAX]; + uint32_t *data; Window dw, childw = None; /* FIXME: check whether e->window.id still points to a @@ -93,14 +92,17 @@ * done every time we enter this function. */ - snprintf (buf, sizeof (buf), "%s/"FILE_FMT".jpeg", - e->output_dir, e->frame_count); - /* was there any change at all? * if not, just link the last written frame to the current. */ if (!e->damage_valid) { - symlink (e->last_written, buf); + /* FIXME: + * According to this ticket + * https://trac.xiph.org/changeset/11119 + * it seems we can just put in an empty packet to repeat + * the last frame. + */ + enthrall_theora_encode_frame (&e->theora, false); goto out; } @@ -130,11 +132,12 @@ e->cursor.w, e->cursor.h); } - imlib_image_attach_data_value ("quality", NULL, e->quality, NULL); - imlib_image_set_format ("jpeg"); + data = imlib_image_get_data_for_reading_only (); + rgb2yuv420 (data, e->window.w, e->window.h, e->y, e->u, e->v, + e->theora.yuv.y_stride, e->theora.yuv.uv_stride); + imlib_image_put_back_data (data); - imlib_save_image (buf); - strcpy (e->last_written, buf); + enthrall_theora_encode_frame (&e->theora, false); e->damage_valid = false; @@ -187,12 +190,12 @@ "Options:\n" " -f, --fps=FPS " "frames per second (1-50, default: 25)\n" - " -o, --output-directory=DIR " - "output directory (default: working directory)\n" + " -o, --output-file=F " + "output file\n" " -p, --pointer=FILE " "path to pointer image file\n" " -q, --quality=QUALITY " - "JPEG quality (0-100, default: 90)\n" + "video quality (0-100, default: 90)\n" " -w, --window=WINDOW " "window to grab\n"); } @@ -226,13 +229,14 @@ main (int argc, char **argv) { Enthrall e; - DIR *d; - char pointer_img[PATH_MAX]; + char pointer_img[PATH_MAX], output_file[PATH_MAX] = {0}; double start; + bool s; + int fps = 25, quality = 90; struct option options[] = { {"help", no_argument, NULL, 'h'}, {"fps", required_argument, NULL, 'f'}, - {"output-directory", required_argument, NULL, 'o'}, + {"output-file", required_argument, NULL, 'o'}, {"pointer", required_argument, NULL, 'p'}, {"quality", required_argument, NULL, 'q'}, {"window", required_argument, NULL, 'w'}, @@ -241,11 +245,6 @@ memset (&e, 0, sizeof (Enthrall)); - e.fps = 25; - e.quality = 90; - - strcpy (e.output_dir, "."); - while ((c = getopt_long (argc, argv, "hf:o:p:q:w:", options, NULL)) != -1) { int base; @@ -254,10 +253,10 @@ show_usage (); return EXIT_SUCCESS; case 'f': - e.fps = atoi (optarg); + fps = atoi (optarg); break; case 'o': - snprintf (e.output_dir, sizeof (e.output_dir), "%s", + snprintf (output_file, sizeof (output_file), "%s", optarg); break; case 'p': @@ -265,7 +264,7 @@ optarg); break; case 'q': - e.quality = atoi (optarg); + quality = atoi (optarg); break; case 'w': base = strncasecmp (optarg, "0x", 2) ? 10 : 16; @@ -274,33 +273,24 @@ } } - if (!e.window.id) { + if (!e.window.id || !*output_file) { show_usage (); return EXIT_FAILURE; } - if (e.quality < 0 || e.quality > 100) { + if (quality < 0 || quality > 100) { show_usage (); return EXIT_FAILURE; } - if (e.fps < 1 || e.fps > 50) { + if (fps < 1 || fps > 50) { show_usage (); return EXIT_FAILURE; } - d = opendir (e.output_dir); - if (!d) { - fprintf (stderr, "Error: cannot open output directory.\n"); - - return EXIT_FAILURE; - } - - closedir (d); - ecore_init (); ecore_x_init (NULL); @@ -329,7 +319,16 @@ init_imlib (&e); - ecore_timer_add (1.0 / e.fps, on_timer, &e); + s = enthrall_theora_init (&e.theora, output_file, + quality, e.window.w, e.window.h, + &e.y, &e.u, &e.v); + if (!s) { + fprintf (stderr, "Error: Cannot initialize theora encoder.\n"); + + return EXIT_FAILURE; + } + + ecore_timer_add (1.0 / fps, on_timer, &e); ecore_event_handler_add (ECORE_X_EVENT_DAMAGE_NOTIFY, on_damage, &e); @@ -342,8 +341,12 @@ e.prev_img = IMG_FROM_RECT (e.damage); imlib_context_set_image (e.prev_img); + printf ("Starting recording...\n"); ecore_main_loop_begin (); + enthrall_theora_encode_frame (&e.theora, true); + enthrall_theora_finish (&e.theora); + ecore_x_shutdown (); ecore_shutdown (); @@ -357,12 +360,6 @@ printf ("Wrote %lu frames in %f seconds.\n\n", e.frame_count, ecore_time_get () - start); - printf ("Suggested MEncoder call to encode the video:\n\n" - "mencoder \"mf://%s/*.jpeg\" \\\n" - " -mf w=%i:h=%i:fps=%i:type=jpeg -ovc lavc \\\n" - " -lavcopts vcodec=mpeg4:vbitrate=16000:vhq:autoaspect \\\n" - " -o out.avi\n\n", - e.output_dir, e.window.w, e.window.h, e.fps); return EXIT_SUCCESS; } ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs