VideoHelp Forum
+ Reply to Thread
Results 1 to 14 of 14
  1. 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.
    See post #10 for the additional functions added.

    CPreview 2024-06-15 (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.


    Last edited by hello_hello; 14th Jun 2024 at 16:41.
    Quote Quote  
  2. I'm glad you'll have a use for it!
    Quote Quote  
  3. 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.
    Last edited by hello_hello; 29th Jan 2022 at 01:55.
    Quote Quote  
  4. 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.
    Quote Quote  
  5. There's a link for a new version dated 2023-09-25 in the opening post.

    The Avisynth version hasn't changed in functionality (just cleaned up the syntax a bit) but there's now also a VapourSynth flavour.
    Quote Quote  
  6. 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
    You might want to add support for the float types (RGBS, RGBH, YUV444PH, YUV444PS).

    Cu Selur
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  7. Originally Posted by Selur View Post
    You might want to add support for the float types (RGBS, RGBH, YUV444PH, YUV444PS).

    Cu Selur
    Did I do a silly or does that syntax convert float to integer?
    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)
    ], mismatch=True)

    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.
    Quote Quote  
  8. There's a link for a new version dated 2023-10-02 in the opening post.
    Quote Quote  
  9. There's a link for a new version dated 2024-06-10 in the opening post.
    I've added some additional wrapper functions for displaying the cropping previews, but without displaying any text.
    The new wrapper functions are used by prefixing Crop() with "q" instead of "p", because I couldn't think of a more appropriate letter to use and alphabetically "q" comes after "p".

    So now you can also use
    Quote Quote  
  10. Member
    Join Date
    Aug 2018
    Search PM
    Does not work:

    Quote Quote  
  11. Yeah, you're correct. I never crop that way so I never considered it. I'll probably update the function in the near future so it'll work.
    Quote Quote  
  12. It turns out I did consider it, but at some stage a couple of plus signs became minus signs and it broke.
    Here's a fixed version until I update the zip file.

    - deleted -
    Last edited by hello_hello; 14th Jun 2024 at 16:42.
    Quote Quote  
  13. There's a link for a new version dated 2024-06-15 in the opening post.

    For the Avisynth version I fixed not being able to specify right and bottom cropping as a positive value.
    For both versions there's a small function added to the end of the scripts. Modifying the return value will change the thickness of the lines used for the first cropping preview.
    Quote Quote  

Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!