How can you play videos in C++, I am quite willing to use more than less any headers, I basically need a code that will work like this:

#include "PlayVideos.h"
int main(int argc, char *argv[])
{
    SDL_Surface *screen=SDL_SetVideoMode(WINWIDTH,WINHEIGHT,WINBPP,SDL_SWSURFACE);
    ShowVideo("MyVideo.avi",0,0,screen);//play a video at position 0,0 and apply it to the screen while playing sound
    return 0;
}

or if it can't be done via blitting to a screen surface then I would settle for an external command like:

#include "PlayVideos.h"
int main(int argc, char *argv[])
{
    ShowVideo("MyVideo.avi");//Play a video
    return 0;
}

Any Ideas?

Recommended Answers

All 3 Replies

I don't know much about that. But gstreamer is the classic tool for video loading / decoding / displaying. Look at the list of plugins, they have several "videosink" (which is the lingo for "displaying the video"), I believe it can be easily be used with OpenGL, SDL, X, Xv, OSX, DirectX, and other less well-known rendering systems.

Then, there is also the well-known VideoLAN (VLC). You can use libvlc to embed video into either an SDL surface or a Qt widget. With all the video formats that VLC supports.

Then, phonon which can be used in Qt4.5 and above.

There are plenty of options to choose from.

OpenCV is another which can easily grab raw video and display it on a separate window.

The list could go on... This depends also one whether you want to decode video files or if you want to display/record a raw video input (IP camera, firewire, etc.). VLC is probably the most comprehensive solution. But again, I don't know much about video.

Thanks, VLC is awesome, quick (hopefully) follow-up question that may or may not be related. What is the standard for screen dimensions and pixel density, E.G.: My screen is 1440x900 px at 96 dpi.

There are no real "standard" screen size. There are big screens, small screens, higher and lower pixel density.

The common aspect ratios are 4:3 (full-screen), 16:9 (wide-screen), and sometimes 16:10. And common pixel dimensions would be 1900x1080 (16:9), 960x720 (4:3), 1440x1080 (4:3), and so on.. I really don't think it should matter, your program should do like any good video player: start the video at the native size of the video, and allow the user to resize the screen at his will.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.