February 8, 2013

vwinnie vwinnie
Lab Rat
4 posts

Qt5 multimedia - mjpeg support

 

Hi all,

i’m trying to capture mjpeg stream arriving from a ip camera and display the “video” using QMediaPlayer and QVideoWidget.
The code is very basic:

  1.    
  2. mediaPlayer = new QMediaPlayer;
  3. connect(mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this,        SLOT(currentMediaStatus(QMediaPlayer::MediaStatus)));
  4. mediaPlayer->setMedia(QUrl("http://security.camera.local/mjpg/video.mjpg"));
  5. mediaPlayer->setVideoOutput(videoWidget);
  6. videoWidget->show();
  7. mediaPlayer->play();

Unfortunately the one and only status i can receive is QMediaPlayer::LoadingMedia with QMediaPlayer::StoppedState .
The videoWidget doesn’t display anything.

Does QMediaPlayer support mjpeg at all?
Although i do not receive neither QMediaPlayer::InvalidMedia status nor any other error.
Of course i could use QDesktopServices to display the stream with a web browser but i’d prefer using my own video widget…

Env: Qt5.0.1 mingw47, Windows7 ×64

Thanks:
Rudolf

5 replies

February 13, 2013

noah.k noah.k
Lab Rat
3 posts

Hello,

I am facing the same problem but I get an error when loading the ip camera stream http://../mjpeg.cgi
—>“Error: Failed to load source.”

You need to add an error handler in your code in order to get this error message:
connect(mediaPlayer, SIGNAL), this, SLOT));

In handleError method you can get the error message by this call > mediaPlayer>errorString()

You said:
“Of course i could use QDesktopServices to display the stream with a web browser but i’d prefer using my own video widget…”
Could you be more explicit about this solution, please ? I am really interested.

Thanks.

Noah

February 13, 2013

noah.k noah.k
Lab Rat
3 posts

You need to add an error handler in your code in order to get this error message:

  1. connect(mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError()));

February 13, 2013

vwinnie vwinnie
Lab Rat
4 posts

Hi Noah,

thanks for your reply!
QMediaPlayer has a static member hasSupport. I called it with the appropriate mime type (video/x-motion-jpeg) to determine whether it is supported or not.
The function returned the QMultimedia::MaybeSupported enum which is quite funny…

I’ll check the error signal tomorrow.

QDesktopServices offers methods for accessing common desktop services on different desktop environments.
The static bool QDesktopServices::openUrl(const QUrl& url) method will open your http://../mjpeg.cgi with your default web browser.

Rudolf

February 15, 2013

noah.k noah.k
Lab Rat
3 posts

Hi Rudolf,

Take a look at this [code.google.com] project.

February 17, 2013

vwinnie vwinnie
Lab Rat
4 posts

Appears promising…

Unfortunately now i have to go one step further. The app must support rtsp streams as well so i try to use vlc-qt [qt-apps.org] now

 
  ‹‹ how to link socket programming in c and Qt gui      Qt & Zip files ››

You must log in to post a reply. Not a member yet? Register here!