Blame view

3rdparty/ffmpeg-4.4.4/x264/tools/digress/comparers.py 1.82 KB
f244cbd5   Hu Chunming   ffmpeg支持h264编码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  """
  Digress comparers.
  """
  
  from digress.errors import ComparisonError
  
  import os
  from itertools import imap, izip
  
  def compare_direct(value_a, value_b):
      if value_a != value_b:
          raise ComparisonError("%s is not %s" % (value_a, value_b))
  
  def compare_pass(value_a, value_b):
      """
      Always true, as long as the test is passed.
      """
  
  def compare_tolerance(tolerance):
      def _compare_tolerance(value_a, value_b):
          if abs(value_a - value_b) > tolerance:
              raise ComparisonError("%s is not %s (tolerance: %s)" % (
                  value_a,
                  value_b,
                  tolerance
              ))
      return _compare_tolerance
  
  def compare_files(file_a, file_b):
      size_a = os.path.getsize(file_a)
      size_b = os.path.getsize(file_b)
  
      print file_a, file_b
  
      if size_a != size_b:
          raise ComparisonError("%s is not the same size as %s" % (
              file_a,
              file_b
          ))
  
      BUFFER_SIZE = 8196
  
      offset = 0
  
      with open(file_a) as f_a:
          with open(file_b) as f_b:
              for chunk_a, chunk_b in izip(
                  imap(
                      lambda i: f_a.read(BUFFER_SIZE),
                      xrange(size_a // BUFFER_SIZE + 1)
                  ),
                  imap(
                      lambda i: f_b.read(BUFFER_SIZE),
                      xrange(size_b // BUFFER_SIZE + 1)
                  )
              ):
                  chunk_size = len(chunk_a)
  
                  if chunk_a != chunk_b:
                      for i in xrange(chunk_size):
                          if chunk_a[i] != chunk_b[i]:
                              raise ComparisonError("%s differs from %s at offset %d" % (
                                  file_a,
                                  file_b,
                                  offset + i
                              ))
  
                  offset += chunk_size