jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
547 stars 68 forks source link

Need help with complex property #130

Closed smallnetbuilder closed 3 years ago

smallnetbuilder commented 4 years ago

I'm trying to access vo-passes properties. I can get player._get_property('vo-passes') to work, but it returns an odd json-like structure. Here's a sample. {'fresh': [{'desc': 'upload frame (naive)', 'last': 83, 'avg': 83, 'peak': 83, 'count': 12, 'samples': [83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83]}, {'desc': 'color conversion + output to screen', 'last': 236416, 'avg': 185380, 'peak': 236416, 'count': 21, 'samples': [50500, 60250, 219000, 219500, 214416, 182833, 195333, 192666, 206083, 216583, 220916, 177750, 179750, 214833, 169583, 182333, 170333, 213750, 183333, 186833, 236416]}, {'desc': 'drawing osd', 'last': 5916, 'avg': 6198, 'peak': 9333, 'count': 21, 'samples': [1416, 6833, 8666, 9000, 6333, 6000, 6666, 7583, 9333, 5583, 5666, 6083, 5750, 6000, 5333, 5333, 5666, 5833, 5166, 6000, 5916]}], 'redraw': []}

Which function do I use to access, say the upload frame (naive), avg value?

jaseg commented 4 years ago

Hey there,

that data structure is indeed a bit unwieldy. This format comes straight out of libmpv, python-mpv just passes it through to python.

One way to parse this would be to use a small helper to turn the list of stats into a dict. Then your query is easy.

map_descs = lambda l: { v['desc']: v for v in l }
map_descs(d['fresh'])['upload frame (naive)']['avg']

smallnetbuilder commented 4 years ago

Thanks. I'll give it a try. I appreciate the help!