webrtc_m130/webrtc/examples/androidtests/video_quality_loopback_test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

134 lines
4.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
"""
This script is the wrapper that starts a loopback call with stubbed video in
and out. It then analyses the video quality of the output video against the
reference input video.
It expect to be given the webrtc output build directory as the first argument
all other arguments are optional.
It assumes you have a Android device plugged in.
"""
import argparse
import logging
import os
import shutil
import subprocess
import sys
import tempfile
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
os.pardir))
def _RunCommand(argv, cwd=SRC_DIR, **kwargs):
logging.info('Running %r', argv)
subprocess.check_call(argv, cwd=cwd, **kwargs)
def _ParseArgs():
parser = argparse.ArgumentParser(description='Start loopback video analysis.')
parser.add_argument('build_dir_android',
help='The path to the build directory for Android.')
parser.add_argument('--build_dir_x86',
help='The path to the build directory for building locally.')
parser.add_argument('--temp_dir',
help='A temporary directory to put the output.')
args = parser.parse_args()
return args
def main():
logging.basicConfig(level=logging.INFO)
args = _ParseArgs()
build_dir_android = args.build_dir_android
build_dir_x86 = args.build_dir_x86
temp_dir = args.temp_dir
if not temp_dir:
temp_dir = tempfile.mkdtemp()
else:
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
if not build_dir_x86:
build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
_RunCommand(['gn', 'gen', build_dir_x86])
_RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
tools_dir = os.path.join(SRC_DIR, 'tools-webrtc')
toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain')
# Download ffmpeg and zxing.
download_script = os.path.join(tools_dir, 'download_tools.py')
_RunCommand([sys.executable, download_script, toolchain_dir])
# Run the Espresso code.
test_script = os.path.join(build_dir_android,
'bin', 'run_AppRTCMobileTestStubbedVideoIO')
_RunCommand([sys.executable, test_script])
# Pull the output video.
test_video = os.path.join(temp_dir, 'test_video.y4m')
_RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video])
test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
Reland of PyLint fixes for tools-webrtc and webrtc/tools (patchset #1 id:1 of https://codereview.webrtc.org/2737233003/ ) Reason for revert: Fixing errors for reland. I have tested that this does not make Chromium video quality tests fail. Original issue's description: > Revert of PyLint fixes for tools-webrtc and webrtc/tools (patchset #3 id:40001 of https://codereview.webrtc.org/2736233003/ ) > > Reason for revert: > Fails video quality tests in Chrome: http://build.chromium.org/p/chromium.webrtc.fyi/builders/Win10%20Tester/builds/6568 > I should have looked more closer at those :( > > Original issue's description: > > PyLint fixes for tools-webrtc and webrtc/tools > > > > Fix a lot of errors before bringing in the new config in > > https://codereview.webrtc.org/2737963003/ > > > > BUG=webrtc:7303 > > NOTRY=True > > > > Review-Url: https://codereview.webrtc.org/2736233003 > > Cr-Commit-Position: refs/heads/master@{#17137} > > Committed: https://chromium.googlesource.com/external/webrtc/+/f5318e1f391859c82aaa47b297429e50f41f6b3c > > TBR=oprypin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7303 > > Review-Url: https://codereview.webrtc.org/2737233003 > Cr-Commit-Position: refs/heads/master@{#17142} > Committed: https://chromium.googlesource.com/external/webrtc/+/94f4d9effc3fa1ee6a6a48a7bbdef6684defd1dc NOTRY=true BUG=webrtc:7312 Review-Url: https://codereview.webrtc.org/2741733003 Cr-Commit-Position: refs/heads/master@{#17541}
2017-04-05 06:42:43 -07:00
def ConvertVideo(input_video, output_video):
_RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
Reland of PyLint fixes for tools-webrtc and webrtc/tools (patchset #1 id:1 of https://codereview.webrtc.org/2737233003/ ) Reason for revert: Fixing errors for reland. I have tested that this does not make Chromium video quality tests fail. Original issue's description: > Revert of PyLint fixes for tools-webrtc and webrtc/tools (patchset #3 id:40001 of https://codereview.webrtc.org/2736233003/ ) > > Reason for revert: > Fails video quality tests in Chrome: http://build.chromium.org/p/chromium.webrtc.fyi/builders/Win10%20Tester/builds/6568 > I should have looked more closer at those :( > > Original issue's description: > > PyLint fixes for tools-webrtc and webrtc/tools > > > > Fix a lot of errors before bringing in the new config in > > https://codereview.webrtc.org/2737963003/ > > > > BUG=webrtc:7303 > > NOTRY=True > > > > Review-Url: https://codereview.webrtc.org/2736233003 > > Cr-Commit-Position: refs/heads/master@{#17137} > > Committed: https://chromium.googlesource.com/external/webrtc/+/f5318e1f391859c82aaa47b297429e50f41f6b3c > > TBR=oprypin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7303 > > Review-Url: https://codereview.webrtc.org/2737233003 > Cr-Commit-Position: refs/heads/master@{#17142} > Committed: https://chromium.googlesource.com/external/webrtc/+/94f4d9effc3fa1ee6a6a48a7bbdef6684defd1dc NOTRY=true BUG=webrtc:7312 Review-Url: https://codereview.webrtc.org/2741733003 Cr-Commit-Position: refs/heads/master@{#17541}
2017-04-05 06:42:43 -07:00
ConvertVideo(test_video, test_video_yuv)
reference_video = os.path.join(SRC_DIR,
'resources', 'reference_video_640x360_30fps.y4m')
reference_video_yuv = os.path.join(temp_dir,
'reference_video_640x360_30fps.yuv')
Reland of PyLint fixes for tools-webrtc and webrtc/tools (patchset #1 id:1 of https://codereview.webrtc.org/2737233003/ ) Reason for revert: Fixing errors for reland. I have tested that this does not make Chromium video quality tests fail. Original issue's description: > Revert of PyLint fixes for tools-webrtc and webrtc/tools (patchset #3 id:40001 of https://codereview.webrtc.org/2736233003/ ) > > Reason for revert: > Fails video quality tests in Chrome: http://build.chromium.org/p/chromium.webrtc.fyi/builders/Win10%20Tester/builds/6568 > I should have looked more closer at those :( > > Original issue's description: > > PyLint fixes for tools-webrtc and webrtc/tools > > > > Fix a lot of errors before bringing in the new config in > > https://codereview.webrtc.org/2737963003/ > > > > BUG=webrtc:7303 > > NOTRY=True > > > > Review-Url: https://codereview.webrtc.org/2736233003 > > Cr-Commit-Position: refs/heads/master@{#17137} > > Committed: https://chromium.googlesource.com/external/webrtc/+/f5318e1f391859c82aaa47b297429e50f41f6b3c > > TBR=oprypin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7303 > > Review-Url: https://codereview.webrtc.org/2737233003 > Cr-Commit-Position: refs/heads/master@{#17142} > Committed: https://chromium.googlesource.com/external/webrtc/+/94f4d9effc3fa1ee6a6a48a7bbdef6684defd1dc NOTRY=true BUG=webrtc:7312 Review-Url: https://codereview.webrtc.org/2741733003 Cr-Commit-Position: refs/heads/master@{#17541}
2017-04-05 06:42:43 -07:00
ConvertVideo(reference_video, reference_video_yuv)
# Run compare script.
compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools',
'compare_videos.py')
zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
# The frame_analyzer binary should be built for local computer and not for
# Android
frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
frame_width = 640
frame_height = 360
stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
_RunCommand([
sys.executable, compare_script, '--ref_video', reference_video_yuv,
'--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
'--yuv_frame_height', str(frame_height),
'--stats_file_ref', stats_file_ref,
'--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer,
'--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
shutil.rmtree(temp_dir)
if __name__ == '__main__':
sys.exit(main())