parameters: ()
return_statement: return 0
docstring: The main function.
  
    A simple invocation is:
    ./webrtc/tools/barcode_tools/compare_videos.py
    --ref_video=<path_and_name_of_reference_video>
    --test_video=<path_and_name_of_test_video>
    --frame_analyzer=<path_and_name_of_the_frame_analyzer_executable>
  
    Notice that the prerequisites for barcode_decoder.py also applies to this
    script. The means the following executables have to be available in the PATH:
    * zxing
    * ffmpeg
docstring_summary: The main function.
docstring_tokens: The main function .
function: def main():
    """The main function.
  
    A simple invocation is:
    ./webrtc/tools/barcode_tools/compare_videos.py
    --ref_video=<path_and_name_of_reference_video>
    --test_video=<path_and_name_of_test_video>
    --frame_analyzer=<path_and_name_of_the_frame_analyzer_executable>
  
    Notice that the prerequisites for barcode_decoder.py also applies to this
    script. The means the following executables have to be available in the PATH:
    * zxing
    * ffmpeg
    """
    options = _ParseArgs()
  
    if options.barcode_decoder:
      path_to_decoder = options.barcode_decoder
    else:
      path_to_decoder = os.path.join(SCRIPT_DIR, 'barcode_tools',
                                     'barcode_decoder.py')
  
    # On Windows, sometimes the inherited stdin handle from the parent process
    # fails. Work around this by passing null to stdin to the subprocesses.
    null_filehandle = open(os.devnull, 'r')
  
    # Run barcode decoder on the test video to identify frame numbers.
    png_working_directory = tempfile.mkdtemp()
    cmd = [
      sys.executable,
      path_to_decoder,
      '--yuv_file=%s' % options.test_video,
      '--yuv_frame_width=%d' % options.yuv_frame_width,
      '--yuv_frame_height=%d' % options.yuv_frame_height,
      '--stats_file=%s' % options.stats_file,
      '--png_working_dir=%s' % png_working_directory,
    ]
    if options.zxing_path:
      cmd.append('--zxing_path=%s' % options.zxing_path)
    if options.ffmpeg_path:
      cmd.append('--ffmpeg_path=%s' % options.ffmpeg_path)
    barcode_decoder = subprocess.Popen(cmd, stdin=null_filehandle,
                                       stdout=sys.stdout, stderr=sys.stderr)
    barcode_decoder.wait()
  
    shutil.rmtree(png_working_directory)
    if barcode_decoder.returncode != 0:
      print 'Failed to run barcode decoder script.'
      return 1
  
    # Run frame analyzer to compare the videos and print output.
    cmd = [
      options.frame_analyzer,
      '--label=%s' % options.label,
      '--reference_file=%s' % options.ref_video,
      '--test_file=%s' % options.test_video,
      '--stats_file=%s' % options.stats_file,
      '--width=%d' % options.yuv_frame_width,
      '--height=%d' % options.yuv_frame_height,
    ]
    frame_analyzer = subprocess.Popen(cmd, stdin=null_filehandle,
                                      stdout=sys.stdout, stderr=sys.stderr)
    frame_analyzer.wait()
    if frame_analyzer.returncode != 0:
      print 'Failed to run frame analyzer.'
      return 1
  
    return 0
function_tokens: def main ( ) : options = _ParseArgs ( ) if options . barcode_decoder : path_to_decoder = options . barcode_decoder else : path_to_decoder = os . path . join ( SCRIPT_DIR , 'barcode_tools' , 'barcode_decoder.py' ) # On Windows, sometimes the inherited stdin handle from the parent process # fails. Work around this by passing null to stdin to the subprocesses. null_filehandle = open ( os . devnull , 'r' ) # Run barcode decoder on the test video to identify frame numbers. png_working_directory = tempfile . mkdtemp ( ) cmd = [ sys . executable , path_to_decoder , '--yuv_file=%s' % options . test_video , '--yuv_frame_width=%d' % options . yuv_frame_width , '--yuv_frame_height=%d' % options . yuv_frame_height , '--stats_file=%s' % options . stats_file , '--png_working_dir=%s' % png_working_directory , ] if options . zxing_path : cmd . append ( '--zxing_path=%s' % options . zxing_path ) if options . ffmpeg_path : cmd . append ( '--ffmpeg_path=%s' % options . ffmpeg_path ) barcode_decoder = subprocess . Popen ( cmd , stdin = null_filehandle , stdout = sys . stdout , stderr = sys . stderr ) barcode_decoder . wait ( ) shutil . rmtree ( png_working_directory ) if barcode_decoder . returncode != 0 : print 'Failed to run barcode decoder script.' return 1 # Run frame analyzer to compare the videos and print output. cmd = [ options . frame_analyzer , '--label=%s' % options . label , '--reference_file=%s' % options . ref_video , '--test_file=%s' % options . test_video , '--stats_file=%s' % options . stats_file , '--width=%d' % options . yuv_frame_width , '--height=%d' % options . yuv_frame_height , ] frame_analyzer = subprocess . Popen ( cmd , stdin = null_filehandle , stdout = sys . stdout , stderr = sys . stderr ) frame_analyzer . wait ( ) if frame_analyzer . returncode != 0 : print 'Failed to run frame analyzer.' return 1 return 0