Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/lib/graphics/importer/media_container.cc @ 6057

Last change on this file since 6057 was 6057, checked in by hdavid, 18 years ago

branches\avi_play: MediaContainer opens a videofile and prints some information

File size: 4.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: David Hasenfratz, Stephan Lienhard
13   co-programmer:
14*/
15
16
17
18/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_MEDIA module
19   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
20*/
21#define DEBUG_MODULE_MEDIA
22
23
24/* include your own header */
25#include "media_container.h"
26
27/* header for debug output */
28#include "debug.h"
29
30
31/**
32 * Default constructor
33 */
34MediaContainer::MediaContainer(const char* filename)
35{
36  /* set the class id for the base object */
37  this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer");
38
39  /* register all formats and codecs */
40  av_register_all();
41
42  current_frame = 0;
43  num_frames = 0;
44        frames_left = true;
45
46  if (filename != NULL)
47    this->loadMedia(filename);
48
49}
50
51/**
52 * Default destructor
53 */
54MediaContainer::~MediaContainer()
55{
56
57  /* Free the frame */
58  av_free(frame);
59
60  /* Close the codec */
61  avcodec_close(codec_context);
62
63  /* Close the video file */
64  av_close_input_file(format_context);
65
66}
67
68/*GLuint MediaContainer::getFrame(int frame_number)
69{
70
71}
72
73GLuint MediaContainer::getNextFrame()
74{
75
76}*/
77
78SDL_Surface* MediaContainer::getFrame(int frame_number)
79{
80
81}
82
83SDL_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
103}
104
105void MediaContainer::loadMedia(const char* filename)
106{
107  /* Open video file */
108  if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 )
109    PRINTF(1)("Could not open %s\n", filename);
110
111  /* Retrieve stream information */
112  if (av_find_stream_info(format_context) < 0)
113    PRINTF(1)("Could not find stream information in %s\n", filename); 
114
115  // Dump information about file onto standard error
116  //dump_format(pFormatCtx, 0, argv[1], false);
117
118  /* Find the first video stream and take it */
119  video_stream = -1;
120  for(int i = 0; i < format_context->nb_streams; i++)
121  {
122    // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis)
123    // if(format_context->streams[i]->codec.codec_type == CODEC_TYPE_VIDEO)             
124    if(format_context->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO)
125    {
126      video_stream = i;
127      break;
128    }
129  }
130 
131  if(video_stream == -1)
132    PRINTF(1)("Could not find a video stream in %s\n", filename);
133
134  /* Get a pointer to the codec context for the video stream */
135  // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis)
136  // codec_context = &format_context->streams[video_stream]->codec;
137  codec_context = format_context->streams[video_stream]->codec;
138
139  /* Find the decoder for the video stream */
140  codec = avcodec_find_decoder(codec_context->codec_id);
141  if (codec == NULL)
142    PRINTF(1)("Could not find codec\n");
143
144  /* Open codec */
145  if (avcodec_open(codec_context, codec) < 0)
146    PRINTF(1)("Could not open codec\n");       
147
148}
149
150int MediaContainer::getHeight()
151{
152        return codec_context->height;
153}
154
155int MediaContainer::getWidth()
156{
157        return codec_context->width;
158}
159
160int MediaContainer::getFrameRate()
161{
162
163}
164
165void MediaContainer::getStream(/* stream */)
166{
167
168}
169
170bool MediaContainer::framesLeft()
171{
172        return frames_left;
173}
174
175void MediaContainer::printMediaInformation()
176{
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}
Note: See TracBrowser for help on using the repository browser.