MCPcopy Create free account
hub / github.com/HelpFreedom/youthub / probe

Function probe

tui_player.py:48–69  ·  view source on GitHub ↗

Use ffprobe to get fps and dimensions.

(path: Path)

Source from the content-addressed store, hash-verified

46
47
48def probe(path: Path) -> dict:
49 """Use ffprobe to get fps and dimensions."""
50 ffprobe = need("ffprobe")
51 cmd = [
52 ffprobe, "-v", "error",
53 "-select_streams", "v:0",
54 "-show_entries", "stream=width,height,avg_frame_rate,duration",
55 "-of", "json",
56 str(path),
57 ]
58 out = subprocess.check_output(cmd).decode()
59 data = json.loads(out)["streams"][0]
60 # avg_frame_rate is "num/den"
61 fr = data.get("avg_frame_rate", "30/1")
62 num, _, den = fr.partition("/")
63 fps = float(num) / float(den or 1) if float(den or 1) else 30.0
64 return {
65 "width": int(data.get("width") or 0),
66 "height": int(data.get("height") or 0),
67 "fps": fps,
68 "duration": float(data.get("duration") or 0),
69 }
70
71
72def png_stream(stdout):

Callers 1

mainFunction · 0.85

Calls 2

getMethod · 0.80
needFunction · 0.70

Tested by

no test coverage detected