xiaoweiyao1989 2018-08-08 02:35 采纳率: 0%
浏览 3719
已结题

QT+gstreamer,视频不在窗口显示问题

目前采用ARM芯片为飞思卡尔的imx6,该芯片具备VPU,具备硬件加速的能力。在ARM板上安装UBUNTU14系统,桌面为XFCE桌面,安装gstreamer1.0(使用synaptic一键安装)播放器可以流畅播放高清视频。使用QT5.1.2调用gstreamer1.0,视频无法在指定窗口播放,而是全屏播放
代码摘录如下,请指出不能在正确位置播放是否为调用方法问题?
Widget::Widget(QWidget parent)
: QWidget(parent)
{
/
Create the elements */
data->playbin2 = gst_element_factory_make ("playbin", "playbin2");
g_object_set(data->playbin2, "uri", uri.toUtf8().data(), NULL);

/* Create the GUI */
createUi(data);

/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
bus = gst_element_get_bus (data->playbin2);
    }
    void Widget::createUi (CustomData *data)

{
setWindowTitle(tr("????????"));
setWindowIcon(QIcon(":/new/image/Image/icon_fronware.png"));
resize(600,500);
setStyleSheet("background-color: white;");
qDebug()<<"CURRENT WIDGET"<winId();

 mainLayout = new QVBoxLayout(this);
 mainLayout->setContentsMargins(5,5,5,5);
 mainLayout->setSpacing(5);

 displayWnd = new VideoWidget;
 qDebug()<<"1"<<displayWnd->width()<<displayWnd->height();

 backgroundWnd = new QLabel;
 backgroundWnd->setStyleSheet("background-color: black;");

qDebug()<<"2backgroundWnd"<width()<height();
renderWnd = new QStackedWidget;
//A = new QGstWidget;
renderWnd->addWidget(displayWnd);
renderWnd->addWidget(backgroundWnd);
renderWnd->setCurrentIndex(0);
//qDebug()<<"2"<width()<height();
qDebug()<<"2renderWnd"<width()<height();
qDebug()<<"3renderWnd"<width()<height();
slider = new QSlider(Qt::Horizontal);
slider->setFixedHeight(15);
timeLabel = new QLabel;
timeLabel->setFixedHeight(15);
timeLabel->setStyleSheet("background-color: #ffffff;color:black; font-family:\"STXihei\";font-size: 10px;");
timeLabel->setText("00:00:00/00:00:00");
timeLayout = new QHBoxLayout;
timeLayout->setContentsMargins(0,0,0,0);
timeLayout->setSpacing(5);
timeLayout->addWidget(slider,5);
timeLayout->addWidget(timeLabel,1);

 infoLabel = new QLabel;
 infoLabel->setFixedHeight(25);
 infoLabel->setStyleSheet("background-color: white;color:black; font-family:\"STXihei\";font-size: 15px;");


 openBtn = new QPushButton;
 openBtn->setFixedSize(75,25);
 openBtn->setText("????");
 openBtn->setStyleSheet(" QPushButton{border: 1px solid #C0C0C0; \
                        background-color: white;\
                        border-style: solid;\
                        border-radius:0px;\
                        color:black;\
                        font-family:\"STXihei\";\
                        font-size: 15px;\
                        padding:0 0px;\
                        margin:0 0px;\
                        }\
                        QPushButton:hover{border: 1px solid #C0C0C0; \
                         background-color: #ececec;\
                         border-style: solid;\
                         border-radius:0px;\
                         color:black;\
                         font-family:\"STXihei\";\
                         font-size: 15px;\
                         padding:0 0px;\
                         margin:0 0px;\
                         }\
                        ");

 startBtn = new QPushButton;
 startBtn->setFixedSize(45,25);
 startBtn->setText("??");
 startBtn->setStyleSheet(openBtn->styleSheet());

 stopBtn = new QPushButton;
 stopBtn->setFixedSize(45,25);
 stopBtn->setText("??");
 stopBtn->setStyleSheet(openBtn->styleSheet());

 plauseBtn = new QPushButton;
 plauseBtn->setFixedSize(45,25);
 plauseBtn->setText("??");
 plauseBtn->setStyleSheet(openBtn->styleSheet());
 plauseBtn->setVisible(false);

 muteButton = new QToolButton;
 muteButton->setFixedSize(45,25);
 muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume));

 volumeSlider = new QSlider(Qt::Horizontal);
 volumeSlider->setFixedSize(60,15);
 volumeSlider->setRange(0,100);

 buttonLayout = new QHBoxLayout;
 buttonLayout->setContentsMargins(0,0,0,0);
 buttonLayout->setSpacing(15);
 buttonLayout->addStretch();
 buttonLayout->addWidget(openBtn);
 buttonLayout->addWidget(startBtn);
 buttonLayout->addWidget(plauseBtn);
 buttonLayout->addWidget(stopBtn);
 buttonLayout->addWidget(muteButton);
 buttonLayout->addWidget(volumeSlider);
 buttonLayout->addStretch();

 mainLayout->addWidget(renderWnd,5);
 mainLayout->addWidget(infoLabel,1);
 mainLayout->addLayout(timeLayout);
 mainLayout->addLayout(buttonLayout);

qDebug()<<"3"<width()<height();

 realize_cb(displayWnd,data);


 connect(openBtn,SIGNAL(clicked()),this,SLOT(slotOpenButtonClicked()));
 connect(startBtn,SIGNAL(clicked()),this,SLOT(slotPlayButtonClicked()));
 connect(plauseBtn,SIGNAL(clicked()),this,SLOT(slotPaluseButtonClicked()));
 connect(stopBtn,SIGNAL(clicked()),this,SLOT(slotStopButtonClicked()));
 connect(displayWnd,SIGNAL(fullScreenSignal(bool)),this,SLOT(slotFullScreen(bool)));
 connect(muteButton,SIGNAL(clicked()),this,SLOT(slotmuteButtonClicked()));
 connect(volumeSlider,SIGNAL(sliderMoved(int)),this,SLOT(slotVolumeChange(int)));

 slider->setRange(0,100);
 volumeSlider->setValue(50);
 data->slider = slider;
 connect(slider,SIGNAL(sliderMoved(int)),this,SLOT(seek(int)));
 data->streams_list = infoLabel;
 qDebug()<<"4"<<displayWnd->width()<<displayWnd->height();

}

void Widget::realize_cb(QWidget *widget, CustomData *data)
{
guintptr window_handle;
window_handle = (guintptr)(widget->winId());

gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(data->playbin2),window_handle);
}

 void Widget::playButtonClicked(QPushButton *button, CustomData *data)

{
Q_UNUSED(button);
GstStateChangeReturn ret;
ret = gst_element_set_state (data->playbin2, GST_STATE_PLAYING);
}

  • 写回答

4条回答

  • zqbnqsdsmd 2018-08-09 03:50
    关注
    评论

报告相同问题?

悬赏问题

  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误