[xiph-commits] r3153 - in liboggplay/trunk/src: liboggplay tools
shans at svn.annodex.net
shans at svn.annodex.net
Sun Jul 1 23:48:08 PDT 2007
Author: shans
Date: 2007-07-01 23:48:07 -0700 (Sun, 01 Jul 2007)
New Revision: 3153
Added:
liboggplay/trunk/src/tools/dump-first-frame.c
Modified:
liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
liboggplay/trunk/src/tools/Makefile.am
Log:
dump-first-frame utility to replace gstreamer in cmmlwiki. Doesn't work yet.
Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-06-29 06:23:21 UTC (rev 3152)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c 2007-07-02 06:48:07 UTC (rev 3153)
@@ -415,7 +415,6 @@
return E_OGGPLAY_BAD_INPUT;
} else {
found_http_response = 1;
- printf("found HTTP response\n");
}
dpos = strstr((char *)me->buffer, "X-Content-Duration:");
Modified: liboggplay/trunk/src/tools/Makefile.am
===================================================================
--- liboggplay/trunk/src/tools/Makefile.am 2007-06-29 06:23:21 UTC (rev 3152)
+++ liboggplay/trunk/src/tools/Makefile.am 2007-07-02 06:48:07 UTC (rev 3153)
@@ -27,7 +27,7 @@
# Tools
-bin_PROGRAMS = oggplay-info
+bin_PROGRAMS = oggplay-info dump-first-frame
noinst_PROGRAMS = get-stream-info $(glut_tools) $(sndfile_tools)
oggplay_info_SOURCES = oggplay-info.c
@@ -40,6 +40,9 @@
dump_all_streams_CFLAGS = @SNDFILE_CFLAGS@
dump_all_streams_LDADD = $(OGGPLAY_LIBS) @SNDFILE_LIBS@
+dump_first_frame_SOURCES = dump-first-frame.c
+dump_first_frame_LDADD = $(OGGPLAY_LIBS) @IMLIB2_LIBS@
+
glut_player_SOURCES = glut-player.c
glut_player_LDADD = $(OGGPLAY_LIBS) @GLUT_LIBS@
if MACOS
Added: liboggplay/trunk/src/tools/dump-first-frame.c
===================================================================
--- liboggplay/trunk/src/tools/dump-first-frame.c (rev 0)
+++ liboggplay/trunk/src/tools/dump-first-frame.c 2007-07-02 06:48:07 UTC (rev 3153)
@@ -0,0 +1,166 @@
+#include "config.h"
+
+#include <oggplay/oggplay.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h>
+
+#include <Imlib2.h>
+
+static int n_frames = 0;
+
+void
+write_png_file(char *fname, OggPlayRGBChannels *data) {
+
+ Imlib_Image *image;
+ int i;
+ int j;
+
+ /*
+ for (i = 0; i < data->rgb_height; i++) {
+ for (j = 0; j < data->rgb_width; j++) {
+ char *ptr = data->ptro + i * data->rgb_width * 4 + j * 4;
+ int *iptr = (int *)ptr;
+ *iptr = (0xFF << 24) | ((((i >> 2) % 2) ? 0xFF : 0x00) << 16) |
+ ((((j >> 2) % 2) ? 0xFF : 0x00) << 8);
+ }
+ }*/
+ FILE *f = fopen("out.rgb", "wb");
+ for (i = 0; i < data->rgb_height; i++) {
+ for (j = 0; j < data->rgb_width; j++) {
+ char *ptr = data->ptro + i * data->rgb_width * 4 + j * 4;
+ int *iptr = (int *)ptr;
+ fwrite(iptr, 4, 1, f);
+ //*iptr = 0xFF000000 | (((int)(ptr[0])) << 16) | (((int)(ptr[2])) << 8)
+ // | ptr[3];
+ }
+ }
+ fclose(f);
+
+
+ image = imlib_create_image_using_data(data->rgb_width, data->rgb_height,
+ (unsigned int *)data->ptro);
+ imlib_context_set_image(image);
+ imlib_image_set_format("png");
+ imlib_save_image(fname);
+ imlib_free_image_and_decache();
+
+
+}
+
+void
+dump_video_data (OggPlay * player, int track_num, OggPlayVideoData * video_data,
+ int frame) {
+
+ char fname[256];
+ FILE * f;
+ FILE * g;
+ int i;
+ unsigned char * ptr;
+ unsigned char * ptr2;
+ OggPlayYUVChannels from;
+ OggPlayRGBChannels to;
+
+ from.ptry = video_data->y;
+ from.ptru = video_data->u;
+ from.ptrv = video_data->v;
+ oggplay_get_video_y_size(player, track_num, &(from.y_width),
+ &(from.y_height));
+ oggplay_get_video_uv_size(player, track_num, &(from.uv_width),
+ &(from.uv_height));
+
+ printf("size: %dx%d %dx%d\n", from.y_width, from.y_height, from.uv_width,
+ from.uv_height);
+
+ to.ptro = malloc(from.y_width * from.y_height * 4);
+ to.rgb_width = from.y_width;
+ to.rgb_height = from.y_height;
+
+ oggplay_yuv2rgb(&from, &to);
+ printf("now %dx%d\n", to.rgb_width, to.rgb_height);
+
+ write_png_file("out.png", &to);
+ //free(to.ptro);
+
+}
+
+int
+dump_streams_callback (OggPlay *player, int num_tracks,
+ OggPlayCallbackInfo **track_info, void *user) {
+
+ int i;
+ int j;
+ OggPlayDataHeader ** headers;
+ OggPlayVideoData * video_data;
+ OggPlayAudioData * audio_data;
+ int required;
+ OggPlayDataType type;
+
+ for (i = 0; i < num_tracks; i++) {
+ type = oggplay_callback_info_get_type(track_info[i]);
+ headers = oggplay_callback_info_get_headers(track_info[i]);
+
+ switch (type) {
+ case OGGPLAY_INACTIVE:
+ break;
+ case OGGPLAY_YUV_VIDEO:
+ /*
+ * there should only be one record
+ */
+ if (oggplay_callback_info_get_required(track_info[i]) < 1) {
+ printf("oops\n");
+ break;
+ }
+ video_data = oggplay_callback_info_get_video_data(headers[0]);
+ dump_video_data(player, i, video_data, n_frames);
+ exit(0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ n_frames++;
+
+ return 0;
+}
+
+int
+main (int argc, char * argv[]) {
+
+ OggPlay * player;
+ OggPlayReader * reader;
+ int i;
+
+ if (argc < 2) {
+ printf ("please provide a filename\n");
+ exit (1);
+ }
+
+ if (strlen(argv[1]) > 7 && (strncmp(argv[1], "http://", 7) == 0)) {
+ reader = oggplay_tcp_reader_new(argv[1], NULL, 80);
+ } else {
+ reader = oggplay_file_reader_new(argv[1]);
+ }
+
+ player = oggplay_open_with_reader(reader);
+
+ if (player == NULL) {
+ printf ("could not initialise oggplay with this file\n");
+ exit (1);
+ }
+
+ for (i = 0; i < oggplay_get_num_tracks (player); i++) {
+ if (oggplay_get_track_type (player, i) == OGGZ_CONTENT_THEORA) {
+ oggplay_set_callback_num_frames (player, i, 1);
+ oggplay_set_track_active(player, i);
+ break;
+ }
+ }
+
+ oggplay_set_data_callback(player, dump_streams_callback, NULL);
+ oggplay_start_decoding(player);
+
+ return 0;
+}
More information about the commits
mailing list