#NEWLINE# def remux( self ) : #NEWLINE# #INDENT# if ( self . detect is None ) : #NEWLINE# #INDENT# log . error ( 'Cant detect ffmpeg or avconv. cant mux files without it' ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( self . stream . finished is False ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# orig_filename = self . stream . options . output #NEWLINE# new_name = '{0}.mp4' . format ( os . path . splitext ( self . stream . options . output ) [ 0 ] ) #NEWLINE# log . info ( 'Muxing %s into %s' , orig_filename , new_name ) #NEWLINE# tempfile = '{0}.temp' . format ( self . stream . options . output ) #NEWLINE# ( name , ext ) = os . path . splitext ( orig_filename ) #NEWLINE# arguments = [ '-c' , 'copy' , '-copyts' , '-f' , 'mp4' ] #NEWLINE# if ( ext == '.ts' ) : #NEWLINE# #INDENT# arguments += [ '-bsf:a' , 'aac_adtstoasc' ] #NEWLINE# #UNINDENT# arguments += [ '-y' , tempfile ] #NEWLINE# cmd = [ self . detect , '-i' , orig_filename ] #NEWLINE# cmd += arguments #NEWLINE# p = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , stdin = subprocess . PIPE ) #NEWLINE# ( stdout , stderr ) = p . communicate ( ) #NEWLINE# if ( p . returncode != 0 ) : #NEWLINE# #INDENT# stderr = stderr . decode ( 'utf-8' , 'replace' ) #NEWLINE# msg = stderr . strip ( ) . split ( '\n' ) [ ( - 1 ) ] #NEWLINE# log . error ( 'Something went wrong: %s' , msg ) #NEWLINE# return #NEWLINE# #UNINDENT# log . info ( 'Muxing done. removing the old file.' ) #NEWLINE# os . remove ( self . stream . options . output ) #NEWLINE# os . rename ( tempfile , new_name )