2

I would like to use Qt Multimedia to display a video stream. I have run

@server: $gst-launch-1.0 -v videotestsrc  pattern=ball ! video/x-raw,width=1280,height=720 ! jpegenc ! rtpjpegpay ! udpsink name=sink host=localhost port=34400 sync=false async=false         

@client: $gst-launch-1.0 udpsrc port=34400 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG, payload=(int)26" ! rtpjpegdepay ! jpegdec ! filesink location=a.mp4

Its working fine. now I want to server command on one terminal and Qt app should play the part of client so it will play video. I have tried one app but its not working.

main.cpp:

#include <QApplication>
#include <QMediaPlayer>
#include <QWidget>
#include <QVideoWidget>
#include <QBoxLayout>
#include <QProcess>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *window = new QWidget;
    QVideoWidget *videoWidget = new QVideoWidget;
    QBoxLayout *layout = new QVBoxLayout;
    QMediaPlayer *player = new QMediaPlayer;
    QProcess *process = new QProcess;

    layout->addWidget(videoWidget);
    window->setLayout(layout);
    window->show();
    player->setVideoOutput(videoWidget);
    QString program = "gst-launch-1.0";
    QStringList arguments;
    arguments << "udpsrc" << "port=34400" << "caps=application/x-rtp, media=(string)video, 
    clock-rate=(int)90000, encoding-name=(string)JPEG, payload=(int)26" << "!" << "rtpjpegdepay" 
    << "!" << "jpegdec" << "!" << "filesink location=a.mp4" ;
    
    process->setReadChannel(QProcess::StandardError);
    process->start(program, arguments);

    while (!process->waitForReadyRead()) {}

    player->setMedia(QMediaContent(), process);
    player->play();

    return a.exec();

project.pro:

QT       += core gui multimedia multimediawidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = video_play_file
TEMPLATE = app


SOURCES += main.cpp\
        dialog.cpp

HEADERS  += dialog.h

FORMS    += dialog.ui
karlphillip
  • 92,053
  • 36
  • 243
  • 426
Pooja
  • 33
  • 1
  • 7

1 Answers1

0

Since Qt 5.12.2, you can pass GStreamer pipelines to QMediaPlayer::setMedia() if the GStreamer backend is used. In your case the code for setMedia() should look something like this (untested):

...
player->setMedia(QUrl("gst-pipeline: udpsrc port=34400 caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG, payload=(int)26\" ! rtpjpegdepay ! jpegdec ! videoconvert ! xvimagesink name=\"qtvideosink\""));
...

Take a look at the documentation for more information.

ptr
  • 316
  • 1
  • 3
  • Thanks for u r prompt help. i have first tested ```player = new QMediaPlayer; player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink")); player->play(); qDebug() <state(); return a.exec(); }``` but throwing Error: "No URI handler implemented for \"gst-pipeline\"." – Pooja Oct 22 '20 at 14:24
  • What version of Qt do you use? At least Qt 5.12.2 is required. Is your Qt client app running on Linux? The Gstreamer backend of Qt Multimedia is only supported on Linux. – ptr Oct 22 '20 at 18:42
  • Yes right ,because of Qt version i am using (QT Creator 3.5.1). so i have stared to build a new QT version Qt 5.12.0 . – Pooja Oct 23 '20 at 06:36
  • could you please suggest me Qt version which support Gstreamer pipeline and links to setup that QT on linux facing some issue with version 5.12.0. – Pooja Oct 23 '20 at 15:48
  • The documentation states that at least Qt 5.12.2 is required. Install the latest Ubuntu LTS version (20.04, Focal Fossa). It includes libqt5multimedia5 version 5.12.8. Look here for instructions: https://ubuntu.com/tutorials/install-ubuntu-desktop – ptr Oct 24 '20 at 17:14
  • I think that is out of scope of your original questions. Start a new question for such instructions. – ptr Oct 27 '20 at 10:10
  • Yes right ptr. I have setup Qt 5.12.0 on ubuntu 16.06 LTS. – Pooja Oct 27 '20 at 10:31
  • Hello ptr, I have setup Qt 5.12.9 on ubuntu and tried above application with u r comment. i am able to build and run but Qt widget showing nothing on screen. could you please suggest ? – Pooja Oct 28 '20 at 07:21
  • Hello ptr. i have edited my application but still facing same issue. – Pooja Oct 28 '20 at 11:25