1// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// This package contains a java library and binary for the calculation of
16// Bjontegaard-Delta (BD) rate from rate-distortion data.
17
18java_library_host {
19    name: "cts-media-videoquality-bdrate-lib",
20    srcs: [
21        "src/main/java/com/android/media/videoquality/bdrate/*.java",
22    ],
23    libs: [
24        "auto_value_annotations",
25    ],
26    static_libs: [
27        "guava",
28        "apache-commons-math3",
29        "gson",
30        "args4j-2.0.28",
31    ],
32    plugins: [
33        "auto_value_plugin",
34    ],
35    java_version: "11",
36
37}
38
39java_test_host {
40    name: "cts-media-videoquality-bdrate-lib-tests",
41    srcs: [
42        "src/test/java/com/android/media/videoquality/bdrate/*.java",
43    ],
44    static_libs: [
45        "cts-media-videoquality-bdrate-lib",
46        "junit",
47        "junit-params",
48        "truth",
49    ],
50    test_suites: ["general-tests"],
51    java_version: "11",
52}
53
54/*
55This binary will calculate the BD-RATE or BD-QUALITY
56for a given set of data, then provides the result
57as an exit code from the binary with the following
58key:
59
600 : The provided data passes the VEQ test within the
61    threshold defined in the key.
621 : The provided data fails the VEQ test and is outside
63    the threshold defined in the key, this value indicates
64    that BD-RATE/BD-QUALITY was calculated successfully.
652 : A precondition for the calculation of BD-RATE/BD-QUALITY
66    was not met, thus no result can be given.
673:  One of the arguments to the binary was invalid.
684:  An unknown, internal error occurred.
69
70Version Check:
71
72java -jar cts-media-videoquality-bdrate -v
73
74General Usage:
75
76java -jar cts-media-videoquality-bdrate \
77    --REF_JSON_FILE path/to/ref.json \
78    --TEST_VMAF_FILE path/to/test.txt
79
80Where the JSON file is of the form:
81
82[
83  {
84    "TestId": "pc14-veq",
85    "FrameRate": 30,
86    "FrameCount": 300,
87    "RefFileName": "AVICON-MOBILE-Beach-SO04-CRW02-L-420-8bit-SDR-1080p-30fps.y4m",
88    "Height": 1080,
89    "Width": 1920,
90    "RefRate": "4242 6009 7996 9990 12093",
91    "RefVmaf": "64 72 79 83 87",
92    "RefThreshold": "0",
93    "CodecConfigs": [
94      {
95        "Codec": "avc",
96        "KeyFrameInterval": "1",
97        "MaxBFrames": "0",
98        "EncoderType": "hw",
99        "EncodedFileName": "output_hw_2mbps.mp4",
100        "Level": "Level52",
101        "BitRate": "2000000",
102        "Profile": "High"
103      },
104      {
105        "Codec": "avc",
106        "KeyFrameInterval": "1",
107        "MaxBFrames": "0",
108        "EncoderType": "hw",
109        "EncodedFileName": "output_hw_4mbps.mp4",
110        "Level": "Level52",
111        "BitRate": "4000000",
112        "Profile": "High"
113      },
114      {
115        "Codec": "avc",
116        "KeyFrameInterval": "1",
117        "MaxBFrames": "0",
118        "EncoderType": "hw",
119        "EncodedFileName": "output_hw_6mbps.mp4",
120        "Level": "Level52",
121        "BitRate": "6000000",
122        "Profile": "High"
123      },
124      {
125        "Codec": "avc",
126        "KeyFrameInterval": "1",
127        "MaxBFrames": "0",
128        "EncoderType": "hw",
129        "EncodedFileName": "output_hw_8mbps.mp4",
130        "Level": "Level52",
131        "BitRate": "8000000",
132        "Profile": "High"
133      },
134      {
135        "Codec": "avc",
136        "KeyFrameInterval": "1",
137        "MaxBFrames": "0",
138        "EncoderType": "hw",
139        "EncodedFileName": "output_hw_10mbps.mp4",
140        "Level": "Level52",
141        "BitRate": "10000000",
142        "Profile": "High"
143      },
144      {
145        "Codec": "avc",
146        "KeyFrameInterval": "1",
147        "MaxBFrames": "0",
148        "EncoderType": "hw",
149        "EncodedFileName": "output_hw_12mbps.mp4",
150        "Level": "Level52",
151        "BitRate": "12000000",
152        "Profile": "High"
153      }
154    ]
155  }
156]
157
158and the TEST_VMAF_FILE is is of the form:
159
160VMAF score = 95.853458
161Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
162MP4 file = output_hw_10mbps.mp4
163Filesize = 12354333
164FPS = 30
165Frame count = 300
166Duration = 10
167Bitrate kbps = 9883.4
168VMAF score = 96.704977
169Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
170MP4 file = output_hw_12mbps.mp4
171Filesize = 14815468
172FPS = 30
173Frame count = 300
174Duration = 10
175Bitrate kbps = 11852.3
176VMAF score = 81.363013
177Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
178MP4 file = output_hw_2mbps.mp4
179Filesize = 2640926
180FPS = 30
181Frame count = 300
182Duration = 10
183Bitrate kbps = 2112.7
184VMAF score = 88.821365
185Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
186MP4 file = output_hw_4mbps.mp4
187Filesize = 4934241
188FPS = 30
189Frame count = 300
190Duration = 10
191Bitrate kbps = 3947.3
192VMAF score = 92.617636
193Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
194MP4 file = output_hw_6mbps.mp4
195Filesize = 7407080
196FPS = 30
197Frame count = 300
198Duration = 10
199Bitrate kbps = 5925.6
200VMAF score = 94.591995
201Y4M file = AVICON-MOBILE-SelfieTeenKitchenSocialMedia-SS01-CF01-P-420-8bit-SDR-1080p-30fps.y4m
202MP4 file = output_hw_8mbps.mp4
203Filesize = 9886890
204FPS = 30
205Frame count = 300
206Duration = 10
207Bitrate kbps = 7909.5
208
209Each file is read for their rate-distortion curves and then compared to return one
210of the return codes specified above.
211*/
212
213java_binary_host {
214    name: "cts-media-videoquality-bdrate",
215    static_libs: [
216        "cts-media-videoquality-bdrate-lib",
217    ],
218    java_version: "11",
219    manifest: "manifest.inf",
220}
221