Avisynth and VapourSynth cropping preview functions
The cropping preview function now comes in both Avisynth and VapourSynth flavours.
The examples below use Avisynth syntax, but the VapourSynth version works in much the same manner (see the help file for exact details).
The name of the script has been changed to CPreview for both versions.
CPreview 2023-10-02 (Cropping Preview).zip
This function is based on the previews from the CropResize script.
I thought I'd upload it for anyone who's interested. Sometimes it's easier to look at what you're cropping before actually cropping it.
It's very simple to use, although there is a help file. When using the Crop() function, you can use pCrop() for a cropping preview (naturally when you adjust the cropping you need to refresh the preview), and when you're happy, remove the "p" from the beginning of the function name to crop.
There's three cropping previews, and the other two are enabled by adding more "p"s.
Obviously this image doesn't really need cropping, but to demonstrate...
pCrop shows the cropping preview as yellow lines.
ppCrop shows the cropping preview as yellow transparent borders.
And pppCrop shows the cropping preview as the inverse of the picture, much like AvsPmod's preview.
Naturally when you're happy, you just remove the "p"s to crop.
Because sometimes it's handy, there's also wrapper functions for displaying the current frame number and/or time over the video. The help file has details, but they work by appending letters to the other side of the function name, and can be used with or without a cropping preview enabled.
+ Reply to Thread
Results 1 to 9 of 9
Last edited by hello_hello; 1st Oct 2023 at 13:11.
Very handy tool!
I'm glad you'll have a use for it!
New version dated 2022-01-29 in the opening post. Functionality hasn't changed. Just cleaned up the syntax and adjusted the text display a little.
And a quick update to change the cropping to unnamed arguments to match the Crop function as it makes more sense.
Also changed the default behaviour of the CropF, CropT and CropP functions so they apply the cropping. New version dated 2022-01-30.
Had a quick look at the Vapoursynth script (haven't tested it):
Source444 = vc.resize.Bicubic(Source, format=vs.RGB48) \ if (Source_Sample_Type != 0) and (SCFamily == vs.RGB) else \ vc.resize.Bicubic(Source, format=vs.GRAY16) \ if (Source_Sample_Type != 0) and (SCFamily == vs.GRAY) else \ vc.resize.Bicubic(Source, format=vs.YUV444P16) \ if (Source_Sample_Type != 0) and (SCFamily == vs.YUV) else \ eval("vc.resize.Bicubic(Source, format=vs.YUV444P" + str(Source_Bits)+ ")") \ if (SCFamily == vs.YUV) and (Is444 is False) else Source
Cu Selurusers currently on my ignore list: deadrats, Stears555
The reason float is converted to integer for the preview is because the mask clip used for MaskMerge has to be full range, so the appropriate scaling must be used for Levels when converting YUV masks to full range and I'm not sure how to best do it for float. I wasn't sure if YUV float is always full range anyway, and the Levels function description says
Note that the range behavior is unintuitive for YUV float formats since the assumed range will be 0-1 even for the UV-planes.
In the end the easy/lazy way to deal with float seemed to be to just convert it to 16 bit for the preview. I'm pretty sure I tested it, but if the result is incorrect I guess I should change it.
Thinking about it now, VapourSynth makes previewing cropping while splicing clips easier because it supports splicing of clips with different dimensions. It's probably not needed when using the Cropping Preview function but a similar function is built into CropResize, the idea being you can splice clips while enabling a single copping preview this way:
clip = core.std.Splice([
CR.CropResize(clip[0:99], 640,480, 8, 10, 2, 4),
CR.CropResize(clip[100:199], 640,480, 16, 10, 6, 4, CPreview=1),
CR.CropResize(clip[200:299], 640,480, 8, 10, 2, 4)
I guess that'd fail for float because the clip with the cropping preview enabled is converted to integer and clips of different bitdepths can't be spliced.
You could work around it by temporarily converting the source clip to integer before splicing, but it's a scenario I hadn't considered. It's the only time converting float to 16 bit for a preview might be an issue but it probably isn't a problem for the stand-alone cropping preview function.
I kind-of remember another reason for float being a pain but that could be wishful thinking. Maybe I should re-think the float conversion at some stage though.