Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过以太网插座从摄像头捕获视频_C++_Qt - Fatal编程技术网

C++ 如何通过以太网插座从摄像头捕获视频

C++ 如何通过以太网插座从摄像头捕获视频,c++,qt,C++,Qt,我需要从连接到我的PC以太网插座的实时摄像机中捕获视频。我首先使用声子从系统中的文件中捕获视频。它很好用。然后,我创建了一个套接字来读取视频。在这里,我不知道如何获取缓冲数据并将其设置为声子视频的源!如果有人能帮我做这件事,我将不胜感激 以下是阅读视频的代码: void PlayVideo::rollOn() { media = new Phonon::MediaObject(movieLabel); media->setCurrentSource(Phonon::Med

我需要从连接到我的PC以太网插座的实时摄像机中捕获视频。我首先使用声子从系统中的文件中捕获视频。它很好用。然后,我创建了一个套接字来读取视频。在这里,我不知道如何获取缓冲数据并将其设置为声子视频的源!如果有人能帮我做这件事,我将不胜感激

以下是阅读视频的代码:

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");
   }    
void PlayVideo::rollOn()
{
udpSocketin=新的QUdpSocket(此);
udpSocketin->bind(本地端口);
连接(udpSocketin,信号(readyRead()),此,插槽(readDatagrams());
QDataStream out(&datagramout,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_7);
timer2=新的QTimer(此);
连接(timer2,信号(timeout()),此,插槽(playbuff());
媒体=新声子::媒体对象(movieLabel);
media->setCurrentSource(Phonon::MediaSource(QString(“/home/saman/4.7/Phonon_test/sample.mp4”));
//media->setCurrentSource(声子::MediaSource());
视频播放器=新的声子::视频播放器(声子::视频类别,电影标签);
视频播放器->设置固定大小(QSize(400300));
视频播放器->显示();
连接(视频播放器,信号(完成()),视频播放器,插槽(删除稍后());
视频播放器->播放(媒体->当前源代码());
}    
void PlayVideo::readDatagrams()
{
if(udpSocketin->hasPendingDatagrams())
{
datagramin.resize(udpSocketin->pendingDatagramSize());
qint64 receiveBytes=udpSocketin->readDatagram(datagramin.data(),datagramin.size));

如果(receivedBytes您可以将数据放入
QBuffer
,这是
QIODevice
的子类。然后,有一个媒体源构造函数在将来接受
QIODevice

,您可以高亮显示代码并点击ctrl-k以获得堆栈溢出以生成代码块(假设这里每行有4个空格)。我不太确定如何解释您的问题,您的套接字是QSocket吗?QSocket还实现了QIODevice,因此您可以将其直接传递给Phonon::MediaSource。。。