3 #include <oggplay/oggplay.h>
12 static int n_frames
= 0;
15 write_png_file(char *fname
, OggPlayRGBChannels
*data
) {
19 FILE *f
= fopen("out.rgb", "wb");
20 fwrite(data
->ptro
, data
->rgb_width
* data
->rgb_height
, 4, f
);
24 image
= imlib_create_image_using_data(data
->rgb_width
, data
->rgb_height
,
25 (unsigned int *)data
->ptro
);
26 imlib_context_set_image(image
);
27 imlib_image_set_format("png");
28 imlib_save_image(fname
);
29 imlib_free_image_and_decache();
33 dump_video_data (OggPlay
* player
, int track_num
, OggPlayVideoData
* video_data
,
36 OggPlayYUVChannels from
;
37 OggPlayRGBChannels to
;
39 from
.ptry
= video_data
->y
;
40 from
.ptru
= video_data
->u
;
41 from
.ptrv
= video_data
->v
;
42 oggplay_get_video_y_size(player
, track_num
, &(from
.y_width
),
44 oggplay_get_video_uv_size(player
, track_num
, &(from
.uv_width
),
47 FILE *f
= fopen("out.y", "wb");
48 fwrite(from
.ptry
, from
.y_width
* from
.y_height
, 1, f
);
51 printf("size: %dx%d %dx%d\n", from
.y_width
, from
.y_height
, from
.uv_width
,
54 to
.ptro
= malloc(from
.y_width
* from
.y_height
* 4);
55 to
.rgb_width
= from
.y_width
;
56 to
.rgb_height
= from
.y_height
;
58 oggplay_yuv2bgra (&from
, &to
);
59 printf("now %dx%d\n", to
.rgb_width
, to
.rgb_height
);
61 write_png_file("out.png", &to
);
66 dump_streams_callback (OggPlay
*player
, int num_tracks
,
67 OggPlayCallbackInfo
**track_info
, void *user
) {
71 OggPlayDataHeader
** headers
;
72 OggPlayVideoData
* video_data
;
73 //OggPlayAudioData * audio_data;
77 for (i
= 0; i
< num_tracks
; i
++) {
78 type
= oggplay_callback_info_get_type(track_info
[i
]);
79 headers
= oggplay_callback_info_get_headers(track_info
[i
]);
82 case OGGPLAY_INACTIVE
:
84 case OGGPLAY_YUV_VIDEO
:
86 * there should only be one record
88 if (oggplay_callback_info_get_required(track_info
[i
]) < 1) {
92 video_data
= oggplay_callback_info_get_video_data(headers
[0]);
93 dump_video_data(player
, i
, video_data
, n_frames
);
107 main (int argc
, char * argv
[]) {
110 OggPlayReader
* reader
;
114 printf ("please provide a filename\n");
118 if (strlen(argv
[1]) > 7 && (strncmp(argv
[1], "http://", 7) == 0)) {
119 reader
= oggplay_tcp_reader_new(argv
[1], NULL
, 80);
121 reader
= oggplay_file_reader_new(argv
[1]);
124 player
= oggplay_open_with_reader(reader
);
126 if (player
== NULL
) {
127 printf ("could not initialise oggplay with this file\n");
131 for (i
= 0; i
< oggplay_get_num_tracks (player
); i
++) {
132 if (oggplay_get_track_type (player
, i
) == OGGZ_CONTENT_THEORA
) {
133 oggplay_set_callback_num_frames (player
, i
, 1);
135 oggplay_set_track_active(player
, i
);
138 oggplay_set_data_callback(player
, dump_streams_callback
, NULL
);
139 oggplay_start_decoding(player
);
141 oggplay_close (player
);