- Timestamp:
- Dec 12, 2005, 4:32:11 PM (19 years ago)
- Location:
- branches/avi_play/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/avi_play/src/lib/graphics/importer/media_container.cc
r6057 r6068 41 41 42 42 current_frame = 0; 43 num_frames = 0;44 frames_left = true;45 43 46 44 if (filename != NULL) … … 54 52 MediaContainer::~MediaContainer() 55 53 { 54 // Free the RGB image 55 delete [] buffer; 56 av_free(RGB_frame); 56 57 57 58 /* Free the frame */ … … 66 67 } 67 68 68 /*GLuint MediaContainer::getFrame(int frame_number)69 GLuint MediaContainer::getFrame(int frame_number) 69 70 { 70 71 … … 73 74 GLuint MediaContainer::getNextFrame() 74 75 { 75 76 }*/ 77 78 SDL_Surface* MediaContainer::getFrame(int frame_number) 79 { 80 81 } 82 83 SDL_Surface* MediaContainer::getNextFrame() 84 { 85 /* get next frame */ 86 if(av_read_frame(format_context, &packet) >= 0) 87 { 88 frames_left = true; 89 current_frame++; 90 PRINTF(1)("current_frame: %i\n", current_frame); 91 92 93 /* work with the frame */ 94 /* packet -> SDL_Surface */ 95 96 97 98 99 } 100 else 101 frames_left = false; 102 76 /* get next frame */ 77 if(av_read_frame(format_context, &packet) >= 0) 78 { 79 //this->printPacketInformation(); 80 81 /* Is this a packet from the video stream? */ 82 if(packet.stream_index == video_stream) 83 { 84 int frame_finished; 85 // Decode video frame 86 avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size); 87 88 // Did we get a video frame? 89 if(frame_finished) 90 { 91 current_frame++; 92 PRINTF(1)("current_frame: %i\n", current_frame); 93 94 // Convert the image from its native format to RGB 95 img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame, codec_context->pix_fmt, 96 codec_context->width, codec_context->height); 97 98 // save frame 99 this->saveCurrentFrame(); 100 101 102 /* RGB_picture -> texture */ 103 104 105 return texture; 106 } 107 } 108 // Free the packet that was allocated by av_read_frame 109 av_free_packet(&packet); 110 } 111 else 112 return NULL; 113 } 114 115 void MediaContainer::saveCurrentFrame() 116 { 117 FILE *file; 118 char filename[32]; 119 int y; 120 121 picture = (AVPicture*)RGB_frame; 122 123 // Open file 124 sprintf(filename, "frame%i.ppm", current_frame); 125 file = fopen(filename, "wb"); 126 if(file == NULL) 127 return; 128 129 // Write header 130 fprintf(file, "P6\n%d %d\n255\n", codec_context->width, codec_context->height); 131 // Write pixel data 132 for(y = 0; y < codec_context->height; y++) 133 fwrite(picture->data[0]+y * picture->linesize[0], 1, codec_context->width*3, file); 134 // Close file 135 fclose(file); 136 137 PRINTF(1)("created file: %s\n", filename); 103 138 } 104 139 … … 144 179 /* Open codec */ 145 180 if (avcodec_open(codec_context, codec) < 0) 146 PRINTF(1)("Could not open codec\n"); 181 PRINTF(1)("Could not open codec\n"); 182 183 // Allocate video frame 184 frame = avcodec_alloc_frame(); 185 RGB_frame = avcodec_alloc_frame(); 186 187 // Determine required buffer size and allocate buffer 188 num_bytes = avpicture_get_size(PIX_FMT_RGB24, codec_context->width, codec_context->height); 189 buffer=new uint8_t[num_bytes]; 190 191 // Assign appropriate parts of buffer to image planes in pFrameRGB 192 avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height); 147 193 148 194 } … … 150 196 int MediaContainer::getHeight() 151 197 { 152 198 return codec_context->height; 153 199 } 154 200 155 201 int MediaContainer::getWidth() 156 202 { 157 203 return codec_context->width; 158 204 } 159 205 … … 168 214 } 169 215 170 bool MediaContainer::framesLeft()171 {172 return frames_left;173 }174 175 216 void MediaContainer::printMediaInformation() 176 217 { 177 PRINTF(1)("========================\n"); 178 PRINTF(1)("========================\n"); 179 PRINTF(1)("= MEDIACONTAINER =\n"); 180 PRINTF(1)("========================\n"); 181 PRINTF(1)("========================\n"); 182 PRINTF(1)("= AVFormatContext =\n"); 183 PRINTF(1)("========================\n"); 184 PRINTF(1)("filename: %s\n", format_context->filename); 185 PRINTF(1)("nb_streams: %i\n", format_context->nb_streams); 186 PRINTF(1)("duration: %fs\n", format_context->duration/1000000.); 187 PRINTF(1)("file_size: %ikb\n", format_context->file_size/1024); 188 PRINTF(1)("bit_rate: %ikb/s\n", format_context->bit_rate/1000); 189 PRINTF(1)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames); 190 //PRINTF(1)("r_frame_rate: %ifps\n", format_context->streams[video_stream]->r_frame_rate.num); 191 PRINTF(1)("========================\n"); 192 PRINTF(1)("= AVCodecContext =\n"); 193 PRINTF(1)("========================\n"); 194 PRINTF(1)("width: %i\n", codec_context->width); 195 PRINTF(1)("height: %i\n", codec_context->height); 196 PRINTF(1)("========================\n"); 197 PRINTF(1)("= AVCodec =\n"); 198 PRINTF(1)("========================\n"); 199 PRINTF(1)("codec name: %s\n", codec->name); 200 PRINTF(1)("========================\n"); 201 PRINTF(1)("========================\n"); 202 } 218 PRINTF(1)("========================\n"); 219 PRINTF(1)("========================\n"); 220 PRINTF(1)("= MEDIACONTAINER =\n"); 221 PRINTF(1)("========================\n"); 222 PRINTF(1)("========================\n"); 223 PRINTF(1)("= AVFormatContext =\n"); 224 PRINTF(1)("========================\n"); 225 PRINTF(1)("filename: %s\n", format_context->filename); 226 PRINTF(1)("nb_streams: %i\n", format_context->nb_streams); 227 PRINTF(1)("duration: %fs\n", format_context->duration/1000000.); 228 PRINTF(1)("file_size: %ikb\n", format_context->file_size/1024); 229 PRINTF(1)("bit_rate: %ikb/s\n", format_context->bit_rate/1000); 230 PRINTF(1)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames); 231 PRINTF(1)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num); 232 PRINTF(1)("========================\n"); 233 PRINTF(1)("= AVCodecContext =\n"); 234 PRINTF(1)("========================\n"); 235 PRINTF(1)("width: %i\n", codec_context->width); 236 PRINTF(1)("height: %i\n", codec_context->height); 237 PRINTF(1)("========================\n"); 238 PRINTF(1)("= AVCodec =\n"); 239 PRINTF(1)("========================\n"); 240 PRINTF(1)("codec name: %s\n", codec->name); 241 PRINTF(1)("========================\n"); 242 PRINTF(1)("========================\n"); 243 } 244 245 void MediaContainer::printPacketInformation() 246 { 247 PRINTF(1)("========================\n"); 248 PRINTF(1)("========================\n"); 249 PRINTF(1)("= AVPacket =\n"); 250 PRINTF(1)("========================\n"); 251 PRINTF(1)("pts: %i\n", packet.pts); 252 PRINTF(1)("dts: %i\n", packet.dts); 253 PRINTF(1)("size: %i\n", packet.size); 254 PRINTF(1)("stream_index: %i\n", packet.stream_index); 255 PRINTF(1)("duration: %i\n", packet.duration); 256 PRINTF(1)("pos: %i\n", packet.pos); 257 PRINTF(1)("========================\n"); 258 PRINTF(1)("========================\n"); 259 } -
branches/avi_play/src/lib/graphics/importer/media_container.h
r6057 r6068 24 24 using namespace std; 25 25 26 /* Forward Declaration */27 struct SDL_Surface;28 29 26 class MediaContainer : public BaseObject 30 27 { … … 32 29 private: 33 30 34 int current_frame; 35 int num_frames; 31 int current_frame; 32 int num_frames; 33 GLuint texture; 36 34 37 AVFormatContext* format_context; 38 AVCodecContext* codec_context; 39 AVCodec* codec; 40 AVFrame* frame; 41 AVPacket packet; 35 AVFormatContext* format_context; 36 AVCodecContext* codec_context; 37 AVCodec* codec; 38 AVFrame* frame; 39 AVPacket packet; 40 AVPicture* picture; 41 AVFrame* RGB_frame; 42 42 43 44 int video_stream;45 bool frames_left;43 int num_bytes; 44 uint8_t *buffer; 45 int video_stream; 46 46 47 47 public: … … 50 50 ~MediaContainer(); 51 51 52 //GLuint getFrame(int frame_number); 53 SDL_Surface* getFrame(int frame_number); 54 //GLuint getNextFrame(); 55 SDL_Surface* getNextFrame(); 56 void loadMedia(const char* filename); 52 GLuint getFrame(int frame_number); 53 GLuint getNextFrame(); 54 void loadMedia(const char* filename); 57 55 58 59 60 61 56 int getHeight(); 57 int getWidth(); 58 int getFrameRate(); 59 void getStream(/* stream */); 62 60 63 bool framesLeft(); 64 65 /* prints some information about the 66 media file for debug reasons */ 67 void printMediaInformation();61 /* prints some information about the 62 media file for debug reasons */ 63 void printMediaInformation(); 64 void printPacketInformation(); 65 void saveCurrentFrame(); 68 66 69 67 }; -
branches/avi_play/src/subprojects/importer/importer.cc
r6057 r6068 35 35 movie = new MediaContainer(argv[1]); 36 36 37 38 movie->printMediaInformation(); 37 // print information about the media file 38 movie->printMediaInformation(); 39 39 40 /* 41 ResourceManager::getInstance()->addImageDir("./"); 40 SDL_Delay(1000); 42 41 43 for (int i = 0; i < argc; i++) 44 { 45 printf("%s\n", argv[i]); 46 } 47 ResourceManager::getInstance()->addImageDir(""); 42 // get the frame and save it as an image 43 //while(movie->getNextFrame() != NULL); 48 44 49 50 if (argc>=3)51 obj = new OBJModel (argv[1], atof(argv[2]));52 else if (argc>=2)53 obj = new OBJModel(argv[1]);54 else55 obj = new PrimitiveModel(PRIM_CYLINDER);56 57 ResourceManager::getInstance()->debug();58 59 LightManager* lightMan = LightManager::getInstance();60 lightMan->setAmbientColor(.1,.1,.1);61 (new Light())->setAbsCoor(5.0, 10.0, 40.0);62 (new Light())->setAbsCoor(-10, -20, -100);*/63 45 } 64 46 … … 78 60 void Framework::moduleTick(float dt) 79 61 { 80 if(movie->framesLeft()) 81 movie->getNextFrame(); 62 while(movie->getNextFrame() != NULL); 82 63 } 83 64 84 65 void Framework::moduleDraw(void) const 85 66 { 86 //obj->draw();87 67 88 //LightManager::getInstance()->draw();89 68 } 90 69 -
branches/avi_play/src/subprojects/importer/multitex.cc
r6013 r6068 76 76 obj = new PrimitiveModel(PRIM_CUBE, 10.0); 77 77 break; 78 78 case SDLK_2: 79 79 obj = new PrimitiveModel(PRIM_SPHERE, 10.0); 80 80 break;
Note: See TracChangeset
for help on using the changeset viewer.