Preamble : this article targets IT developers and deals with the C++ programming language and movie playback.

~

Introduction

Here is a little sum up of a project I’ve been working on for the past few weeks. As you may know, I’ve written the Mac OS X port of SFML 1.x (more exactly from v1.4 to v1.7). Thus I’ve some knowledge about SFML and I’m convinced it’s a really good library for simple multimedia software applications. But its maintainer, Laurent, cannot achieve everything alone, even if developers would need much more features (fitting in SFML’s purpose). He already did a lot, but there’s still a lot to do, and that’s why I decided to work on sfe::Movie.

sfe::Movie is a simple class whose purpose is to display movies with their audio track, the most efficiently and easily as possible. Therefore, if it’s so simple, why would I make a post about it here? For four reasons. First of all because I want this blog to be a sum up of all of my works. Secondly because I want to sum up the work that has been done for this project. Thirdly because I want to do some advertisement for the great library that is SFML. And fourthly because I want to improve my English by writing here (yes this is my first IT article, and it’s in English!).

 

The already-existing projects and their issues

How would one play movies before this project was achieved ? There was no already-writen solution. Or at least, these solutions were only handling video, and not audio. Plus they were usually not easy to use. Here they are :

Lire une vidéo sans le son avec FFMpeg. (french) (tr: reading a movie without audio with FFMpeg)
VideoIntegration : Object Oriented ffmpeg wrapper. Play videos the same way you use images.

While the first project is an adaptation of the SDL tutorial, the second project is much more interesting as it brings a wrapper, and is therefore much easier to use. However, the second project was achieved on the personal purpose of its author, thus I’m not saying it’s « bad » work, but it just doesn’t fit in with more common uses (ie. playing an introduction movie for a video game), especially as it cannot play audio.

The sfe::Movie project

So that’s why I wrote sfe::Movie. I wanted SFML users to be able to play their introduction or transition or whatever-they-want movies as easily as possible and with all of the basic features : playing, stopping, viewing and listening.

sfe::Movie playing Sintel

What sfe::Movie supports:

  • using the audio track
  • using the video track
  • keeping the audio and video tracks synchronized
  • using several threads in order to get better performances with multicore processors
  • playing, pausing or stopping the movie
  • getting a copy of the image currently being displayed
  • automatically scaling the movie to fit a certain frame while preserving it’s original ratio

What sfe::Movie does not support:

  • seeking in the movie

And how are you supposed to achieve that kind of playback ?

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFE Movie Player");
    sfe::Movie movie;

    if (!movie.OpenFromFile("movie.avi"))
        return 1;

    movie.ResizeToFrame(0, 0, 640, 480);
    movie.Play();

    while (window.IsOpened())
    {
        sf::Event ev;
        while (window.GetEvent(ev))
        {
            if (ev.Type == sf::Event::Closed)
                window.Close();
        }

        window.Clear();
        window.Draw(movie);
        window.Display();
    }

    return 0;
}

Results

I’ve successfully read movies with a definition of 2048×872 (see the Sintel movie) on Mac OS X. When I say « successfully » it means there was no frame skipped, the video was not late, and both audio and video were always smooth. As for Windows there is still some testing needed : it works fine on my computer but not with performances as good as with Mac OS X. Especially, I could play a 1280×544 definition movie smoothly, but not a 2048×872 one. It may also depends on my graphic card drivers though.

As for the supported movie formats sfe::Movie can read, these are the one that FFmpeg can read, which mainly means : FLV, H264, MPEG4, Theora, VP8 and WMV.

And as far as the CPU usage is concerned, sfe::Movie uses about 55% CPU for a 2048×872 movie, and 30% CPU for a 1280×544 definition movie on Mac OS X. As for Windows, I have no precise stats to give for now, but it seems to be heavier.

Conclusion

For those of you who are already familiar with SFML, I think you’ll agree we cannot do anything simpler. And for the very few (yes, the very very few!) of you who are not, why are you still waiting here ? Go and have a look at SFML!

However, if you still believe sfe::Movie can be improved, or have any question or any little thing you want to write here, don’t hesitate to leave a comment.

If you’re interested in using the Movie class, you can download the sources from the Git repository and build the library. Note that the project is not yet in a released state yet, even if it’s stable. Thus you may need to update the provided IDE project files in order to build the library successfully.

 

Links

sfeMovie website

Git repository of this project

SFML website

sfeMovie topic on the English forum

Publicités