3

Given below is the code for playing a video file using Qt. Instead of playing the video I want to play a live video stream from an IP Camera. Another approach is to embed the VLC Player in Qt and a link for the project is provided here. The problem is I do not know how to include the player in Qt. So how do I proceed?

#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QFile>
#include <QHBoxLayout>
#include "DemoPlayer.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *widget=new QWidget;
    widget->resize(400,300);

    QMediaPlayer *player=new QMediaPlayer;
    QVideoWidget *vw= new QVideoWidget;
    QHBoxLayout *layout=new QHBoxLayout;

    layout->addWidget(vw);
    widget->setLayout(layout);
    player->setVideoOutput(vw);
    player->setMedia(QUrl::fromLocalFile("C:/Users/Administrator/Desktop/1minute.mp4"));
    player->play();
    widget->show();
    qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();

    return a.exec();
}
praxmon
  • 5,009
  • 22
  • 74
  • 121
  • The above code works just fine....please make your question a bit more clear – Metoo Jan 30 '14 at 07:16
  • @Metoo check the question now. – praxmon Jan 30 '14 at 07:18
  • 1
    Have you tried LibVLC https://wiki.videolan.org/LibVLC_SampleCode_Qt – Metoo Jan 30 '14 at 07:21
  • @Metoo I have, cannot add it to the app, I am new to Qt so I don't know how to do so. If you know how to add it, then please tell me how to do it, or if there exists any tutorial tell me, because I cannot find any. – praxmon Jan 30 '14 at 07:22
  • 1
    Are you on a system supporting X11 ie Linux, Mac (to some extent)? Btw the link provided by metoo is already a tutorial by itself... – UmNyobe Jan 30 '14 at 08:14
  • Dont have qmake, and no, sadly on windows. – praxmon Jan 30 '14 at 08:16

1 Answers1

6

follow this code . you can embed a widget inside another widget using a valid window id . How to show output video of other application in Qt? you can use the qx11embedwidget and qx11embedwidgetcontainer QX11EmbedWidget and QX11EmbedContainer

Community
  • 1
  • 1
Wagmare
  • 1,354
  • 1
  • 24
  • 58
  • The link is not opening. Are you sure that its a valid link? – praxmon Feb 03 '14 at 07:04
  • just check for qx11EmbedWidget and QX11EmbedContainer.. can you able to open the stack overflow thread ..? – Wagmare Feb 03 '14 at 07:14
  • I can open the thread but cannot open the link provided in the answer. That's the problem. – praxmon Feb 03 '14 at 07:18
  • for me also . but you can start searching for QX11EmbedWidget. the required widget container you are looking for – Wagmare Feb 03 '14 at 07:26
  • The QX11EmbedWidget class provides an XEmbed client widget. XEmbed is an X11 protocol that supports the embedding of a widget from one application into another application. An XEmbed client widget is a window that is embedded into a container. A container is the graphical location that embeds (or swallows) an external application. – Wagmare Feb 03 '14 at 07:26
  • Ah, okay. I get it. Will read about it and come back to you if I have any problems. Thanks :) – praxmon Feb 03 '14 at 07:38
  • What is the header file that I am supposed to use? I am using the normal #include as given in the documentation but it gives the error saying:No such file or Directory. What should I do? – praxmon Feb 03 '14 at 09:53
  • your qt version ?. QWidget based application running on X11 better stay with Qt4. http://www.qtcentre.org/threads/54922-Qt5-and-embedwidgets – Wagmare Feb 03 '14 at 10:19
  • Qt 5.2.0, I downloaded it recently so... Which Qt4 version do I need to use in order to use it? – praxmon Feb 03 '14 at 10:19
  • sorry ..you cant do .. there is no replacement for qx11embedwidget in qt5 and plus. – Wagmare Feb 03 '14 at 10:21
  • So which Qt4 version do I use? – praxmon Feb 03 '14 at 10:21
  • 4.8, 4.8.x any version .. there is even a sample application on QX11embedWidget for 4.8 in the link i send you recently . this one again http://www.qtcentre.org/threads/54922-Qt5-and-embedwidgets 12th reply – Wagmare Feb 03 '14 at 10:25
  • Check out this link: http://stackoverflow.com/questions/21527851/qx11embedcontainer-code-error Another answer for you :P If you manage to solve it though – praxmon Feb 03 '14 at 12:51