title: Saving a stream while playing it using LibVLC
body: <p>Using <a href="http://wiki.videolan.org/Developers_Corner" rel="nofollow noreferrer">LibVLC</a>, I'm trying to save a stream while playing it. This is the python code:</p>
  
  <pre><code>import os
  import sys
  import vlc
  
  if __name__ == '__main__':
      filepath = &lt;either-some-url-or-local-path&gt;
      movie = os.path.expanduser(filepath)
      if 'http://' not in filepath:
          if not os.access(movie, os.R_OK):
              print ( 'Error: %s file is not readable' % movie )
              sys.exit(1)
      instance = vlc.Instance("--sub-source marq --sout=file/ps:example.mpg")
      try:
          media = instance.media_new(movie)
      except NameError:
          print ('NameError: % (%s vs Libvlc %s)' % (sys.exc_info()[1],
                         vlc.__version__, vlc.libvlc_get_version()))
          sys.exit(1)
      player = instance.media_player_new()
      player.set_media(media)
      player.play()
  
      #dont exit!
      while(1):
          continue
  </code></pre>
  
  <p>It saves the video stream to a file <code>example.mpg</code>. As per <a href="http://wiki.videolan.org/Documentation:Streaming_HowTo/Receive_and_Save_a_Stream#Save_a_stream_with_VLC" rel="nofollow noreferrer">this</a> doc, the command to save a stream is this :</p>
  
  <pre><code>--sout=file/ps:example.mpg
  </code></pre>
  
  <p>which I've using when creating an instance of <code>vlc.Instance</code>:</p>
  
  <pre><code>instance = vlc.Instance("--sub-source marq --sout=file/ps:example.mpg")
  </code></pre>
  
  <p>But the problem is that it <em>only</em> saves the stream, it doesn't play the stream simultaneously.</p>
  
  <p><strong>Is there any way (in LibVLC) I can save the stream (to a local file) while paying it?</strong> </p>
  
  <p>Although, I'm looking for a solution in <code>Python 3.3.1</code> but it is fine if there is any C or C++ solution.</p>
  
  <hr>
  
  <p><sup>I've created a similar, but not duplicate, <a href="https://stackoverflow.com/questions/16506504/writing-video-file-and-simultaneously-playing-it">topic</a> yesterday.</sup></p>