title: Playing H264 video stream (from raspberri pi) in Qt
body: <p>I have a working streaming device (raspberry pi with camera module - it has a tool called "raspivid"), from which I am streaming live video using netcat</p>
  
  <pre><code>raspivid -t 999999 -w 300 -h 300 -hf -fps 20 -o - | nc -l 9999
  </code></pre>
  
  <p>In Ubuntu, after connecting to the device using netcat and streaming video to mplayer, everything works like a charm...</p>
  
  <pre><code>nc *ip* 9999 | mplayer -fps 200 -demuxer h264es -
  </code></pre>
  
  <p>Now, I want to make this video available for Windows users (with minimal setup required, possibly only an .exe).
  I decided to use Qt 5 - it has qTcpSocket and QMediaPlayer (according to doc, it supports stream-input). 
  I already have some code which can read data from socket and also play local files.</p>
  
  <p>But playing streams does not seem to work. Maybe it is because the video format and some codecs ? WMP also cant play the video I saved using raspivid, although vlc plays it perfectly.
  I also tested cat'ing a simple .avi file (which Qt plays successfully from local disc) in raspberry pi and playing the same TcpStream in Qt with no success.</p>
  
  <p>Also, after netcat'ing from PI and running the compiled program in Windows, I can see that the LED on wifi dongle on raspberry pi starts flashing - so the stream arrives in the application.</p>
  
  <p>Could you maybe give me some advice, what to do/try next?</p>
  
  <p>I have not much previous experience with C++, so if I am asking something really wrong, please do not hit me too hard :)</p>
  
  <p>Also, the "SimpleChatClient" comes from a random template I started working on..</p>
  
  <pre><code>SimpleChatClient::SimpleChatClient(QWidget* parent, Qt::WindowFlags flags)
  : QWidget(parent, flags)
  {
      QVBoxLayout* main   = new QVBoxLayout(this);
      player = new QMediaPlayer(this, QMediaPlayer::StreamPlayback);
      QVideoWidget* widget = new QVideoWidget;
      widget-&gt;show();
      player-&gt;setVideoOutput(widget);
      main-&gt;addWidget(widget);
      setLayout(main);
      socket = new QTcpSocket(this);
      connect(socket, SIGNAL(connected()), this, SLOT(playStream()));
      toggleConnection();
  }
  
  SimpleChatClient::~SimpleChatClient()
  {
  }
  
  void SimpleChatClient::toggleConnection()
  {
      if (socket-&gt;state() == QAbstractSocket::UnconnectedState)
      {
          socket-&gt;connectToHost(SERVER, PORT);
      }
      else
      {
          socket-&gt;disconnectFromHost();
      }
  }
  
  void SimpleChatClient::playStream()
  {
      player-&gt;setMedia(QMediaContent(), socket);
      //player-&gt;setMedia(QUrl::fromLocalFile("C:\\Users\\m\\d.avi")); //This works for local files
      if (socket-&gt;canReadLine())
      {
          player-&gt;play();
      }
  }
  </code></pre>