[問題] SDL Raw Video Player

看板C_and_CPP (C/C++)作者 (Oh Yes)時間15年前 (2010/07/26 13:56), 編輯推噓1(108)
留言9則, 3人參與, 最新討論串1/1
我目前是依這個文件的說明去做的 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
改出來了,把 screen->pixels = buf; 反過來就行了
07/27 10:54, 1F

07/27 10:54, , 2F
但是不知道為什麼原來的寫法不行。
07/27 10:54, 2F

07/27 11:06, , 3F
可是你要是寫成 buf = screen->pixels; 就mem leak了@@"
07/27 11:06, 3F

07/27 11:06, , 4F
buf需要的是malloc好的實際空間?? 還是只需要當成ptr
07/27 11:06, 4F

07/27 11:07, , 5F
指到data就可以?? 若是前者, 看起來少了個memcpy, 若是
07/27 11:07, 5F

07/27 11:07, , 6F
後者, 就不需要malloc了....@_@"
07/27 11:07, 6F

07/27 13:52, , 7F
奇怪,因為我正好有環境,把網頁上code複製貼上,
07/27 13:52, 7F

07/27 13:53, , 8F
編譯後執行就看到WC3的影片了,不用反過來??
07/27 13:53, 8F

07/28 00:07, , 9F
我是用 VS 2008,就是出不來,Dev C++也試過了。反過來就ok
07/28 00:07, 9F
文章代碼(AID): #1CJIEKBv (C_and_CPP)
文章代碼(AID): #1CJIEKBv (C_and_CPP)