我需要从插入PC以太网插座的实时摄像头捕获视频。我首先使用Phonon从我系统中的文件中捕获视频。它工作正常。然后,我创建了一个读取视频的套接字。在这里,我不知道如何获取缓冲数据并将其设置为我的Phonon视频的源!我要感谢有人能帮助我。
以下是阅读视频的代码:
void PlayVideo::rollOn()
{
media = new Phonon::MediaObject(movieLabel);
media->setCurrentSource(Phonon::MediaSource(QString("/home/saman/4.7/phonon_test/sample.mp4")));
videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, movieLabel);
videoPlayer->setFixedSize(QSize(400, 300));
videoPlayer->show();
connect(videoPlayer, SIGNAL(finished()), videoPlayer, SLOT(deleteLater()));
videoPlayer->play(media->currentSource());
}
这就是我在代码中添加套接字的方法:
void PlayVideo::rollOn()
{
udpSocketin = new QUdpSocket(this);
udpSocketin->bind(localPort);
connect(udpSocketin, SIGNAL(readyRead()),this, SLOT(readDatagrams()));
QDataStream out(&datagramout, QIODevice::WriteOnly);
out.setVersion (QDataStream::Qt_4_7);
timer2 = new QTimer(this);
connect(timer2, SIGNAL(timeout()), this, SLOT(playbuff()));
media = new Phonon::MediaObject(movieLabel);
media->setCurrentSource(Phonon::MediaSource(QString("/home/saman/4.7/phonon_test/sample.mp4")));
//media->setCurrentSource (Phonon::MediaSource());
videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, movieLabel);
videoPlayer->setFixedSize(QSize(400, 300));
videoPlayer->show();
connect(videoPlayer, SIGNAL(finished()), videoPlayer, SLOT(deleteLater()));
videoPlayer->play(media->currentSource());
}
void PlayVideo::readDatagrams()
{
if(udpSocketin->hasPendingDatagrams ())
{
datagramin.resize (udpSocketin->pendingDatagramSize ());
qint64 receiveBytes = udpSocketin->readDatagram (datagramin.data (), datagramin.size ));
if(receivedBytes <= 0)
{
qDebug("receivedBytes <= 0");
}
} }
答案 0 :(得分:1)
您可以将数据放入QBuffer
,这是QIODevice
的子类。然后,有一个接受QIODevice
的媒体源构造函数。