xref: /aosp_15_r20/external/libaom/tools/aggregate_entropy_stats.py (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1#!/usr/bin/env python3
2## Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3##
4## This source code is subject to the terms of the BSD 2 Clause License and
5## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6## was not distributed with this source code in the LICENSE file, you can
7## obtain it at www.aomedia.org/license/software. If the Alliance for Open
8## Media Patent License 1.0 was not distributed with this source code in the
9## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10##
11"""Aggregate multiple entropy stats output which is written in 32-bit int.
12
13python ./aggregate_entropy_stats.py [dir of stats files] [keyword of filenames]
14 [filename of final stats]
15"""
16
17__author__ = "[email protected]"
18
19import os
20import sys
21import numpy as np
22
23def main():
24    dir = sys.argv[1]
25    sum = []
26    for fn in os.listdir(dir):
27        if sys.argv[2] in fn:
28            stats = np.fromfile(dir + fn, dtype=np.int32)
29            if len(sum) == 0:
30                sum = stats
31            else:
32                sum = np.add(sum, stats)
33    if len(sum) == 0:
34        print("No stats file is found. Double-check directory and keyword?")
35    else:
36        sum.tofile(dir+sys.argv[3])
37
38if __name__ == '__main__':
39    main()
40