-
-
Save l00tzOMG/404e81cdcae2e7415dd96b57b08f32ce to your computer and use it in GitHub Desktop.
FFInfo for VapourSynth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Pimped version of nyuszika7h's original VS_FFInfo script | |
v1.3 by l00t | |
Example: | |
a = core.ffms2.Source('a.mkv') | |
b = core.ffms2.Source('b.mkv') | |
a = a.resize.Spline36(1920, 1080) | |
a = FFInfo(a, text='720p', frame_num=True, frame_type=True, frame_time=True) | |
b = FFInfo(b, text='1080p', frame_num=True, frame_type=True, frame_time=True) | |
core.std.Interleave([a, b]).set_output() | |
If you want different custom text than the rest, call the function twice: | |
clip = vs_ffinfo.FFInfo(clip, text='Flip da script', frame_num=False, frame_type=False, frame_format=False, frame_resol=False, frame_fps=False, frame_time=False, frame_primaries=False, frame_matrix=False, frame_transfer=False, frame_chromaloc=False, frame_interlaced=False, frame_sar=False, frame_fullformat=False, color='0000FF00', size=40, top=200) | |
clip = vs_ffinfo.FFInfo(clip, frame_num=True, frame_type=True, frame_time=False, frame_fps=True, frame_primaries=True, frame_matrix=True, frame_transfer=True, frame_chromaloc=True, frame_interlaced=False, frame_sar=False, frame_fullformat=False, color='0000FFFF') | |
""" | |
import functools | |
import time | |
import vapoursynth as vs | |
core = vs.get_core() | |
def FrameInfo(n, f, clip, frame_num=True, frame_type=True, frame_format=True, frame_resol=True, frame_fps=True, frame_time=False, frame_primaries=False, frame_matrix=False, frame_transfer=False, frame_chromaloc=False, frame_colorrange=False, frame_interlaced=False, frame_sar=False, frame_fullformat=False, text=None, color='0000FFFF', size=20, numpad=7, top=10, left=10): | |
# NOTE: color is in format AABBGGRR | |
lines = [] | |
if text: | |
lines.append(text) | |
lines.append('') | |
if frame_num: | |
lines.append(f'Frame {n} of {len(clip) - 1}') | |
if frame_type: | |
lines.append(f'Frame type: {f.props["_PictType"].decode("utf-8")}') | |
if frame_format: | |
lines.append(f'Frame format: {f.format.name}') | |
if frame_resol: | |
lines.append(f'Resolution: {f.width} x {f.height}') | |
if frame_fps: | |
lines.append(f'FPS: {clip.fps}') | |
if frame_time: | |
t = f.props["_AbsoluteTime"] | |
(h, m) = divmod(t, 3600) | |
(m, s) = divmod(m, 60) | |
(s, ms) = divmod(s, 1) | |
h = int(h) | |
m = int(m) | |
s = int(s) | |
ms = int(ms * 1000) | |
lines.append(f'Time: {h:02d}:{m:02d}:{s:02d}.{ms:03d}') | |
if frame_primaries: | |
PRIMARIES = { | |
0 : 'reserved', | |
1 : 'BT.709', | |
2 : 'undef', | |
3 : 'reserved', | |
4 : 'BT.470 M', | |
5 : 'BT.470 B/G', | |
6 : 'BT.601', | |
7 : 'SMPTE ST 240', | |
8 : 'Generic film', | |
9 : 'BT.2020', | |
10 : 'SMPTE ST 428', | |
11 : 'P3DCI', | |
12 : 'P3D65', | |
22 : 'EBU Tech. 3213-E' | |
} | |
try: | |
lines.append(f'Primaries: {PRIMARIES[f.props["_Primaries"]]}') | |
except Exception as e: | |
lines.append(f'Primaries: {str(e)}') | |
if frame_matrix: | |
COLORMATRIX = { | |
0 : 'RGB', | |
1 : 'BT.709', | |
2 : 'undef', | |
3 : 'reserved', | |
4 : 'FCC T47', | |
5 : 'BT.470 B/G', | |
6 : 'BT.601', | |
7 : 'SMPTE ST 240', | |
8 : 'YCgCo', | |
9 : 'BT.2020ncl', | |
10 : 'BT.2020cl', | |
11 : 'SMPTE ST 2085', | |
12 : 'Chroma ncl', | |
13 : 'Chroma cl', | |
14 : 'BT.2100' | |
} | |
try: | |
lines.append(f'Color matrix: {COLORMATRIX[f.props["_Matrix"]]}') | |
except Exception as e: | |
lines.append(f'Color matrix: {str(e)}') | |
if frame_transfer: | |
TRANSFER = { | |
0 : 'reserved', | |
1 : 'BT.709', | |
2 : 'undef', | |
3 : 'reserved', | |
4 : 'BT.470 M', | |
5 : 'BT.470 B/G', | |
6 : 'BT.601', | |
7 : 'SMPTE ST 240', | |
8 : 'linear', | |
9 : 'log100', | |
10 : 'log316', | |
11 : 'xvycc (IEC 61966-2-4)', | |
12 : 'BT.1361', | |
13 : 'IEC 61966 sRGB', | |
14 : 'BT.2020_10', | |
15 : 'BT.2020_12', | |
16 : 'SMPTE ST 2084', | |
17 : 'SMPTE ST 428', | |
18 : 'BT.2100 HLG' | |
} | |
try: | |
lines.append(f'Transfer: {TRANSFER[f.props["_Transfer"]]}') | |
except Exception as e: | |
lines.append(f'Transfer: {str(e)}') | |
if frame_chromaloc: | |
CHROMALOC = { | |
0 : 'left', | |
1 : 'center', | |
2 : 'top-left', | |
3 : 'top', | |
4 : 'bottom-left', | |
5 : 'bottom' | |
} | |
try: | |
lines.append(f'Chroma location: {f.props["_ChromaLocation"]}; {CHROMALOC[f.props["_ChromaLocation"]]}') | |
except Exception as e: | |
lines.append(f'Chroma location: {str(e)}') | |
if frame_colorrange: | |
COLORRANGE = { | |
0 : 'full (PC)', | |
1 : 'limited (TV)' | |
} | |
try: | |
lines.append(f'Color range: {f.props["_ColorRange"]}; {COLORRANGE[f.props["_ColorRange"]]}') | |
except Exception as e: | |
lines.append(f'Color range: {str(e)}') | |
if frame_interlaced: | |
FIELDBASED = { | |
0 : 'progressive', | |
1 : 'BFF (Bottom Field First)', | |
2 : 'TFF (Top Field First)' | |
} | |
try: | |
lines.append(f'Field type: {f.props["_FieldBased"]}; {FIELDBASED[f.props["_FieldBased"]]}') | |
except Exception as e: | |
lines.append(f'Field type: {str(e)}') | |
if frame_sar: | |
lines.append(f'SAR: {f.props["_SARNum"]}:{f.props["_SARDen"]}') | |
if frame_fullformat: | |
lines.append(f'\n{f.format}') | |
return clip.sub.Subtitle( | |
'\n'.join(lines), | |
start=n, | |
end=n + 1, | |
style=f'sans-serif,{size},&H{color},&H00000000,&H00000000,&H00000000,1,0,0,0,100,100,0,0,1,2,0,{numpad},{left},10,{top},1' | |
) | |
def FFInfo(clip, **kwargs): | |
return clip.std.FrameEval(functools.partial(FrameInfo, clip=clip, f=[clip], **kwargs), [clip]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment