コード例 #1
0
ファイル: vplayer.py プロジェクト: pymedia/pymedia
    def p(file, t):
        pygame.init()
        pygame.display.set_mode((800, 600), 0)
        player.startPlayback({'name': file})
        player.start()
        player.setOverlay((0, 0, 800, 600))
        while player.isPlaying() == 0 and len(player.err) == 0:
            time.sleep(.05)
        while player.isPlaying():
            if (t > 0 and player.getPTS() > t):
                player.stopPlayback()
                break
            ev = pygame.event.get()
            if len(ev) == 0:
                time.sleep(0.01)
            for e in ev:
                if e.type == pygame.KEYDOWN:
                    if e.key == pygame.K_ESCAPE:
                        player.stopPlayback()
                        break
                    if e.key == pygame.K_RIGHT:
                        player.seekRelative(SEEK_SEC)
                    if e.key == pygame.K_LEFT:
                        player.seekRelative(-SEEK_SEC)

        if len(player.err):
            raise player.err[0]
コード例 #2
0
ファイル: vplayer_v.py プロジェクト: pymedia/pymedia
 def p( file, t ):
   pygame.init()
   pygame.display.set_mode( (800,600), 0 )
   player.startPlayback( { 'name': file } )
   player.start()
   player.setOverlay( (0,0,800,600) )
   while player.isPlaying()== 0 and len( player.err )== 0:
     time.sleep( .05 )
   while player.isPlaying():
     if ( t> 0 and player.getPTS()> t ):
       player.stopPlayback()
       break
     ev= pygame.event.get()
     if len( ev )== 0:
       time.sleep( 0.01 )
     for e in ev:
       if e.type== pygame.KEYDOWN: 
         if e.key== pygame.K_ESCAPE: 
             player.stopPlayback()
             break
         if e.key== pygame.K_RIGHT: 
             player.seekRelative( SEEK_SEC )
         if e.key== pygame.K_LEFT: 
             player.seekRelative( -SEEK_SEC )
   
   if len( player.err ):
     raise player.err[ 0 ]
コード例 #3
0
def run(file):
    pygame.init()
    pygame.display.set_mode((800, 600), 0)
    callback = PlayerCallback()
    player = pymedia.Player(callback)
    player.start()
    # Stat the path
    if os.path.isfile(file):
        files = [file]
    else:
        files = [os.path.join(file, x) for x in os.listdir(file)]

    stopped = False
    i = 0
    while i < len(files) and not stopped:
        f = files[i]
        print 'Playing %s...' % f
        player.startPlayback(open(f, 'rb'), f.split('.')[-1].lower())
        i += 1

        while player.isPlaying() and not stopped:
            time.sleep(PLAYER_DELAY)
            ev = pygame.event.get()
            br = False
            for e in ev:
                if e.type == pygame.KEYDOWN:
                    if e.key == pygame.K_ESCAPE:
                        stopped = True
                    if e.key == pygame.K_LEFT:
                        print 'seek backward', player.getPosition(
                        ), player.getLength()
                        player.seekTo(player.getPosition() - 20)
                    if e.key == pygame.K_RIGHT:
                        print 'seek forward', player.getPosition(
                        ), player.getLength()
                        player.seekTo(player.getPosition() + 10)
                    if e.key == pygame.K_UP:
                        br = True
                        break
                    if e.key == pygame.K_DOWN:
                        if i > 1:
                            br = True
                            i -= 2
                            break

            if br:
                break

    if len(player.getError()) > 0:
        print 'Error detected'
        print player.getError()[0][1]

    player.stopPlayback()
    player.stop()
    while player.isRunning():
        time.sleep(PLAYER_DELAY)
コード例 #4
0
ファイル: player.py プロジェクト: pymedia/pymedia
def run( file ):
  pygame.init()
  pygame.display.set_mode( (800,600), 0 )
  callback= PlayerCallback()
  player= pymedia.Player( callback )
  player.start()
  # Stat the path
  if os.path.isfile( file ):
    files= [ file ]
  else:
    files= [ os.path.join( file, x ) for x in os.listdir( file ) ]
  
  stopped= False
  i= 0
  while i< len( files ) and not stopped:
    f= files[ i ]
    print 'Playing %s...' % f
    player.startPlayback( open( f, 'rb' ), f.split( '.' )[ -1 ].lower() )
    i+= 1
    
    while player.isPlaying() and not stopped:
      time.sleep( PLAYER_DELAY )
      ev= pygame.event.get()
      br= False
      for e in ev:
        if e.type== pygame.KEYDOWN:
          if e.key== pygame.K_ESCAPE: 
            stopped= True
          if e.key== pygame.K_LEFT:
            print 'seek backward', player.getPosition(), player.getLength()
            player.seekTo( player.getPosition()- 20 )
          if e.key== pygame.K_RIGHT:
            print 'seek forward', player.getPosition(), player.getLength()
            player.seekTo( player.getPosition()+ 10 )
          if e.key== pygame.K_UP:
            br= True
            break
          if e.key== pygame.K_DOWN:
            if i> 1:
              br= True
              i-= 2
              break
      
      if br:
        break
  
  if len( player.getError() )> 0:
    print 'Error detected'
    print player.getError()[ 0 ][ 1 ]
  
  player.stopPlayback()
  player.stop()
  while player.isRunning():
    time.sleep( PLAYER_DELAY )
コード例 #5
0
ファイル: player.py プロジェクト: gromaudio/dashtest
def run( file ):
  pygame.init()
  pygame.display.set_mode( (800,600), 0 )
  callback= PlayerCallback()
  player= pymedia.Player( callback )
  player.start()
  player.startPlayback( file )
  stopped= False
  
  while player.isPlaying() and not stopped:
    time.sleep( PLAYER_DELAY )
    ev= pygame.event.get()
    for e in ev:
      if e.type== pygame.KEYDOWN:
        if e.key== pygame.K_ESCAPE: 
          stopped= True
        if e.key== pygame.K_LEFT:
          print 'seek left'
        if e.key== pygame.K_RIGHT:
          print 'seek right'
  
  player.stopPlayback()
  player.stop()
コード例 #6
0
ファイル: vplayer.py プロジェクト: vleo/vleo-notebook
        return open( f['name'], 'rb' )
      def getPathName( self, f ):
        return f[ 'name' ]
      def getExtension( self, f ):
        return f[ 'name' ].split( '.' )[ -1 ].lower()
    
    cache= Cache()
  
  # Menu module instance for standalone testing

  menu= Menu()
  
  if len( sys.argv )< 2 or len( sys.argv )> 3:
      print 'Usage: vplayer <file_name>'
  else:
      pygame.init()
      pygame.display.set_mode( (800,600), 0 )
      player.startPlayback( { 'name': sys.argv[ 1 ] } )
      player.start()
      player.setOverlay( (0,0,800,600) )
      while player.isPlaying()== 0:
          time.sleep( .05 )
      while player.isPlaying():
        e= pygame.event.wait()
        if e.type== pygame.KEYDOWN: 
            if e.key== pygame.K_ESCAPE: 
                player.stopPlayback()
                break
            if e.key== pygame.K_RIGHT: 
                player.seekRelative( SEEK_SEC )
            if e.key== pygame.K_LEFT: 
コード例 #7
0
ファイル: video_bench_ovl.py プロジェクト: pymedia/pymedia
def videoDecodeBenchmark(inFile, opt):
    pygame.init()
    pygame.display.set_mode((800, 600), 0)
    ovl = None

    dm = muxer.Demuxer(inFile.split('.')[-1])
    f = open(inFile, 'rb')
    s = f.read(400000)
    r = dm.parse(s)
    v = filter(lambda x: x['type'] == muxer.CODEC_TYPE_VIDEO, dm.streams)
    if len(v) == 0:
        raise 'There is no video stream in a file %s' % inFile

    v_id = v[0]['index']
    print 'Assume video stream at %d index: ' % v_id

    a = filter(lambda x: x['type'] == muxer.CODEC_TYPE_AUDIO, dm.streams)
    if len(a) == 0:
        print 'There is no audio stream in a file %s. Ignoring audio.' % inFile
        opt = 'noaudio'
    else:
        a_id = a[0]['index']

    t = time.time()

    vc = vcodec.Decoder(dm.streams[v_id])
    print dm.streams[v_id]
    if opt != 'noaudio':
        ac = acodec.Decoder(dm.streams[a_id])
    resampler = None
    frames = 0
    q = []
    while len(s) > 0:
        for fr in r:
            if fr[0] == v_id:
                d = vc.decode(fr[1])
                if d and d.data:
                    frames += 1
                    #ff= open( 'c:\\test', 'wb' )
                    #ff.write( d.data[ 0 ] )
                    #ff.close()
                    if not ovl:
                        ovl = pygame.Overlay(YV12, d.size)
                    q.append(d)
                    if len(q) > 4:
                        try:
                            ovl.set_data(q[0].data)
                            ovl.display()
                        except:
                            ovl.display(q[0].data)

                        del (q[0])
            elif opt != 'noaudio' and fr[0] == a_id:
                d = ac.decode(fr[1])
                if resampler == None:
                    if d and d.channels > 2:
                        resampler = sound.Resampler(
                            (d.sample_rate, d.channels), (d.sample_rate, 2))
                else:
                    data = resampler.resample(d.data)

        s = f.read(400000)
        r = dm.parse(s)

        tt = time.time() - t
        print '%d frames in %d secs( %.02f fps )' % (frames, tt,
                                                     float(frames) / tt)

        ev = pygame.event.get()
        for e in ev:
            if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                s = ''
                break
コード例 #8
0
ファイル: video_bench_ovl.py プロジェクト: gromaudio/dashtest
def videoDecodeBenchmark( inFile, opt ):
  pygame.init()
  pygame.display.set_mode( (800,600), 0 )
  ovl= None
  
  dm= muxer.Demuxer( inFile.split( '.' )[ -1 ] )
  f= open( inFile, 'rb' )
  s= f.read( 400000 )
  r= dm.parse( s )
  v= filter( lambda x: x[ 'type' ]== muxer.CODEC_TYPE_VIDEO, dm.streams )
  if len( v )== 0:
    raise 'There is no video stream in a file %s' % inFile
  
  v_id= v[ 0 ][ 'index' ]
  print 'Assume video stream at %d index: ' % v_id
  
  a= filter( lambda x: x[ 'type' ]== muxer.CODEC_TYPE_AUDIO, dm.streams )
  if len( a )== 0:
    print 'There is no audio stream in a file %s. Ignoring audio.' % inFile
    opt= 'noaudio'
  else:
    a_id= a[ 0 ][ 'index' ]
  
  t= time.time()
  
  vc= vcodec.Decoder( dm.streams[ v_id ] )
  print dm.streams[ v_id ]
  if opt!= 'noaudio':
    ac= acodec.Decoder( dm.streams[ a_id ] )
  resampler= None
  frames= 0
  q= []
  while len( s )> 0:
    for fr in r:
      if fr[ 0 ]== v_id:
        d= vc.decode( fr[ 1 ] )
        if d and d.data:
          frames+= 1
          #ff= open( 'c:\\test', 'wb' )
          #ff.write( d.data[ 0 ] )
          #ff.close()
          if not ovl:
            ovl= pygame.Overlay( YV12, d.size )
          q.append( d )
          if len( q )> 4:
            try:
              ovl.set_data( q[0].data )
              ovl.display()
            except:
              ovl.display(q[0].data)
            
            del( q[0] )
      elif opt!= 'noaudio' and fr[ 0 ]== a_id:
        d= ac.decode( fr[ 1 ] )
        if resampler== None:
          if d and d.channels> 2:
            resampler= sound.Resampler( (d.sample_rate,d.channels), (d.sample_rate,2) )
        else:
          data= resampler.resample( d.data )
    
    s= f.read( 400000 )
    r= dm.parse( s )
    
    tt= time.time()- t
    print '%d frames in %d secs( %.02f fps )' % ( frames, tt, float(frames)/tt )
    
    ev= pygame.event.get()
    for e in ev:
      if e.type== pygame.KEYDOWN and e.key== pygame.K_ESCAPE:
        s= ''
        break
コード例 #9
0
ファイル: vplayer_threads.py プロジェクト: pymedia/pymedia
            # Close current file when error detected
            if len(self.err) or len(s) == 0:
                self.stopPlayback(False)
                self.playingFile = None

        print 'Main video loop has closed.'


player = VPlayer()

if __name__ == "__main__":
    menu = Menu()
    if len(sys.argv) < 2 or len(sys.argv) > 3:
        print 'Usage: vplayer <file_name>'
    else:
        pygame.init()
        pygame.display.set_mode((800, 600), 0)
        player.start()
        player.startPlayback({'name': sys.argv[1]})
        player.setOverlay((0, 0, 800, 600))
        while player.isPlaying() == 0:
            time.sleep(.05)
        while player.isPlaying():
            e = pygame.event.wait()
            if e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    player.stopPlayback()
                    break
                if e.key == pygame.K_RIGHT:
                    player.seekRelative(SEEK_SEC)
                if e.key == pygame.K_LEFT: