0

我需要从插入我的 PC 以太网插座的实时摄像头捕捉视频。我首先使用 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");
   }    

} }

4

1 回答 1

1

您可以将数据放入 中QBuffer,它是 的子类QIODevice。然后,有一个接受QIODevice.

于 2012-08-14T07:41:55.403 回答