def __init__(self,rate=44100,channels=2,fps=30): try: self.ao=oss.open_audio() except: self.ao=oss.open('w') if (hasattr(self.ao,'stereo')): self.ao.stereo(1) self.ao.speed(rate) if (hasattr(self.ao,'format')): self.ao.format(oss.AFMT_S16_LE) else: self.ao.setfmt(oss.AFMT_S16_LE) self.ao.channels(channels)
## open an audio video file vf=sys.argv[1] #vf="/home/tranx/conan1.flv" mp.open(vf,TS_VIDEO_RGB24) tracks=mp.get_tracks() ## connect video and audio to their respective device ld=LazyDisplayQt() tracks[0].set_observer(ld.f) ao=oss.open_audio() ao.stereo(1) ao.speed(tracks[1].get_samplerate()) ao.format(oss.AFMT_S16_LE) tracks[1].set_observer(lambda x:ao.write(x[0].data)) tracks[0].seek_to_seconds(10) ao.channels(tracks[1].get_channels()) ## play the movie ! mp.run() ########NEW FILE######## __FILENAME__ = seek_test # -*- coding: utf-8 -*-
def display(cls,elr): global with_oss if (not cls.ld): cls.ld=LazyDisplay() tracks=None if (hasattr(elr,"tracks")): tracks=elr.tracks rreader=elr elif (hasattr(elr,"vr")): if (hasattr(elr.vr,"tracks")): tracks=elr.vr.tracks rreader=elr.vr elif (hasattr(elr,"reader")): if (hasattr(elr.reader,"tracks")): tracks=elr.reader.tracks rreader=elr.reader else: pass if (tracks==None): sys.stderr.write("don't know how to get sound track info\n") raise Exception, "don't know how to get sound track info" rate=tracks[1].get_samplerate() channels=tracks[1].get_channels() fps=tracks[0].get_fps() print rate,channels,fps if not with_oss: ap=AlsaSoundLazyPlayer(rate,channels,fps) else: try: ao=oss.open_audio() except: ao=oss.open('w') if (hasattr(ao,'stereo')): ao.stereo(1) ao.speed(rate) if (hasattr(ao,'format')): ao.format(oss.AFMT_S16_LE) else: ao.setfmt(oss.AFMT_S16_LE) ao.channels(channels) print tracks class D: def __init__(self): self.ctr=0 def on_event(self,x): global with_oss x=rreader.get_current_frame() if (self.ctr%4==0): cls.ld.f(x[0][2]) #print x[1].shape if with_oss: ao.write(x[1].data) else: #print "push" ap.push((x[1],0)) #print "/push" self.ctr+=1 #elr.set_observer(lambda x:(cls.ld.f(x[0]),ap.push(x[1]))) elr.set_observer(D().on_event) try: elr.run() except Exception,e: sys.stderr.write("WARNING: error during playback...\n"+str(e)+"\n") pass