diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 5f6c66b2d0..8bbddacdb3 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -133,6 +133,15 @@ class DiffFilesPolicy(object): output, error = self._GitDiff(expected_file, actual_file) + # If this is an MP4 file, get a better looking diff. + if ((output or error) and + os.path.splitext(actual_file)[1] in {'.mp4', '.m4s'}): + new_output, new_error = self._Mp4Diff( + out_dir, expected_file, actual_file) + + output = new_output or output + error = new_error or error + if output: failure_messages += [output.decode('utf8')] @@ -160,6 +169,23 @@ class DiffFilesPolicy(object): p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) return p.communicate() + def _Mp4Diff(self, out_dir, file_a, file_b): + dump_a = os.path.join(out_dir, os.path.basename(file_a) + '.dump.expected') + dump_b = os.path.join(out_dir, os.path.basename(file_b) + '.dump.actual') + try: + cmd = ['mp4dump', '--verbosity', '2', file_a] + with open(dump_a, 'w') as f: + subprocess.check_call(cmd, stdout=f) + cmd = ['mp4dump', '--verbosity', '2', file_b] + with open(dump_b, 'w') as f: + subprocess.check_call(cmd, stdout=f) + except (OSError, subprocess.CalledProcessError): + # If the program isn't available or returns an error, just ignore it and + # use the normal diff. + return None, None + + return self._GitDiff(dump_a, dump_b) + def _UpdateGold(self, out_dir, gold_dir): if os.path.exists(gold_dir): shutil.rmtree(gold_dir)