#NEWLINE# def verify_video( filename_or_obj , format , resolution ) : #NEWLINE# #INDENT# '\n    Verify that the video in filename_or_obj has the specified format and\n    resolution.\n    ' #NEWLINE# ( width , height ) = resolution #NEWLINE# if ( format in RAW_FORMATS ) : #NEWLINE# #INDENT# size = ( ( ( ( math . ceil ( ( width / 32 ) ) * 32 ) * math . ceil ( ( height / 16 ) ) ) * 16 ) * RAW_FORMATS [ format ] ) #NEWLINE# if isinstance ( filename_or_obj , str ) : #NEWLINE# #INDENT# stream = io . open ( filename_or_obj , 'rb' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stream = filename_or_obj #NEWLINE# #UNINDENT# stream . seek ( 0 , os . SEEK_END ) #NEWLINE# assert ( stream . tell ( ) > 0 ) #NEWLINE# assert ( ( stream . tell ( ) % size ) == 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( filename_or_obj , str ) : #NEWLINE# #INDENT# p = subprocess . Popen ( [ 'avconv' , '-f' , format , '-i' , filename_or_obj ] , stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p = subprocess . Popen ( [ 'avconv' , '-f' , format , '-i' , '-' ] , stdin = filename_or_obj , stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) #NEWLINE# #UNINDENT# out = p . communicate ( ) [ 0 ] #NEWLINE# assert ( p . returncode == 1 ) , ( 'avconv returned unexpected code %d' % p . returncode ) #NEWLINE# state = 'start' #NEWLINE# for line in out . splitlines ( ) : #NEWLINE# #INDENT# line = line . decode ( 'utf-8' ) . strip ( ) #NEWLINE# if ( ( state == 'start' ) and re . match ( '^Input #0' , line ) ) : #NEWLINE# #INDENT# state = 'input' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( state == 'input' ) and re . match ( '^Duration' , line ) ) : #NEWLINE# #INDENT# state = 'dur' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( state == 'dur' ) and re . match ( '^Stream #0\\.0' , line ) ) : #NEWLINE# #INDENT# assert re . match ( ( '^Stream #0\\.0: Video: %s( \\(.*\\))?, yuvj?420p, %dx%d( \\[PAR \\d+:\\d+ DAR \\d+:\\d+\\])?, \\d+ fps(, \\d+ tbr)?, \\d+k? tbn(, \\d+k? tbc)?$' % ( format , width , height ) ) , line ) , ( 'Unexpected avconv output: %s' % line ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# assert False , 'Failed to locate stream analysis in avconv output'