Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 14th June 2020, 23:28   #1  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 168
Preview for Vapoursynth scripts as python module

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

simple usage:
Code:
import vapoursynth as vs
from view import Preview
clip = vs.core.lsmas.LibavSMASHSource('source.mp4')
Preview(clip)
or comparing clips example:
Code:
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:
Code:
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

Last edited by _Al_; 21st June 2020 at 16:21.
_Al_ is offline   Reply With Quote
Old 15th June 2020, 00:56   #2  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,350
How should I open it?
lansing is online now   Reply With Quote
Old 15th June 2020, 03:38   #3  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 168
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.
_Al_ is offline   Reply With Quote
Old 15th June 2020, 05:56   #4  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,350
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.
lansing is online now   Reply With Quote
Old 16th June 2020, 04:52   #5  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 168
Quote:
Originally Posted by lansing View Post
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.

Last edited by _Al_; 16th June 2020 at 05:22.
_Al_ is offline   Reply With Quote
Old 3rd September 2020, 18:40   #6  |  Link
groucho86
Registered User
 
Join Date: Apr 2016
Posts: 60
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.
groucho86 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.