Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Video on Linux [closed]

Tags:

c

linux

video

I need to write a small software that will show video. I don't know any thing about graphics at C.

What classes are there? Please point me to a place to start from.

Thanks, Nahum

like image 938
nmnir Avatar asked Dec 31 '25 05:12

nmnir


2 Answers

Another simple library to use to display video is OpenCV (cross-platform):

int main(int argc, char** argv) 
{
    cvNamedWindow("xsample", CV_WINDOW_AUTOSIZE);

    CvCapture* capture = cvCreateFileCapture("movie.avi");
    if (!capture)
    {
      printf("!!! cvCreateFileCapture didn't found the file !!!\n");
      return -1; 
    }

    IplImage* frame;
    while(1) 
    {
        frame = cvQueryFrame( capture );
        if (!frame) 
            break;

        cvShowImage( "xsample", frame );

        char c = cvWaitKey(33);
        if (c == 27) 
            break; // ESC was pressed
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("xsample");

    return 0;
}

And that's it. However, you won't be able to play sound with OpenCV, just video. But if you are looking for a workaround on that, here is a little something I wrote some time ago using OpenCV and FFmpeg.

like image 113
karlphillip Avatar answered Jan 02 '26 23:01

karlphillip


I don't know any thing about graphics at C

I strongly suggest you learn this first otherwise you'll have a hard time doing it.

Anyway: writing a well performing video player is no small feat. Luckily there are readily usable multimedia packages for Linux:

  • libxine
  • ffmpeg libraries (libavformat, libavdevice, libavcodec and libswscale) -- used by mplayer
  • VLC
  • GStreamer

All of these can be embedded into your own program. Personally I recommend either libxine or the ffmpeg libraries, as those are the IMHO most solid and straightforward to use. GStreamer looks nice on the paper, but has problems with stability (in my experience).

like image 30
datenwolf Avatar answered Jan 02 '26 23:01

datenwolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!