title: Stream video and audio frames from YouTube
body: <p>I am trying to stream video and audio data from a YouTube video so that I can do some video and audio analysis seperately which is then superimposed on the frames using OpenCV. I have this working perfectly fine with files but want to extend this to streaming from YouTube.</p>
  
  <p>At the moment, I've thought of usings VLC Python bindings to stream from YouTube but I'm not sure how to extract the frames from this video.</p>
  
  <p>Here is the vlc code that performs YouTube streaming at the moment:</p>
  
  <pre><code>import vlc
  import time
  import numpy as np
  from ctypes import *
  
  class MyDisplay(vlc.VideoDisplayCb):
      def __doc__(o,p):
          print "fsdfs"
  
  class MyLock(vlc.VideoLockCb):
      def __doc__():
          raise Exception("sdsds")
          return np.array(500,500).__array_interface__['data']
  
  class MyPlayback(vlc.AudioPlayCb):
      def from_param(self,a,b,c,d):
          print "asfds"
  
  def callbck(a,b,c,d):
      print 'aa'
      print a 
      print b
      print c
      print d
      return 'a'
  
  if __name__ == '__main__':
      url = 'https://www.youtube.com/watch?v=F82XtLmL0tU'
      i = vlc.Instance('--verbose 2'.split())
      media = i.media_new(url)
      media_list = i.media_list_new([url])
  
      p = i.media_player_new()
      p.set_media(media)
  
      lp = i.media_list_player_new()
      lp.set_media_player(p)
      lp.set_media_list(media_list)
      CMPFUNC = CFUNCTYPE(c_char, c_void_p, c_void_p, c_uint, c_long)
  
      lp.next()
      lock = MyLock()
      display = MyDisplay()
  
      playback = MyPlayback()
      p.audio_set_callbacks(CMPFUNC(callbck),None,None,None,None,None)
      p.play()
  
      time.sleep(5)
      r = p.video_take_snapshot(0,'rnd.pong',0,0)
  </code></pre>
  
  <p>How could I produce a stream of frames and audio data using VLC (with Python bindings)? Also is there another way to do this (using ffmpeg for example)?</p>
  
  <p>Thanks</p>