├── readme.md ├── LICENSE └── stats.lua /readme.md: -------------------------------------------------------------------------------- 1 | Note 2 | ==== 3 | This script is now part of mpv and, therefore, **not updated in this repo as of Nov 2018.** 4 | For an up to date version please visit: https://github.com/mpv-player/mpv/blob/master/player/lua/stats.lua 5 | 6 | *You do not need to download it here* unless you want a specific version, e.g. 7 | because you are using an old version of mpv (you shouldn't). 8 | In such a case, start mpv with `--load-stats-overlay=no` in order to disable the 9 | internal version and place your desired script version at the locations mentioned below. 10 | 11 | [There's also some documentation available](https://mpv.io/manual/master/#stats). 12 | 13 | 14 | mpv-stats 15 | ========= 16 | Display statistics for the currently played file in mpv. 17 | 18 | ![Default](https://cloud.githubusercontent.com/assets/540920/16775632/85da9aa6-489c-11e6-8333-176755e64892.jpg) 19 | (screenshot is outdated) 20 | 21 | Requirements 22 | ============ 23 | 24 | mpv 0.28.0 **is not sufficient**. You need a more recent version of mpv. 25 | For older mpv versions please go to [Releases](https://github.com/Argon-/mpv-stats/releases). 26 | The oldest supported version of mpv is 0.9.3. 27 | 28 | By default *Source Sans Pro* is used as font. 29 | [You can download it here](https://github.com/adobe-fonts/source-sans-pro). 30 | If you want to use your own, please make sure your alternative choice supports 31 | as many font weights and monospaced digits, for an optimal visual experience. 32 | 33 | 34 | Usage 35 | ===== 36 | Place `stats.lua` in your `~/.config/mpv/scripts/` or `~/.mpv/scripts/` folder 37 | to autoload the script. 38 | 39 | The script is binding itself to `i` and `I` (however, not overriding your own 40 | bindings) and can therefore be invoked by pressing these keys. 41 | `i` will show the stats once while `I` will toggle them. 42 | 43 | While the stats are visible on screen, you can use numeric keys (1, 2, 3, ...) 44 | to switch between "pages" of stats. So far, the following pages are defined: 45 | 46 | 1. stats (as usual) 47 | 2. frame timings 48 | 49 | There will be more pages in the future. 50 | Also, expect some layout changes of current pages in the near future. 51 | 52 | You can set different bindings either by [customizing](#customization) this script 53 | or by using the `script_binding` input command (in `input.conf`), e.g.: 54 | 55 | e script-binding stats/display-stats 56 | E script-binding stats/display-stats-toggle 57 | 58 | 59 | F.A.Q. 60 | ====== 61 | 62 | ### How to get graphs? 63 | 64 | Graphs are enabled by default. 65 | Due to their size, graphs for `Frame Timings` can only be shown on their dedicated page (2). 66 | For `VSync Ratio` and `VSync Jitter` they are only shown when stats are toggled (page 1) 67 | because they need to be recorded. 68 | Please note that only the `opengl` VO is exposing frame timing data. 69 | 70 | Turn graphs off with `plot_perfdata=no`, `plot_vsync_ratio=no` and `plot_vsync_jitter=no` (see [Customization](#customization)). 71 | 72 | 73 | ### The graph's position is jumping 74 | 75 | Please use a font with monospaced digits. 76 | The default font does meet this requirement. Either download it (see [Usage](#usage)) 77 | or set your own with `font_mono` (see [Customization](#customization)). 78 | Note that `font` does not need to be a monospaced font. 79 | 80 | 81 | Customization 82 | ============= 83 | You can configure various settings by creating a file called `stats.conf` in a folder 84 | named `lua-settings` within your mpv config folder (where your `mpv.conf` is in). 85 | Please refer to the `o` table within the script for possible option names and 86 | consult [mpv manual](http://mpv.io/manual/master/#config-syntax) regarding 87 | configuration syntax. 88 | 89 | To change e.g. the text display duration your `stats.conf` may look like: 90 | 91 | duration=5 92 | 93 | A more sophisticated example: 94 | 95 | key_oneshot=e 96 | key_toggle=E 97 | font_size=8 98 | plot_perfdata=no 99 | font=Arial 100 | font_mono=Monospaced 101 | font_color=262626 102 | border_size=0.5 103 | 104 | Note: colors are given as hexadecimal values and use 105 | [ASS tag](http://docs.aegisub.org/3.2/ASS_Tags/#\c) order: BBGGRR (blue green red). 106 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /stats.lua: -------------------------------------------------------------------------------- 1 | -- Display some stats. 2 | -- 3 | -- Please consult the readme for information about usage and configuration: 4 | -- https://github.com/Argon-/mpv-stats 5 | -- 6 | -- Please note: not every property is always available and therefore not always 7 | -- visible. 8 | 9 | local mp = require 'mp' 10 | local options = require 'mp.options' 11 | local utils = require 'mp.utils' 12 | 13 | -- Options 14 | local o = { 15 | -- Default key bindings 16 | key_oneshot = "i", 17 | key_toggle = "I", 18 | key_page_1 = "1", 19 | key_page_2 = "2", 20 | key_page_3 = "3", 21 | 22 | duration = 4, 23 | redraw_delay = 1, -- acts as duration in the toggling case 24 | ass_formatting = true, 25 | persistent_overlay = false, -- whether the stats can be overwritten by other output 26 | print_perfdata_passes = false, -- when true, print the full information about all passes 27 | filter_params_max_length = 100, -- a filter list longer than this many characters will be shown one filter per line instead 28 | debug = false, 29 | 30 | -- Graph options and style 31 | plot_perfdata = true, 32 | plot_vsync_ratio = true, 33 | plot_vsync_jitter = true, 34 | skip_frames = 5, 35 | global_max = true, 36 | flush_graph_data = true, -- clear data buffers when toggling 37 | plot_bg_border_color = "0000FF", 38 | plot_bg_color = "262626", 39 | plot_color = "FFFFFF", 40 | 41 | -- Text style 42 | font = "Source Sans Pro", 43 | font_mono = "Source Sans Pro", -- monospaced digits are sufficient 44 | font_size = 8, 45 | font_color = "FFFFFF", 46 | border_size = 0.8, 47 | border_color = "262626", 48 | shadow_x_offset = 0.0, 49 | shadow_y_offset = 0.0, 50 | shadow_color = "000000", 51 | alpha = "11", 52 | 53 | -- Custom header for ASS tags to style the text output. 54 | -- Specifying this will ignore the text style values above and just 55 | -- use this string instead. 56 | custom_header = "", 57 | 58 | -- Text formatting 59 | -- With ASS 60 | ass_nl = "\\N", 61 | ass_indent = "\\h\\h\\h\\h\\h", 62 | ass_prefix_sep = "\\h\\h", 63 | ass_b1 = "{\\b1}", 64 | ass_b0 = "{\\b0}", 65 | ass_it1 = "{\\i1}", 66 | ass_it0 = "{\\i0}", 67 | -- Without ASS 68 | no_ass_nl = "\n", 69 | no_ass_indent = "\t", 70 | no_ass_prefix_sep = " ", 71 | no_ass_b1 = "\027[1m", 72 | no_ass_b0 = "\027[0m", 73 | no_ass_it1 = "\027[3m", 74 | no_ass_it0 = "\027[0m", 75 | } 76 | options.read_options(o) 77 | 78 | local format = string.format 79 | local max = math.max 80 | local min = math.min 81 | 82 | -- Function used to record performance data 83 | local recorder = nil 84 | -- Timer used for redrawing (toggling) and clearing the screen (oneshot) 85 | local display_timer = nil 86 | -- Current page and : mappings 87 | local curr_page = o.key_page_1 88 | local pages = {} 89 | -- Save these sequences locally as we'll need them a lot 90 | local ass_start = mp.get_property_osd("osd-ass-cc/0") 91 | local ass_stop = mp.get_property_osd("osd-ass-cc/1") 92 | -- Ring buffers for the values used to construct a graph. 93 | -- .pos denotes the current position, .len the buffer length 94 | -- .max is the max value in the corresponding buffer 95 | local vsratio_buf, vsjitter_buf 96 | local function init_buffers() 97 | vsratio_buf = {0, pos = 1, len = 50, max = 0} 98 | vsjitter_buf = {0, pos = 1, len = 50, max = 0} 99 | end 100 | -- Save all properties known to this version of mpv 101 | local property_list = {} 102 | for p in string.gmatch(mp.get_property("property-list"), "([^,]+)") do property_list[p] = true end 103 | -- Mapping of properties to their deprecated names 104 | local property_aliases = { 105 | ["decoder-frame-drop-count"] = "drop-frame-count", 106 | ["frame-drop-count"] = "vo-drop-frame-count", 107 | ["container-fps"] = "fps", 108 | } 109 | 110 | 111 | -- Return deprecated name for the given property 112 | local function compat(p) 113 | while not property_list[p] and property_aliases[p] do 114 | p = property_aliases[p] 115 | end 116 | return p 117 | end 118 | 119 | 120 | local function set_ASS(b) 121 | if not o.use_ass or o.persistent_overlay then 122 | return "" 123 | end 124 | return b and ass_start or ass_stop 125 | end 126 | 127 | 128 | local function no_ASS(t) 129 | return set_ASS(false) .. t .. set_ASS(true) 130 | end 131 | 132 | 133 | local function b(t) 134 | return o.b1 .. t .. o.b0 135 | end 136 | 137 | 138 | local function it(t) 139 | return o.it1 .. t .. o.it0 140 | end 141 | 142 | 143 | local function text_style() 144 | if not o.use_ass then 145 | return "" 146 | end 147 | if o.custom_header and o.custom_header ~= "" then 148 | return set_ASS(true) .. o.custom_header 149 | else 150 | return format("%s{\\r}{\\an7}{\\fs%d}{\\fn%s}{\\bord%f}{\\3c&H%s&}" .. 151 | "{\\1c&H%s&}{\\alpha&H%s&}{\\xshad%f}{\\yshad%f}{\\4c&H%s&}", 152 | set_ASS(true), o.font_size, o.font, o.border_size, 153 | o.border_color, o.font_color, o.alpha, o.shadow_x_offset, 154 | o.shadow_y_offset, o.shadow_color) 155 | end 156 | end 157 | 158 | 159 | local function has_vo_window() 160 | return mp.get_property("vo-configured") == "yes" 161 | end 162 | 163 | 164 | local function has_ansi() 165 | local is_windows = type(package) == 'table' 166 | and type(package.config) == 'string' 167 | and package.config:sub(1, 1) == '\\' 168 | if is_windows then 169 | return os.getenv("ANSICON") 170 | end 171 | return true 172 | end 173 | 174 | 175 | -- Generate a graph from the given values. 176 | -- Returns an ASS formatted vector drawing as string. 177 | -- 178 | -- values: Array/table of numbers representing the data. Used like a ring buffer 179 | -- it will get iterated backwards `len` times starting at position `i`. 180 | -- i : Index of the latest data value in `values`. 181 | -- len : The length/amount of numbers in `values`. 182 | -- v_max : The maximum number in `values`. It is used to scale all data 183 | -- values to a range of 0 to `v_max`. 184 | -- v_avg : The average number in `values`. It is used to try and center graphs 185 | -- if possible. May be left as nil 186 | -- scale : A value that will be multiplied with all data values. 187 | -- x_tics: Horizontal width multiplier for the steps 188 | local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) 189 | -- Check if at least one value exists 190 | if not values[i] then 191 | return "" 192 | end 193 | 194 | local x_max = (len - 1) * x_tics 195 | local y_offset = o.border_size 196 | local y_max = o.font_size * 0.66 197 | local x = 0 198 | 199 | -- try and center the graph if possible, but avoid going above `scale` 200 | if v_avg then 201 | scale = min(scale, v_max / (2 * v_avg)) 202 | end 203 | 204 | local s = {format("m 0 0 n %f %f l ", x, y_max - (y_max * values[i] / v_max * scale))} 205 | i = ((i - 2) % len) + 1 206 | 207 | for p = 1, len - 1 do 208 | if values[i] then 209 | x = x - x_tics 210 | s[#s+1] = format("%f %f ", x, y_max - (y_max * values[i] / v_max * scale)) 211 | end 212 | i = ((i - 2) % len) + 1 213 | end 214 | 215 | s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max) 216 | 217 | local bg_box = format("{\\bord0.5}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0", 218 | o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max) 219 | return format("%s{\\r}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s", 220 | o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style()) 221 | end 222 | 223 | 224 | local function append(s, str, attr) 225 | if not str then 226 | return false 227 | end 228 | attr.prefix_sep = attr.prefix_sep or o.prefix_sep 229 | attr.indent = attr.indent or o.indent 230 | attr.nl = attr.nl or o.nl 231 | attr.suffix = attr.suffix or "" 232 | attr.prefix = attr.prefix or "" 233 | attr.no_prefix_markup = attr.no_prefix_markup or false 234 | attr.prefix = attr.no_prefix_markup and attr.prefix or b(attr.prefix) 235 | s[#s+1] = format("%s%s%s%s%s%s", attr.nl, attr.indent, 236 | attr.prefix, attr.prefix_sep, no_ASS(str), attr.suffix) 237 | return true 238 | end 239 | 240 | 241 | -- Format and append a property. 242 | -- A property whose value is either `nil` or empty (hereafter called "invalid") 243 | -- is skipped and not appended. 244 | -- Returns `false` in case nothing was appended, otherwise `true`. 245 | -- 246 | -- s : Table containing strings. 247 | -- prop : The property to query and format (based on its OSD representation). 248 | -- attr : Optional table to overwrite certain (formatting) attributes for 249 | -- this property. 250 | -- exclude: Optional table containing keys which are considered invalid values 251 | -- for this property. Specifying this will replace empty string as 252 | -- default invalid value (nil is always invalid). 253 | local function append_property(s, prop, attr, excluded) 254 | excluded = excluded or {[""] = true} 255 | local ret = mp.get_property_osd(prop) 256 | if not ret or excluded[ret] then 257 | if o.debug then 258 | print("No value for property: " .. prop) 259 | end 260 | return false 261 | end 262 | return append(s, ret, attr) 263 | end 264 | 265 | 266 | local function append_perfdata(s, dedicated_page) 267 | local vo_p = mp.get_property_native("vo-passes") 268 | if not vo_p then 269 | return 270 | end 271 | 272 | local ds = mp.get_property_bool("display-sync-active", false) 273 | local target_fps = ds and mp.get_property_number("display-fps", 0) 274 | or mp.get_property_number(compat("container-fps"), 0) 275 | if target_fps > 0 then target_fps = 1 / target_fps * 1e9 end 276 | 277 | -- Sums of all last/avg/peak values 278 | local last_s, avg_s, peak_s = {}, {}, {} 279 | for frame, data in pairs(vo_p) do 280 | last_s[frame], avg_s[frame], peak_s[frame] = 0, 0, 0 281 | for _, pass in ipairs(data) do 282 | last_s[frame] = last_s[frame] + pass["last"] 283 | avg_s[frame] = avg_s[frame] + pass["avg"] 284 | peak_s[frame] = peak_s[frame] + pass["peak"] 285 | end 286 | end 287 | 288 | -- Pretty print measured time 289 | local function pp(i) 290 | -- rescale to microseconds for a saner display 291 | return format("%05d", i / 1000) 292 | end 293 | 294 | -- Format n/m with a font weight based on the ratio 295 | local function p(n, m) 296 | local i = 0 297 | if m > 0 then 298 | i = tonumber(n) / m 299 | end 300 | -- Calculate font weight. 100 is minimum, 400 is normal, 700 bold, 900 is max 301 | local w = (700 * math.sqrt(i)) + 200 302 | return format("{\\b%d}%02d%%{\\b0}", w, i * 100) 303 | end 304 | 305 | s[#s+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}", 306 | dedicated_page and "" or o.nl, dedicated_page and "" or o.indent, 307 | b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66, 308 | "(last/average/peak μs)", o.font_size) 309 | 310 | for frame, data in pairs(vo_p) do 311 | local f = "%s%s%s{\\fn%s}%s / %s / %s %s%s{\\fn%s}%s%s%s" 312 | 313 | if dedicated_page then 314 | s[#s+1] = format("%s%s%s:", o.nl, o.indent, 315 | b(frame:gsub("^%l", string.upper))) 316 | 317 | for _, pass in ipairs(data) do 318 | s[#s+1] = format(f, o.nl, o.indent, o.indent, 319 | o.font_mono, pp(pass["last"]), 320 | pp(pass["avg"]), pp(pass["peak"]), 321 | o.prefix_sep .. o.prefix_sep, p(pass["last"], last_s[frame]), 322 | o.font, o.prefix_sep, o.prefix_sep, pass["desc"]) 323 | 324 | if o.plot_perfdata and o.use_ass then 325 | s[#s+1] = generate_graph(pass["samples"], pass["count"], 326 | pass["count"], pass["peak"], 327 | pass["avg"], 0.9, 0.25) 328 | end 329 | end 330 | 331 | -- Print sum of timing values as "Total" 332 | s[#s+1] = format(f, o.nl, o.indent, o.indent, 333 | o.font_mono, pp(last_s[frame]), 334 | pp(avg_s[frame]), pp(peak_s[frame]), "", "", o.font, 335 | o.prefix_sep, o.prefix_sep, b("Total")) 336 | else 337 | -- for the simplified view, we just print the sum of each pass 338 | s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono, 339 | pp(last_s[frame]), pp(avg_s[frame]), pp(peak_s[frame]), 340 | "", "", o.font, o.prefix_sep, o.prefix_sep, 341 | frame:gsub("^%l", string.upper)) 342 | end 343 | end 344 | end 345 | 346 | 347 | local function append_display_sync(s) 348 | if not mp.get_property_bool("display-sync-active", false) then 349 | return 350 | end 351 | 352 | local vspeed = append_property(s, "video-speed-correction", {prefix="DS:"}) 353 | if vspeed then 354 | append_property(s, "audio-speed-correction", 355 | {prefix="/", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true}) 356 | else 357 | append_property(s, "audio-speed-correction", 358 | {prefix="DS:" .. o.prefix_sep .. " - / ", prefix_sep=""}) 359 | end 360 | 361 | append_property(s, "mistimed-frame-count", {prefix="Mistimed:", nl=""}) 362 | append_property(s, "vo-delayed-frame-count", {prefix="Delayed:", nl=""}) 363 | 364 | -- As we need to plot some graphs we print jitter and ratio on their own lines 365 | if not display_timer.oneshot and (o.plot_vsync_ratio or o.plot_vsync_jitter) and o.use_ass then 366 | local ratio_graph = "" 367 | local jitter_graph = "" 368 | if o.plot_vsync_ratio then 369 | ratio_graph = generate_graph(vsratio_buf, vsratio_buf.pos, vsratio_buf.len, vsratio_buf.max, nil, 0.8, 1) 370 | end 371 | if o.plot_vsync_jitter then 372 | jitter_graph = generate_graph(vsjitter_buf, vsjitter_buf.pos, vsjitter_buf.len, vsjitter_buf.max, nil, 0.8, 1) 373 | end 374 | append_property(s, "vsync-ratio", {prefix="VSync Ratio:", suffix=o.prefix_sep .. ratio_graph}) 375 | append_property(s, "vsync-jitter", {prefix="VSync Jitter:", suffix=o.prefix_sep .. jitter_graph}) 376 | else 377 | -- Since no graph is needed we can print ratio/jitter on the same line and save some space 378 | local vratio = append_property(s, "vsync-ratio", {prefix="VSync Ratio:"}) 379 | append_property(s, "vsync-jitter", {prefix="VSync Jitter:", nl="" or o.nl}) 380 | end 381 | end 382 | 383 | 384 | local function append_filters(s, prop, prefix) 385 | local length = 0 386 | local filters = {} 387 | 388 | for _,f in ipairs(mp.get_property_native(prop, {})) do 389 | local n = f.name 390 | if f.enabled ~= nil and not f.enabled then 391 | n = n .. " (disabled)" 392 | end 393 | 394 | local p = {} 395 | for key,value in pairs(f.params) do 396 | p[#p+1] = key .. "=" .. value 397 | end 398 | if #p > 0 then 399 | p = " [" .. table.concat(p, " ") .. "]" 400 | else 401 | p = "" 402 | end 403 | 404 | length = length + n:len() + p:len() 405 | filters[#filters+1] = no_ASS(n) .. it(no_ASS(p)) 406 | end 407 | 408 | if #filters > 0 then 409 | local ret 410 | if length < o.filter_params_max_length then 411 | ret = table.concat(filters, ", ") 412 | else 413 | local sep = o.nl .. o.indent .. o.indent 414 | ret = sep .. table.concat(filters, sep) 415 | end 416 | s[#s+1] = o.nl .. o.indent .. b(prefix) .. o.prefix_sep .. ret 417 | end 418 | end 419 | 420 | 421 | local function add_header(s) 422 | s[#s+1] = text_style() 423 | end 424 | 425 | 426 | local function add_file(s) 427 | append(s, "", {prefix="File:", nl="", indent=""}) 428 | append_property(s, "filename", {prefix_sep="", nl="", indent=""}) 429 | if not (mp.get_property_osd("filename") == mp.get_property_osd("media-title")) then 430 | append_property(s, "media-title", {prefix="Title:"}) 431 | end 432 | 433 | local ch_index = mp.get_property_number("chapter") 434 | if ch_index and ch_index >= 0 then 435 | append_property(s, "chapter-list/" .. tostring(ch_index) .. "/title", {prefix="Chapter:"}) 436 | append_property(s, "chapter-list/count", 437 | {prefix="(" .. tostring(ch_index + 1) .. "/", suffix=")", nl="", 438 | indent=" ", prefix_sep=" ", no_prefix_markup=true}) 439 | end 440 | 441 | local demuxer_cache = mp.get_property_native("demuxer-cache-state", {}) 442 | if demuxer_cache["fw-bytes"] then 443 | demuxer_cache = demuxer_cache["fw-bytes"] -- returns bytes 444 | else 445 | demuxer_cache = 0 446 | end 447 | local demuxer_secs = mp.get_property_number("demuxer-cache-duration", 0) 448 | local stream_cache = mp.get_property_number("cache-used", 0) * 1024 -- returns KiB 449 | if stream_cache + demuxer_cache + demuxer_secs > 0 then 450 | append(s, utils.format_bytes_humanized(stream_cache + demuxer_cache), {prefix="Total Cache:"}) 451 | append(s, utils.format_bytes_humanized(demuxer_cache), {prefix="(Demuxer:", 452 | suffix=",", nl="", no_prefix_markup=true, indent=o.prefix_sep}) 453 | append(s, format("%.1f", demuxer_secs), {suffix=" sec)", nl="", indent="", 454 | no_prefix_markup=true}) 455 | local speed = mp.get_property_number("cache-speed", 0) 456 | if speed > 0 then 457 | append(s, utils.format_bytes_humanized(speed) .. "/s", {prefix="Speed:", nl="", 458 | indent=o.prefix_sep, no_prefix_markup=true}) 459 | end 460 | end 461 | append_property(s, "file-size", {prefix="Size:"}) 462 | end 463 | 464 | 465 | local function add_video(s) 466 | local r = mp.get_property_native("video-params") 467 | -- in case of e.g. lavi-complex there can be no input video, only output 468 | if not r then 469 | r = mp.get_property_native("video-out-params") 470 | end 471 | if not r then 472 | return 473 | end 474 | 475 | append(s, "", {prefix=o.nl .. o.nl .. "Video:", nl="", indent=""}) 476 | if append_property(s, "video-codec", {prefix_sep="", nl="", indent=""}) then 477 | append_property(s, "hwdec-current", {prefix="(hwdec:", nl="", indent=" ", 478 | no_prefix_markup=true, suffix=")"}, {no=true, [""]=true}) 479 | end 480 | append_property(s, "avsync", {prefix="A-V:"}) 481 | if append_property(s, compat("decoder-frame-drop-count"), 482 | {prefix="Dropped Frames:", suffix=" (decoder)"}) then 483 | append_property(s, compat("frame-drop-count"), {suffix=" (output)", nl="", indent=""}) 484 | end 485 | if append_property(s, "display-fps", {prefix="Display FPS:", suffix=" (specified)"}) then 486 | append_property(s, "estimated-display-fps", 487 | {suffix=" (estimated)", nl="", indent=""}) 488 | else 489 | append_property(s, "estimated-display-fps", 490 | {prefix="Display FPS:", suffix=" (estimated)"}) 491 | end 492 | if append_property(s, compat("container-fps"), {prefix="FPS:", suffix=" (specified)"}) then 493 | append_property(s, "estimated-vf-fps", 494 | {suffix=" (estimated)", nl="", indent=""}) 495 | else 496 | append_property(s, "estimated-vf-fps", 497 | {prefix="FPS:", suffix=" (estimated)"}) 498 | end 499 | 500 | append_display_sync(s) 501 | append_perfdata(s, o.print_perfdata_passes) 502 | 503 | if append(s, r["w"], {prefix="Native Resolution:"}) then 504 | append(s, r["h"], {prefix="x", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true}) 505 | end 506 | append_property(s, "window-scale", {prefix="Window Scale:"}) 507 | append(s, format("%.2f", r["aspect"]), {prefix="Aspect Ratio:"}) 508 | append(s, r["pixelformat"], {prefix="Pixel Format:"}) 509 | 510 | -- Group these together to save vertical space 511 | local prim = append(s, r["primaries"], {prefix="Primaries:"}) 512 | local cmat = append(s, r["colormatrix"], {prefix="Colormatrix:", nl=prim and "" or o.nl}) 513 | append(s, r["colorlevels"], {prefix="Levels:", nl=cmat and "" or o.nl}) 514 | 515 | -- Append HDR metadata conditionally (only when present and interesting) 516 | local hdrpeak = r["sig-peak"] or 0 517 | local hdrinfo = "" 518 | if hdrpeak > 1 then 519 | hdrinfo = " (HDR peak: " .. format("%.2f", hdrpeak) .. ")" 520 | end 521 | 522 | append(s, r["gamma"], {prefix="Gamma:", suffix=hdrinfo}) 523 | append_property(s, "packet-video-bitrate", {prefix="Bitrate:", suffix=" kbps"}) 524 | append_filters(s, "vf", "Filters:") 525 | end 526 | 527 | 528 | local function add_audio(s) 529 | local r = mp.get_property_native("audio-params") 530 | -- in case of e.g. lavi-complex there can be no input audio, only output 531 | if not r then 532 | r = mp.get_property_native("audio-out-params") 533 | end 534 | if not r then 535 | return 536 | end 537 | 538 | append(s, "", {prefix=o.nl .. o.nl .. "Audio:", nl="", indent=""}) 539 | append_property(s, "audio-codec", {prefix_sep="", nl="", indent=""}) 540 | append(s, r["format"], {prefix="Format:"}) 541 | append(s, r["samplerate"], {prefix="Sample Rate:", suffix=" Hz"}) 542 | append(s, r["channel-count"], {prefix="Channels:"}) 543 | append_property(s, "packet-audio-bitrate", {prefix="Bitrate:", suffix=" kbps"}) 544 | append_filters(s, "af", "Filters:") 545 | end 546 | 547 | 548 | -- Determine whether ASS formatting shall/can be used and set formatting sequences 549 | local function eval_ass_formatting() 550 | o.use_ass = o.ass_formatting and has_vo_window() 551 | if o.use_ass then 552 | o.nl = o.ass_nl 553 | o.indent = o.ass_indent 554 | o.prefix_sep = o.ass_prefix_sep 555 | o.b1 = o.ass_b1 556 | o.b0 = o.ass_b0 557 | o.it1 = o.ass_it1 558 | o.it0 = o.ass_it0 559 | else 560 | o.nl = o.no_ass_nl 561 | o.indent = o.no_ass_indent 562 | o.prefix_sep = o.no_ass_prefix_sep 563 | if not has_ansi() then 564 | o.b1 = "" 565 | o.b0 = "" 566 | o.it1 = "" 567 | o.it0 = "" 568 | else 569 | o.b1 = o.no_ass_b1 570 | o.b0 = o.no_ass_b0 571 | o.it1 = o.no_ass_it1 572 | o.it0 = o.no_ass_it0 573 | end 574 | end 575 | end 576 | 577 | 578 | -- Returns an ASS string with "normal" stats 579 | local function default_stats() 580 | local stats = {} 581 | eval_ass_formatting() 582 | add_header(stats) 583 | add_file(stats) 584 | add_video(stats) 585 | add_audio(stats) 586 | return table.concat(stats) 587 | end 588 | 589 | 590 | -- Returns an ASS string with extended VO stats 591 | local function vo_stats() 592 | local stats = {} 593 | eval_ass_formatting() 594 | add_header(stats) 595 | append_perfdata(stats, true) 596 | return table.concat(stats) 597 | end 598 | 599 | 600 | -- Returns an ASS string with stats about filters/profiles/shaders 601 | local function filter_stats() 602 | return "coming soon" 603 | end 604 | 605 | 606 | -- Current page and : mapping 607 | curr_page = o.key_page_1 608 | pages = { 609 | [o.key_page_1] = { f = default_stats, desc = "Default" }, 610 | [o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings" }, 611 | --[o.key_page_3] = { f = filter_stats, desc = "Dummy" }, 612 | } 613 | 614 | 615 | -- Returns a function to record vsratio/jitter with the specified `skip` value 616 | local function record_data(skip) 617 | init_buffers() 618 | skip = max(skip, 0) 619 | local i = skip 620 | return function() 621 | if i < skip then 622 | i = i + 1 623 | return 624 | else 625 | i = 0 626 | end 627 | 628 | if o.plot_vsync_jitter then 629 | local r = mp.get_property_number("vsync-jitter", nil) 630 | if r then 631 | vsjitter_buf.pos = (vsjitter_buf.pos % vsjitter_buf.len) + 1 632 | vsjitter_buf[vsjitter_buf.pos] = r 633 | vsjitter_buf.max = max(vsjitter_buf.max, r) 634 | end 635 | end 636 | 637 | if o.plot_vsync_ratio then 638 | local r = mp.get_property_number("vsync-ratio", nil) 639 | if r then 640 | vsratio_buf.pos = (vsratio_buf.pos % vsratio_buf.len) + 1 641 | vsratio_buf[vsratio_buf.pos] = r 642 | vsratio_buf.max = max(vsratio_buf.max, r) 643 | end 644 | end 645 | end 646 | end 647 | 648 | 649 | -- Call the function for `page` and print it to OSD 650 | local function print_page(page) 651 | if o.persistent_overlay then 652 | mp.set_osd_ass(0, 0, pages[page].f()) 653 | else 654 | mp.osd_message(pages[page].f(), display_timer.oneshot and o.duration or o.redraw_delay + 1) 655 | end 656 | end 657 | 658 | 659 | local function clear_screen() 660 | if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end 661 | end 662 | 663 | 664 | -- Add keybindings for every page 665 | local function add_page_bindings() 666 | local function a(k) 667 | return function() 668 | curr_page = k 669 | print_page(k) 670 | if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end 671 | end 672 | end 673 | for k, _ in pairs(pages) do 674 | mp.add_forced_key_binding(k, k, a(k), {repeatable=true}) 675 | end 676 | end 677 | 678 | 679 | -- Remove keybindings for every page 680 | local function remove_page_bindings() 681 | for k, _ in pairs(pages) do 682 | mp.remove_key_binding(k) 683 | end 684 | end 685 | 686 | 687 | local function process_key_binding(oneshot) 688 | -- Stats are already being displayed 689 | if display_timer:is_enabled() then 690 | -- Previous and current keys were oneshot -> restart timer 691 | if display_timer.oneshot and oneshot then 692 | display_timer:kill() 693 | print_page(curr_page) 694 | display_timer:resume() 695 | -- Previous and current keys were toggling -> end toggling 696 | elseif not display_timer.oneshot and not oneshot then 697 | display_timer:kill() 698 | clear_screen() 699 | remove_page_bindings() 700 | if recorder then 701 | mp.unregister_event(recorder) 702 | recorder = nil 703 | end 704 | end 705 | -- No stats are being displayed yet 706 | else 707 | if not oneshot and (o.plot_vsync_jitter or o.plot_vsync_ratio) then 708 | recorder = record_data(o.skip_frames) 709 | mp.register_event("tick", recorder) 710 | end 711 | display_timer:kill() 712 | display_timer.oneshot = oneshot 713 | display_timer.timeout = oneshot and o.duration or o.redraw_delay 714 | add_page_bindings() 715 | print_page(curr_page) 716 | display_timer:resume() 717 | end 718 | end 719 | 720 | 721 | -- Create the timer used for redrawing (toggling) or clearing the screen (oneshot) 722 | -- The duration here is not important and always set in process_key_binding() 723 | display_timer = mp.add_periodic_timer(o.duration, 724 | function() 725 | if display_timer.oneshot then 726 | display_timer:kill() ; clear_screen() ; remove_page_bindings() 727 | else 728 | print_page(curr_page) 729 | end 730 | end) 731 | display_timer:kill() 732 | 733 | -- Single invocation key binding 734 | mp.add_key_binding(o.key_oneshot, "display-stats", function() process_key_binding(true) end, 735 | {repeatable=true}) 736 | 737 | -- Toggling key binding 738 | mp.add_key_binding(o.key_toggle, "display-stats-toggle", function() process_key_binding(false) end, 739 | {repeatable=false}) 740 | 741 | -- Single invocation bindings without key, can be used in input.conf to create 742 | -- bindings for a specific page: "e script-binding stats/display-page-2" 743 | for k, _ in pairs(pages) do 744 | mp.add_key_binding(nil, "display-page-" .. k, function() process_key_binding(true) end, 745 | {repeatable=true}) 746 | end 747 | 748 | -- Reprint stats immediately when VO was reconfigured, only when toggled 749 | mp.register_event("video-reconfig", 750 | function() 751 | if display_timer:is_enabled() then 752 | print_page(curr_page) 753 | end 754 | end) 755 | --------------------------------------------------------------------------------