[問題] 使用Pymedia播放影片讀Frame問題
各位版友大家好,小弟最近在使用Python匯入Pymedia播放影片,
可是卻遇到只播放不到一秒即停止的窘境,不太清楚是哪裡出了問題,
請有這方面經驗的版友幫忙一下,謝謝!
讀取影片Frame的迴圈:
def readerLoop( self ):
print 'Main video loop has started.'
f= None
try:
self.frameNum= -1
# Initialize demuxer and read small portion of the file to have
more info on the format
dm= muxer.Demuxer( self.playingFile.split( '.' )[ -1 ].lower() )
f= open( self.playingFile, 'rb' )
#小弟個人覺得這裡有可能有問題
s= f.read( 300000 )
r= dm.parse( s )
# Setup video( only first matching stream will be used )
self.err= []
for vindex in xrange( len( dm.streams )):
if dm.streams[ vindex ][ 'type' ]== muxer.CODEC_TYPE_VIDEO:
self.initVideo( dm.streams[ vindex ] )
break
# Setup audio( only first matching stream will be used )
for aindex in xrange( len( dm.streams )):
if dm.streams[ aindex ][ 'type' ]== muxer.CODEC_TYPE_AUDIO:
self.initAudio( dm.streams[ aindex ] )
break
# Open current file for playing
currentFile= self.playingFile
# Play until no exit flag, not eof, no errs and file still the same
while len(s) and len( self.err )== 0 and \
self.exitFlag== 0 and self.playingFile and \
self.playingFile== currentFile:
for d in r:
# Seeking stuff
if not self.seek in ( 0, SEEK_IN_PROGRESS ):
f.seek( self.seek, 1 )
self.resetAudio()
self.resetVideo()
self.rawFrames= []
self.decodedFrames= []
self.seek= SEEK_IN_PROGRESS
break
try:
# Demux file into streams
if d[ 0 ]== vindex:
# Process video frame
self.processVideoFrame( d )
elif d[ 0 ]== aindex and self.seek!= SEEK_IN_PROGRESS:
# Decode and play audio frame
self.processAudioFrame( d )
except:
traceback.print_exc()
raise
# Read next encoded chunk and demux it
s= f.read( 10000 )
r= dm.parse( s )
if f: f.close()
# Close current file when error detected
if len( self.err ) or len( s )== 0:
self.stopPlayback( False )
self.playingFile= None
except:
self.err.append( sys.exc_info()[ 1 ] )
print 'Main video loop has closed'
謝謝大家的幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.54.165
Python 近期熱門文章
PTT數位生活區 即時熱門文章