Req Video dimensions and frame rate in Python interface
#1
As I was writing code to try to open the current XBMC.log to search and find the most recent of the following line and parse it:

Code:
07:27:22 T:8936  NOTICE:  fps: 23.976024, pwidth: 1280, pheight: 720, dwidth: 1280, dheight: 720

I thought I might give it a go and humbly request whether this information might be made available via the python api?

Currently, via InfoLabels, we can retrieve VideoCodec, VideoResolution and VideoAspect.
Unfortunately, VideoResolution != pheight and VideoResolution * VideoAspect != pwidth. So this results in all sorts of other means of trying to get this information since python does not natively provide any libraries that can retrieve this kind of info. Currently, I use a python wrapper around a third party dll (mediainfo) and since dlls cannot be included in the official repo, then I need to provide a means of downloading that dll and then it becomes an issue of platform specificity.

Since the needed info is printed into the log, I was considering reading the log and parsing it when the 'onPlaybackStarted' event fires.

However this seems a bit crazy when XBMC (Kodi) knows this info.

Is there anyone on the dev team that would be willing to make this info available via the python api? Whether its a property of xbmc.Player, an InfoLabel or even via JSON?

Thanks for your consideration. I understand it's a bit of work, likely for someone that doesn't write in python. If I had any talent whatsoever in cpp, I would give it a go, but I am sadly lacking there.
Reply
#2
+1 would love to see this feature implemented.

I had resorted to using subprocess to call ffmpeg in an Android specific add-on.
This was a poor workaround as it required root to install an executable version of ffpmeg.

I'll try switching to the parse log method noted above (big Thank You once again to KenV99 for this idea).
Reply
#3
Well, for anyone interested, I wrote a small subroutine to do this. It reads the last approx 10 lines of the log and parses them and returns a dictionary with keys and values for the info:
Code:
import xbmc

def get_log_mediainfo():
    """
    Retrieves dimensions and framerate information from XBMC.log
    Will likely fail if XBMC in debug mode - could be remedied by increasing the number of lines read
    Props: http://stackoverflow.com/questions/260273/most-efficient-way-to-search-the-last-x-lines-of-a-file-in-python
    @return: dict() object with the following keys:
                                'pwidth' (int)
                                'pheight' (int)
                                'par' (float)
                                'dwidth' (int)
                                'dheight' (int)
                                'dar' (float)
                                'fps' (float)
    @rtype: dict()
    """
    logfn = xbmc.translatePath(r'special://home\XBMC.log')
    xbmc.sleep(250)  # found originally that it wasn't written yet
    with open(logfn, 'r') as f:
        f.seek(0, 2)           # Seek @ EOF
        fsize = f.tell()        # Get Size
        f.seek(max(fsize - 1024, 0), 0)  # Set pos @ last n chars
        lines = f.readlines()       # Read to end
    lines = lines[-10:]    # Get last 10 lines
    ret = None
    for line in lines:
        if 'fps:' in line:
            start = line.find('fps:')
            sub = line[start:].rstrip('\n')
            tret = dict(item.split(":") for item in sub.split(","))
            ret = {}
            for key in tret:
                tmp = key.strip()
                try:
                    if tmp == 'fps':
                        ret['fps'] = float(tret[key])
                    else:
                        ret[tmp] = int(tret[key])
                except ValueError:
                    pass
            if ret['pheight'] != 0:
                ret['par'] = float(ret['pwidth'])/float(ret['pheight'])
            if ret['dheight'] != 0:
                ret['dar'] = float(ret['dwidth'])/float(ret['dheight'])
    return ret
Reply
#4
Doesn't json return this information?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#5
(2014-08-09, 00:15)Lunatixz Wrote: Doesn't json return this information?

Not that I can find: http://wiki.xbmc.org/index.php?title=JSO...perty.Name

But if someone can show me a JSON query that gets that information, I would be overjoyed.
Reply
#6
I stand corrected at least for the height and width:
Code:
http://localhost:9091/jsonrpc?request={"jsonrpc": "2.0", "id":1, "method": "Player.GetItem", "params": { "properties": ["streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}

returns:

Code:
{"id":"VideoGetItem","jsonrpc":"2.0","result":{"item":{"id":8,"label":"Star Trek Into Darkness","streamdetails":{"audio":[{"channels":6,"codec":"dca","language":"eng"}],"subtitle":[{"language":"eng"},{"language":"eng"},{"language":"eng"},{"language":"fre"},{"language":"spa"},{"language":"por"}],"video":[{"aspect":2.4000000953674316,"codec":"h264","duration":7925,"height":800,"stereomode":"","width":1920}]},"type":"movie"}}}

Now if anyone can show me how to get the framerate...

EDIT:
This method works well for playing files, but fails for PVR channels or streaming video. And still no frame rate data that I can find.
Reply
#7
I'm also interested in this feature. I would like to save the OSD stats to a log file.
Reply
#8
this was added in kodi krypton v17:
http://forum.kodi.tv/showthread.php?tid=...pid2373685

you can get those labels in python using the xbmc.getInfoLabel() method
http://mirrors.xbmc.org/docs/python-docs...tInfoLabel
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply

Logout Mark Read Team Forum Stats Members Help
Video dimensions and frame rate in Python interface0