-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl_sink.c
More file actions
76 lines (60 loc) · 1.73 KB
/
sdl_sink.c
File metadata and controls
76 lines (60 loc) · 1.73 KB
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
// Based on http://dranger.com/ffmpeg/tutorial02.c
// tutorial02.c
// A pedagogical video player that will stream through every video frame as fast as it can.
//
// Code based on FFplay, Copyright (c) 2003 Fabrice Bellard,
// and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de)
#include <SDL.h>
#include <SDL_thread.h>
#include <stdio.h>
#include "imgio.h"
int main(int argc, char *argv[]) {
int width, height;
SDL_Overlay *bmp;
SDL_Surface *screen;
SDL_Rect rect;
SDL_Event event;
TJContext *ctx = create_tjcontext();
if (argc != 3) {
fprintf(stderr, "Usage: %s width height\n", argv[0]);
exit(1);
} else {
width = atoi(argv[1]);
height = atoi(argv[2]);
}
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
// Make a screen to put our video
screen = SDL_SetVideoMode(width, height, 0, SDL_RESIZABLE);
if(!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n");
exit(1);
}
// Allocate a place to put our YUV image on that screen
bmp = SDL_CreateYUVOverlay(width, height, SDL_YV12_OVERLAY, screen);
// Read frames and save first five frames to disk
while (1) {
Image *image = read_frame_to_yuv(ctx, stdin);
SDL_LockYUVOverlay(bmp);
copy_yuv_to_planes(image, bmp->pitches, bmp->pixels, 1);
SDL_UnlockYUVOverlay(bmp);
free_image(image);
rect.x = 0;
rect.y = 0;
rect.w = width;
rect.h = height;
SDL_DisplayYUVOverlay(bmp, &rect);
SDL_PollEvent(&event);
switch (event.type) {
case SDL_QUIT:
SDL_Quit();
exit(0);
break;
default:
break;
}
}
return 0;
}