[問題] SDL Raw Video Player
我目前是依這個文件的說明去做的
http://www.webkinesia.com/games/rawvideo.php
程式碼和他的一模一樣,也沒有任何的error,
「Playing video successful!」這個訊息有出現
執行的結果是,有視窗跳出來,但是確是一片黑黑的,沒有任何的畫面。
目前我懷疑是"sample_video.raw",這個檔案, 我用一般的player 都沒有辦法播放
請問要怎麼樣才可以有正常播放的畫面出來呢?
code 如下..
int main( int argc, char* args[] )
{
SDL_Surface *screen;
FILE *fp;
char *buf;
int n;
printf("\nhello \n");
//hard-code file name and parameters just for demo purposes
if ( ( fp = fopen ( "sample_video.raw", "rb" ) ) == NULL ) {
printf("\nError opening file \n");
exit ( 0 );
}
//allocate memory to hold one frame of data
n = 320 * 240 * 3;
buf = ( char *) malloc ( n );
assert ( buf ); //make sure memory has been allocated successfully
//initialize video system
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
//ensure SDL_Quit is called when the program exits
atexit(SDL_Quit);
//set video mode of 320 x 240 with 24-bit pixels
screen = SDL_SetVideoMode( 320, 240, 24, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Unable to set 320x240 video: %s\n", SDL_GetError());
exit(1);
}
screen->pixels = buf; //point framebuffer to data buffer
while ( 1 ) {
//read data ( one frame of n bytes ) into buffer
if ( fread ( buf, 1, n, fp ) <= 0 )
break;
SDL_Delay ( 50 ); //50 ms per frame
SDL_UpdateRect ( screen, 0, 0, 0, 0 ); //blit data to screen
}
fclose ( fp );
SDL_Delay ( 2000 ); //delay 2 seconds before exit
printf("Playing video successful!\n");
return 0;
}
--
真相在此
http://puperchang.myec.tw/wordpress/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.20.164.107
→
07/27 10:54, , 1F
07/27 10:54, 1F
→
07/27 10:54, , 2F
07/27 10:54, 2F
推
07/27 11:06, , 3F
07/27 11:06, 3F
→
07/27 11:06, , 4F
07/27 11:06, 4F
→
07/27 11:07, , 5F
07/27 11:07, 5F
→
07/27 11:07, , 6F
07/27 11:07, 6F
→
07/27 13:52, , 7F
07/27 13:52, 7F
→
07/27 13:53, , 8F
07/27 13:53, 8F
→
07/28 00:07, , 9F
07/28 00:07, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章