I suppose there's loads of methods of playing a video file, but has allegro got anything specific for this? What would be the best way of showing a short (like 2 minutes long) avi type file? Any suggestions out there?
There used to be an add-on library, but I am not sure it is still developed. Better to use a MPEG file and KC's APEG instead.
Correct me if im wrong, but isnt saying "I want to play an .avi" pretty much the same as saying "I want to play a movie file", as .avi is a container file which can have just about any format inside it (that is, any audio, video, subtitle and what not)?
There is a part of directX that can be used to play AVI's, if the user has the correct codecs installed. DirectShow i think?
Allegro has built-in support for playing FLI files. Though they are limited to 8bits-per-frame, don't contain audio, and don't compress well at all.
AllegAVI (I don't have a url handy, sorry) uses the Video for Windows codecs to play videos, which are rather outdated in favor of DirectShow codecs. It is also Windows-only, and in C++.
APEG (which I just updated) can handle MPEG-1 and Ogg (Vorbis audio and Theora video). It is in C, and should work on the same systems Allegro does. (Ogg Theora, btw, is comparible to DivX and XviD in size-vs-quality)
So, basically, there's no decent way of playing a video file in allegro, and my other options are APEG, AllegAVI and directX. Any more suggestions?
Depends on what you mean by decent. APEG is quite flexible, and is able to use a modern format in a cross-platform manner. AllegAVI works as long as you have the proper VfW codecs and are in Windows using C++. And DirectX... well, I think I'll leave that one alone.
Hum, if I'm aiming for simplicity, which one would you recommend? I must admit that AllegAvi non compatibility is a bummer... but I've looked at the code and it seems like something even I could folow.
I've downloaded the APEG files but there's so many things in there that i get lost quite easily
Have you got any manuals for the APEG project? Looks cool but I'm afraid I cant use it by myself, got to learn a lot fore that happens.
Well, still open to whatever suggestions that might come up.
APEG is quite simple. It comes with an example program called exsimple, which shows one of the simplest methods to getting a video to play. Basically, just call
apeg_play_mpg(filename, screen, loop, NULL);
when in a graphics mode. It's just like Allegro's FLI API there.
Past that, you can use the non-blocking poll method.
// Open the file APEG_STREAM *stream = apeg_open_stream(filename); // Call this regularly to check if the video frame updated // If it returns something other than APEG_OK, playback is stopped apeg_advance_stream(stream, loop);
From here you can check if stream->frame_updated > 0, in which case there's a new frame in stream->bitmap for you to show (which you can blit to the screen, or wherever). Then when you're done with the file, call:
apeg_close_stream(stream);
So, a basic loop with this method would be:
1 | int w, h; |
2 | APEG_STREAM *stream; |
3 | |
4 | // Open the stream |
5 | stream = apeg_open_stream(filename); |
6 | if(!stream) |
7 | error(); |
8 | |
9 | // The actual view size may be different than the image size. |
10 | // This gets the full size which we can use stretch_blit with |
11 | apeg_get_video_size(stream, &w, &h); |
12 | |
13 | // Loop through the stream |
14 | while(apeg_advance_stream(stream, FALSE) == APEG_OK) |
15 | { |
16 | // If the stream updated, blit it to the screen |
17 | if(stream->frame_updated > 0) |
18 | stretch_blit(stream->bitmap, screen, 0, 0, stream->w, stream->h, 0, 0, w, h); |
19 | } |
20 | |
21 | // Close the stream |
22 | apeg_close_stream(stream); |
Thank you, I'll get to work on it first thing tomorrow. Thank you every one for your help
And there is MjpgAlleg too, in my signature, but it's a little old hehe, go for apeg or allegavi...
But, if you want to try my lib, you are welcome