yuvdump.cpp
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:3k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- #include "systems.h"
- #include <SDL.h>
- int main (int argc, char **argv)
- {
- FILE *yuvfile;
- uint8_t *ybuf, *ubuf, *vbuf;
- uint32_t height = 240, width = 320, ysize, uvsize, readbytes;
- char buf[32];
- printf("%s - %s version %sn", *argv, PACKAGE, VERSION);
- argc--;
- argv++;
- if (argc == 0) {
- printf("Usage - yuvdump -h <height> -w <width> filenamen");
- return 0;
- }
- while (argv[0][0] == '-') {
- switch (argv[0][1]) {
- case 'h':
- argv++;
- argc--;
- height = atoi(*argv);
- argv++;
- argc--;
- break;
- case 'w':
- argv++;
- argc--;
- width = atoi(*argv);
- argv++;
- argc--;
- break;
- default:
- printf("Unknown option %s", *argv);
- exit(-1);
- }
- }
- if (SDL_Init(SDL_INIT_VIDEO) < 0 || !SDL_VideoDriverName(buf, 1)) {
- printf("Could not init SDL video: %sn", SDL_GetError());
- }
- if (*argv == NULL)
- return(0);
- const SDL_VideoInfo *video_info;
- int video_bpp;
- video_info = SDL_GetVideoInfo();
- switch (video_info->vfmt->BitsPerPixel) {
- case 16:
- case 32:
- video_bpp = video_info->vfmt->BitsPerPixel;
- break;
- default:
- video_bpp = 16;
- break;
- }
- SDL_Surface *m_screen = SDL_SetVideoMode(width,
- height,
- 32,
- SDL_SWSURFACE | SDL_ASYNCBLIT);
- SDL_Rect m_dstrect;
- m_dstrect.x = 0;
- m_dstrect.y = 0;
- m_dstrect.w = m_screen->w;
- m_dstrect.h = m_screen->h;
- SDL_Overlay *m_image = SDL_CreateYUVOverlay(width,
- height,
- SDL_YV12_OVERLAY,
- m_screen);
- yuvfile = fopen(*argv, "r");
- ysize = width*height;
- uvsize = ysize / 4;
- printf("ysize %u uvsize %un", ysize, uvsize);
- ybuf = (uint8_t *)malloc(ysize);
- ubuf = (uint8_t *)malloc(ysize);
- vbuf = (uint8_t *)malloc(ysize);
- unsigned int fcount = 0;
- int qevent = 0;
- do {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- if (event.type == SDL_QUIT) {
- qevent = 1;
- }
- }
- readbytes = fread(ybuf, ysize, sizeof(uint8_t), yuvfile);
- if (readbytes != 1) {
- printf("frame %u - y buf read errorn", fcount);
- continue;
- }
- readbytes = fread(ubuf, uvsize, sizeof(uint8_t), yuvfile);
- if (readbytes != 1) {
- printf("frame %u - u buf read errorn", fcount);
- continue;
- }
- readbytes = fread(vbuf, uvsize, sizeof(uint8_t), yuvfile);
- if (readbytes != 1) {
- printf("frame %u - v buf read errorn", fcount);
- continue;
- }
- SDL_LockYUVOverlay(m_image);
- memcpy(m_image->pixels[0], ybuf, ysize);
- memcpy(m_image->pixels[1], vbuf, uvsize);
- memcpy(m_image->pixels[2], ubuf, uvsize);
- SDL_DisplayYUVOverlay(m_image, &m_dstrect);
- SDL_UnlockYUVOverlay(m_image);
- if (fcount == 0) SDL_Delay(1000);
- fcount++;
- //SDL_Delay(33);
- //printf("%un", fcount);
- } while (qevent == 0 && !feof(yuvfile));
- SDL_Delay(2000);
- printf("Frames read %un", fcount);
- SDL_FreeYUVOverlay(m_image);
- SDL_FreeSurface(m_screen);
- SDL_Quit();
- fclose(yuvfile);
- return (0);
- }