简体   繁体   English

使用RTP在Qt Linux应用程序上的视频流

[英]Video Streaming on Qt Linux application using RTP

I developed Qt application on Linux which can play multiple media file with simultaneously, but in this application source was media file, now I want to play RTP video, means my source will be "rtsp://IPAddress:port/test.sdp". 我在Linux上开发了可以同时播放多个媒体文件的Qt应用程序,但是在此应用程序源中是媒体文件,现在我要播放RTP视频,这意味着我的源代码将是“ rtsp:// IPAddress:port / test.sdp” 。

Please help me to develop application for live streaming using RTP on QT Linux application. 请帮助我开发在QT Linux应用程序上使用RTP进行实时流式传输的应用程序。

EDITED : My code to play multiple video Simultaneously. 编辑:我的代码可以同时播放多个视频。

#include "mainwindow.h"
#include "ui_mainwindow.h"

int max=0;
int row=0;
int column=0;
int flag = 0;
extern int he;
extern int wi;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //disable other option before choose layout...
    ui->menuFile->setDisabled(1);
    ui->menuVideo->setDisabled(1);
    ui->actionOpen->setDisabled(1);
    ui->actionPlay->setDisabled(1);
    ui->actionPause->setDisabled(1);
    ui->actionStop->setDisabled(1);
}

MainWindow::~MainWindow()
{
    delete ui;
}


//for 1_row x 1_column
void MainWindow::on_action1_X_1_triggered(){

    row = 1;
    column = 1;

    ui->menuFile->setEnabled(1);
    ui->menuVideo->setEnabled(1);
    ui->actionOpen->setEnabled(1);
    ui->actionPlay->setEnabled(1);
    ui->actionPause->setEnabled(1);
    ui->actionStop->setEnabled(1);

    video_layout();
}

//for 2_row x 2_column
void MainWindow::on_action2_X_2_triggered(){

    row = 2;
    column = 2;

    ui->menuFile->setEnabled(1);
    ui->menuVideo->setEnabled(1);
    ui->actionOpen->setEnabled(1);
    ui->actionPlay->setEnabled(1);
    ui->actionPause->setEnabled(1);
    ui->actionStop->setEnabled(1);

    video_layout();
}

//for 3_row x 3_column
void MainWindow::on_action3_X_3_triggered(){

    row = 3;
    column = 3;

    ui->menuFile->setEnabled(1);
    ui->menuVideo->setEnabled(1);
    ui->actionOpen->setEnabled(1);
    ui->actionPlay->setEnabled(1);
    ui->actionPause->setEnabled(1);
    ui->actionStop->setEnabled(1);

    video_layout();
}

//for 4_row x 4_column
void MainWindow::on_action4_X_4_triggered(){

    row = 4;
    column = 4;

    ui->menuFile->setEnabled(1);
    ui->menuVideo->setEnabled(1);
    ui->actionOpen->setEnabled(1);
    ui->actionPlay->setEnabled(1);
    ui->actionPause->setEnabled(1);
    ui->actionStop->setEnabled(1);

    video_layout();
}


//for custom row and column
void MainWindow::on_actionCustom_triggered(){

    //Pop-up window call to get data of Row and Column
    Dialog* popup = new Dialog();
    popup->exec();

    ui->menuFile->setEnabled(1);
    ui->menuVideo->setEnabled(1);
    ui->actionOpen->setEnabled(1);
    ui->actionPlay->setEnabled(1);
    ui->actionPause->setEnabled(1);
    ui->actionStop->setEnabled(1);

    video_layout();
}


//Create Layout with MultiMedia and Player as per Row and Column...
void MainWindow::video_layout(){
    static int k = 0;
    int a=0;

    //clear older layout if created...
    while(k>0){
        view[a]->close();
        slider[a]->close();
        bar[a]->close();
        slider1[a]->close();
        k--;
        a++;
    }

    //set size of Video Screen
    if(flag == 0){
        wi -= 40;
        he -= 120;
        flag = 1;
    }

    //create Layout with Player
    for(int i=0; i<row; i++){
        for(int j=0; j<column; j++){
            view[k] = new QGraphicsView(this->centralWidget());
            view[k]->setGeometry((j*((wi/column)+5))+10,(i*((he/row)+5))+10,wi/column,he/row);
            view[k]->show();

            player[k] = new QMediaPlayer;
            vw[k] = new QVideoWidget;

            player[k]->setVideoOutput(vw[k]);
            view[k]->setViewport(vw[k]);

            slider[k] = new QSlider(this);
            bar[k] = new QProgressBar(this);
            slider1[k] = new QSlider(this);

            slider[k]->setOrientation(Qt::Horizontal);

            ui->statusBar->addPermanentWidget(slider[k]);
            ui->statusBar->addPermanentWidget(bar[k]);
            ui->statusBar->addPermanentWidget(slider1[k]);

            connect(player[k],&QMediaPlayer::durationChanged,slider[k],&QSlider::setMaximum);
            connect(player[k],&QMediaPlayer::positionChanged,slider[k],&QSlider::setValue);
            connect(slider[k],&QSlider::sliderMoved,player[k],&QMediaPlayer::setPosition);

            slider1[k]->setValue(50);
            connect(slider1[k],&QSlider::sliderMoved,player[k],&QMediaPlayer::setVolume);

            connect(player[k],&QMediaPlayer::durationChanged,bar[k],&QProgressBar::setMaximum);
            connect(player[k],&QMediaPlayer::positionChanged,bar[k],&QProgressBar::setValue);

            k++;
            max = k;
        }
    }
}

//select video file for Open..
void MainWindow::on_actionOpen_triggered()
{
    QString filename = QFileDialog::getOpenFileName(this,"Open a File","","Video File (*.*)");
    on_actionStop_triggered();

    for(int i=0; i<max; i++){
        player[i]->setMedia(QUrl::fromLocalFile(filename));
    }
    on_actionPlay_triggered();
}

//Play video...
void MainWindow::on_actionPlay_triggered()
{
    for(int i=0; i<max; i++)
        player[i]->play();
    ui->statusBar->showMessage("Playing");
}

//Pause Video...
void MainWindow::on_actionPause_triggered()
{
    for(int i=0; i<max; i++)
        player[i]->pause();

    ui->statusBar->showMessage("Paused...");
}

//Stop Video...
void MainWindow::on_actionStop_triggered()
{
    for(int i=0; i<max; i++)
        player[i]->stop();

    ui->statusBar->showMessage("Stopped");
}


//Mute Video...
void MainWindow::on_actionMute_triggered()
{
    for(int i=0; i<max; i++)
        if(player[i]->isMuted()){
            player[i]->setMuted(0);
        }else{
            player[i]->setMuted(1);
        }

    ui->statusBar->showMessage("Muted...");
}

Thanks. 谢谢。

Thanks buddy, 谢谢哥们儿,

Now requirement change by client, Now I have to show frame which store by rtsp client. 现在需求由客户端更改,现在我必须显示由rtsp客户端存储的框架。 So this question not much more useful for me. 所以这个问题对我来说没有多大用处。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM