diff --git a/tools/barcode_tools/barcode_decoder.py b/tools/barcode_tools/barcode_decoder.py index 87b3ec2993..362a794f6b 100755 --- a/tools/barcode_tools/barcode_decoder.py +++ b/tools/barcode_tools/barcode_decoder.py @@ -35,7 +35,14 @@ def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height, """ size_string = str(yuv_frame_width) + 'x' + str(yuv_frame_height) output_files_pattern = os.path.join(output_directory, 'frame_%04d.png') - command = ['ffmpeg', '-s', '%s' % size_string, '-i', '%s' + ffmpeg_executable = 'ffmpeg' + if sys.platform == 'win32': + if os.getenv('FFMPEG_HOME'): + ffmpeg_executable = os.path.join(os.getenv('FFMPEG_HOME'), 'bin', + 'ffmpeg.exe') + else: + ffmpeg_executable = 'ffmpeg.exe' + command = [ffmpeg_executable, '-s', '%s' % size_string, '-i', '%s' % yuv_file_name, '-f', 'image2', '-vcodec', 'png', '%s' % output_files_pattern] try: @@ -92,7 +99,14 @@ def _decode_barcode_in_file(file_name, barcode_width, barcode_height, jars, Return: (bool): True upon success, False otherwise. """ - command = ['java', '-Djava.awt.headless=true', '-cp', '%s' % jars, + java_executable = 'java' + if sys.platform == 'win32': + if os.getenv('JAVA_HOME'): + java_executable = os.path.join(os.getenv('JAVA_HOME'), 'bin', + 'java.exe') + else: + java_executable = 'java.exe' + command = [java_executable, '-Djava.awt.headless=true', '-cp', '%s' % jars, '%s' % command_line_decoder, '--products_only', '--dump_results', '--brief', '--crop=%d,%d,%d,%d' % (0, 0, barcode_width, barcode_height), @@ -257,6 +271,10 @@ def _main(): --yuv_file= --yuv_frame_width=352 --yuv_frame_height=288 --barcode_height=32 --stats_file= + + NOTE: On Windows, if you don't have ffmpeg and Java in your PATH, you can + set the JAVA_HOME and FFMPEG_HOME environment variables to help the script + find the executables to use. """ options = _parse_args() diff --git a/tools/barcode_tools/build_zxing.py b/tools/barcode_tools/build_zxing.py index 9e737f2f70..5656a46a51 100755 --- a/tools/barcode_tools/build_zxing.py +++ b/tools/barcode_tools/build_zxing.py @@ -14,28 +14,29 @@ import sys def run_ant_build_command(path_to_ant_build_file): """Tries to build the passed build file with ant.""" - ant_suffix = '.bat' if 'win32' in sys.platform else '' - cmd = ['ant%s' % ant_suffix, '-buildfile', path_to_ant_build_file] - try: - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - if process.returncode != 0: - print >> sys.stderr, 'Failed to execute: %s\nError: %s' % (' '.join(cmd), - stderr) + ant_executable = 'ant' + if sys.platform == 'win32': + if os.getenv('ANT_HOME'): + ant_executable = os.path.join(os.getenv('ANT_HOME'), 'bin', 'ant.bat') else: - print stdout + ant_executable = 'ant.bat' + cmd = [ant_executable, '-buildfile', path_to_ant_build_file] + try: + process = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr) + process.wait() + if process.returncode != 0: + print >> sys.stderr, 'Failed to execute: %s' % ' '.join(cmd) + return process.returncode except Exception as e: - print >> sys.stderr, 'Failed to execute: %s\nError: %s' % (' '.join(cmd), e) - + print >> sys.stderr, 'Failed to execute: %s' % ' '.join(cmd) + return -1 def _main(): core_build = os.path.join('third_party', 'zxing', 'core', 'build.xml') run_ant_build_command(core_build) javase_build = os.path.join('third_party', 'zxing', 'javase', 'build.xml') - run_ant_build_command(javase_build) - return 0 + return run_ant_build_command(javase_build) if __name__ == '__main__':