Log in

View Full Version : Preview for Vapoursynth scripts as python module


_Al_
14th June 2020, 23:28
view.py is a python script/module for Python/vapoursynth scripts that previews VideoNode (clip) on screen.

It is a pythonic solution to play or compare vapoursynth clips by using opencv module. For windows, linux. In theory it should work on Mac as well, but keybindings might need to be fixed. More about that on github.

links and instruction on github (https://github.com/UniversalAl/view)

simple usage:
import vapoursynth as vs
from view import Preview
clip = vs.core.lsmas.LibavSMASHSource('source.mp4')
Preview(clip)
or comparing clips example:
import vapoursynth as vs
from view import Preview
clip = vs.core.lsmas.LibavSMASHSource('source.mp4')
changed_clip = clip.std.Expr(['x 20 -','','']) #darken luma
Preview([clip, changed_clip])

It uses keybindings to get informations (pixel values in YUV or RGB, props, real cropping values). Mouse is used to crop or to just quickly 2x zoom in. That was the main purpose for this project to quickly zoom in on mouse position after double click and then pressing '1' to '9' numerical keys to compare clips.

KEYBINDINGS:

MOUSE LEFT DOUBLECLICK zooms in 2x, centers on mouse position
'Z' - same as above, zooms in 2x as well, again centers on mouse position

MOUSE LEFT CLICK and MOVE initiates crop mode, selecting rectangle with mouse, confirm it with ENTER KEY
or doubleclick inside of selected area or mouse right click
while touching first anchor point, it snaps to to a pixel following subsumpling,
also while drawing a rectangle , it snaps to mods (2,4,8 or 16), whatever is passed as argument
default modes: mod_x=2, mod_y=2
key 'Z' - zooms 2x in as well, again using mouse to be a center if available
key 'R' - RESETs preview to original 1:1 clip on screen
key 'I' - prints YUV or RGB values for pixel under mouse pointer in preview window
printing is in this format:
clip number, _PictType (I,B or P), frame number ,absolute pixel coordinates,
original clip YUV or RGB values, preview RGB values
key 'P' prints all available frame properties (_PictType, _Matrix, _Primaries ...etc.)
key 'W' - save PNG image, what you just preview and it will be saved on hardisk as 8bit PNG as 1:1,
ingnoring zoom that you have on screen
key 'E' - save PNG image, what you just preview and it will be saved on hardisk as 8bit PNG,
it will be saved as you see on screen, respecting zoom, pixel blocks
key Spacebar - Play/Pause switch
key ',' - '<' step one frame back
key '.' - '>' step one frame forward
'Home' - go to first frame
'End' - go to last frame
Seeking is source plugin dependant so it could take a time and window could freeze for a while.
key 'Esc' returns to PREVIOUS zoom or crop
key 'Q' Quits app.
key 'S' Slider on/off,
Seeking is source plugin dependant, could be major problem,
so moving slider might have conciderable delay and freeze
key 'F' Fullscreen on/off switch
key 'H' help, prints this keybinding text into console

lansing
15th June 2020, 00:56
How should I open it?

_Al_
15th June 2020, 03:38
Treat it as a regular python module with dependencies, which are numpy and opencv in this case. You have to install both.

Then you download view.py and output_window.py (optional). So same rules like any import module, it has to be either in site-packages directory for you installed Python, or have them in a directory where your Python script is.

lansing
15th June 2020, 05:56
I got it working with normal python.

All the functions seems to work, you can switch between different videos on playback, which is a feature I have never seen before wow. Problem I see is that resizing window doesn't keep with the aspect ratio, as well as crop + zoom.

_Al_
16th June 2020, 04:52
I see is that resizing window doesn't keep with the aspect ratio, as well as crop + zoom.
Double click zooms in 2x so it keeps aspect ratio, meaning whatever was on screen before so that is fine for now, that is the main reason using it with quick zoom in on mouse position. Then quick comparisons etc.

If cropping while holding SHIFT, cropping selection while drawing with mouse always snaps to the same aspect ratio as video clip resolution has, so that can help. Cropped image fills current window.

Crop is keeping aspect ratio on my Linux though. So at first I did not even noticed. I have openCV version with Qt library on Linux, so that might be the reason, but not sure 100%. After the crop is drawn by mouse it keeps same window but it creates white blocks of letterbox or pillarbox. Not on Windows, where I use openCV build that was compiled without Qt library. It just fills previous window, not keeping aspect ratio.
That could be fixed by re-drawing window every time after crop, but I skipped that because then cropping did not work during playback smoothly and there are other smooth issues, maybe will give it some argument for it.

Window could be always adjusted manually.

groucho86
3rd September 2020, 18:40
Heartfelt thank you, _AI_. Love being able to work in a Python IDE and easily get previews. A-B'ing between clips is also very well implemented.