Best/easiest way to retrieve video details (resolution, fps) from library recordings?

Context: I have more than 2,000 episodes of Judge Judy in my library (thank you, Pluto TV and CBS) and they don't all have the same resolutions or frame rates. I want to see which ones are in 720p and 30fps. Some episodes are recordings from Channels DVR (MPG files) and others are imports after being edited (MKV files).

When you look at recordings from your library by fetching the data from http://127.0.0.1:8089/dvr/files, these pieces of information are not available in the json data: picture height, picture width, average frame rate.

If the devs are reading this post, any specific technical reason why this is not saved in the database? Just curious. :slight_smile:

So it seems that you have to use a third party tool in order to do this.
In my case, I would prefer to do it in a python script but I'm not against doing it in a shell script instead.

After doing some research, I have tried a few candidates for the job and ran into problems trying to install them (incompatibilities, etc.) In the end, I was able to use ffprobe, which comes with the installation of ffmpeg. It has a python module for it but it relies on the executable to be installed on the system first (in my case: Windows). I wish there was a "pythonic" way of doing it (i.e. with a built-in module) but that doesn't seem to be the case.

I have this function in python that works very well with MPG files:

def get_video_track_info(file_path):
    frame_rate     = None
    picture_height = None
    picture_width  = None
    
    probe = ffprobe.FFProbe(file_path)

    video_streams = [stream for stream in probe.streams if stream.codec_type == 'video']
    if video_streams:
        video_stream = video_streams[0]
        
        frame_rate     = round(eval(video_stream.avg_frame_rate), 2)
        picture_height = video_stream.height
        picture_width  = video_stream.width

    return frame_rate, picture_height, picture_width

Example:

file_path = "H:\DVR\TV\Judge Judy\Judge Judy S22E217 2018-06-11 Grandmother Raises Ungrat 2023-06-12-1559.mpg"

Output: 59.94, 1080, 1920

And with an MKV file, it fails:

file_path = "J:\TV\Judge Judy\Season 02\Judge Judy S02E182 1997-01-01 Episode 182 2022-06-05-1259 (S02E175).mkv"

File "C:\Users\mjitk\Documents\Scripts\cdvr_judge_judy_to_csv.py", line 61, in get_video_track_info
probe = ffprobe.FFProbe(file_path)
File "C:\Users\mjitk\AppData\Local\Programs\Python\Python310\lib\site-packages\ffprobe\ffprobe.py", line 75, in init
self.metadata[m.groups()[0]] = m.groups()[1].strip()
AttributeError: 'NoneType' object has no attribute 'groups'

ChatGPT suggests a different way of calling ffprobe via python's subprocess. I will try it later.

Until then, I wanted to ask the community, in case somebody has done something similar and would be willing to share. :slight_smile:

Download this. It'll show you directly: MediaInfo

You can also use the commandline (CLI) version of Mediainfo

1 Like

Thank you for the suggestion to use MediaInfo.

Fun fact: I have MediaInfo installed on my computer but I have only used the GUI. It never even crossed my mind to look at the CLI. Silly me. :grin:

1 Like

You can hit http://localhost:8089/dvr/files/<id>/mediainfo.json to get that info from the DVR. It is basically making that ffprobe call for you.

2 Likes

Wow! :exploding_head: Thank you, @eric ! :+1:

1 Like