VideoHelp Forum
+ Reply to Thread
Results 1 to 25 of 25
Thread
  1. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Trying to reduce file size of a UHD video (3840x2160). It's of an older full screen movie (1.37) with black bars, so I wanted to crop and resize. Cropping 440 each side yields 1.37 resolution. To maintain this aspect, the smaller resolution options are 1480x1080 (abit large) or 740x540 (abit small). Would prefer to find an in-between size for TV. One option is to resize to 988x720 but the DAR is a tad larger.
    A similar solution is to first resize to 1280x720, then crop, but the DAR would be a tad smaller.
    In both 720 encode situations, the DAR could be changed in another program to 1.37, but would that be inaccurate, or unacceptable to purists?
    Quote Quote  
  2. Why are you worried about tiny AR errors like that?
    Quote Quote  
  3. When it was pillarboxed, an aspect error was most likely introduced to jam it forcefully to one dimension and keep subsumpling. Or perhaps master had already a tiny ar error as well. No point to be that pedant and keep two decimal floating point as well. I would not worry. If you are lucky you actually might end up fixing that error.
    Quote Quote  
  4. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Originally Posted by jagabo View Post
    Why are you worried about tiny AR errors like that?
    I'd like to get it right, and I figured there must be a method or trick to preserve AR at more resolutions. If there was, it would help with other encodes.
    Quote Quote  
  5. If you want to find out best resolution with almost no AR error, you can run Python code for example, it has to include mods for subsampling and range you want to include, for example for you new height from 700 to 740 and you let it run or you decide. Or you start with a width range like 960 to 1010 to get height:
    Code:
    WIDTH = 3840-440-440 #(2960)
    HEIGHT = 2160
    MODX = 2  #for YUV420, but it can be testes as both values as 4 (mod4) or 8 (mod8)
    MODY = 2
    NEW_WIDTH_RANGE  = (960, 1010)
    NEW_HEIGTH_RANGE = (700,740)
    
    
    def boxing(w, h, W, H):
        #back check, if w/h is not too off, x or y positive values means it is quite off
        if W/H > w/h:
            w = w*H/h
            x = int((W-w)/2)
            x = x - x%MODX
            return max(0, x)
        else:
            h = h*W/w
            y = int((H-h)/2)
            y = y - y%MODY
            return max(0, y)
    
    for h in range(*NEW_HEIGTH_RANGE, MODY):
        h = h - h%MODY
        w = WIDTH/HEIGHT *h
        w = w - w%MODX
        off_value = boxing(w, h, WIDTH, HEIGHT)
        if not off_value:
            print(f'new width = {int(w)}, new height = {int(h)} new ar = {w/h}') 
    print('')   
    for w in range(*NEW_WIDTH_RANGE, MODX):
        w = w - w%MODX
        h = HEIGHT/WIDTH *w
        h = h - h%MODY
        off_value = boxing(w, h, WIDTH, HEIGHT)
        if not off_value:
            print(f'new width = {int(w)}, new height = {int(h)} new ar = {w/h}')
    edit: I fix code above, same results, but it is more readable, more logical to read the code

    you'd get:
    Code:
    new width = 958, new height = 700 new ar = 1.3685714285714285
    new width = 962, new height = 702 new ar = 1.3703703703703705
    new width = 964, new height = 704 new ar = 1.3693181818181819
    new width = 970, new height = 708 new ar = 1.3700564971751412
    new width = 972, new height = 710 new ar = 1.3690140845070422
    new width = 978, new height = 714 new ar = 1.3697478991596639
    new width = 980, new height = 716 new ar = 1.3687150837988826
    new width = 986, new height = 720 new ar = 1.3694444444444445
    new width = 992, new height = 724 new ar = 1.3701657458563536
    new width = 994, new height = 726 new ar = 1.3691460055096418
    new width = 1000, new height = 730 new ar = 1.36986301369863
    new width = 1002, new height = 732 new ar = 1.3688524590163935
    new width = 1008, new height = 736 new ar = 1.3695652173913044
    new width = 1010, new height = 738 new ar = 1.3685636856368564
    
    new width = 960, new height = 700 new ar = 1.3714285714285714
    new width = 962, new height = 702 new ar = 1.3703703703703705
    new width = 966, new height = 704 new ar = 1.3721590909090908
    new width = 968, new height = 706 new ar = 1.3711048158640227
    new width = 972, new height = 708 new ar = 1.3728813559322033
    new width = 974, new height = 710 new ar = 1.371830985915493
    new width = 976, new height = 712 new ar = 1.3707865168539326
    new width = 980, new height = 714 new ar = 1.3725490196078431
    new width = 982, new height = 716 new ar = 1.3715083798882681
    new width = 984, new height = 718 new ar = 1.3704735376044568
    new width = 988, new height = 720 new ar = 1.3722222222222222
    new width = 990, new height = 722 new ar = 1.371191135734072
    new width = 996, new height = 726 new ar = 1.371900826446281
    new width = 998, new height = 728 new ar = 1.370879120879121
    new width = 1002, new height = 730 new ar = 1.3726027397260274
    new width = 1004, new height = 732 new ar = 1.3715846994535519
    new width = 1006, new height = 734 new ar = 1.3705722070844686
    so you can grab resolution that is closest to your 1.37037
    Last edited by _Al_; 17th Jan 2023 at 11:50.
    Quote Quote  
  6. with all mod as 4, you'd get:
    Code:
    new width = 964, new height = 704 new ar = 1.3693181818181819
    new width = 968, new height = 708 new ar = 1.3672316384180792
    new width = 980, new height = 716 new ar = 1.3687150837988826
    new width = 992, new height = 724 new ar = 1.3701657458563536
    new width = 996, new height = 728 new ar = 1.3681318681318682
    new width = 1008, new height = 736 new ar = 1.3695652173913044
    
    new width = 960, new height = 700 new ar = 1.3714285714285714
    new width = 968, new height = 704 new ar = 1.375
    new width = 972, new height = 708 new ar = 1.3728813559322033
    new width = 976, new height = 712 new ar = 1.3707865168539326
    new width = 984, new height = 716 new ar = 1.3743016759776536
    new width = 988, new height = 720 new ar = 1.3722222222222222
    new width = 1000, new height = 728 new ar = 1.3736263736263736
    new width = 1004, new height = 732 new ar = 1.3715846994535519
    all mods as 8 it would be:
    Code:
    new width = 952, new height = 696 new ar = 1.367816091954023
    new width = 960, new height = 704 new ar = 1.3636363636363635
    new width = 984, new height = 720 new ar = 1.3666666666666667
    
    new width = 960, new height = 696 new ar = 1.3793103448275863
    new width = 968, new height = 704 new ar = 1.375
    new width = 976, new height = 712 new ar = 1.3707865168539326
    new width = 992, new height = 720 new ar = 1.3777777777777778
    new width = 1000, new height = 728 new ar = 1.3736263736263736
    So as best mod 8, and closest to your AR, it seams to be that the winner might be:
    976 x 712 ,new ar = 1.3707865168539326
    or to keep conventions 720p:
    992x720 is not bad as well
    Last edited by _Al_; 16th Jan 2023 at 23:58.
    Quote Quote  
  7. Originally Posted by spiritgumm View Post
    I'd like to get it right
    There is no "right". For example to get exactly 1.37:1 AR with a 720 pixel height requires you resize to a horizontal size of 986.4 (720 * 1.37). Since you are probably working with YUV 4:2:0 video the nearest you can get is a mod 2 frame size of 986x720. But that is mod 2. Some players have problems with mod 2 frame sizes so the software is saving you from yourself and using mod 4 sizes. The nearest mod 4 size is 988x720 (1.37222...:1). It knows you cannot see a ~0.162 percent AR error.
    Quote Quote  
  8. Mod 4:
    988x720
    1480x1080
    Quote Quote  
  9. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Since there is no perfect fit in the 720 range, any comment about changing its DAR in mkvtoolnix (mmg.exe) to 1.370?
    Quote Quote  
  10. Not all players will respect MKV DAR (and other) flags.
    Quote Quote  
  11. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    So if I want to maintain the old "Academy ratio" (1.370) which the film was released in, from a purist point of view, I'm limited to the few exact resolutions, correct?
    Quote Quote  
  12. A purist would check to see if the 1.37 transfer was correct . Often there are slight AR errors to begin with
    Quote Quote  
  13. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    The movie was painstakingly remastered, and is listed on imdb as being 1.37:1. I'm not dismissing that the AR could be wrong, but I don't know how to check it.
    Quote Quote  
  14. You'd have to measure some known objects (such as a circular wall clock), shot straight on ( preferably at the center of the frame to reduce lens curvature issues) . There are several threads discussing this. Otherwise there is a possibility that you're jumping through these hoops worrying about 0.2% errors and just propagating the upstream AR errors which might be more than 0.2% in the first place
    Quote Quote  
  15. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Thanks for all the replies.
    Quote Quote  
  16. If you make the assumption the transfer was correct without small AR errors - the "perfect fit" at 720 is 1280x720. ie. don't crop it.
    Quote Quote  
  17. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    I suppose that's one idea, but I also wanted to compress the UHD video to a smaller file, and it seems a waste to keep the black bars.
    Quote Quote  
  18. Constant clean black bars do not "cost" much bitrate to encode, probably <0.5% . If they are not clean (unlikely for a remastered release), you can crop and add clean ones back.
    Quote Quote  
  19. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    I assumed (incorrectly) that any large border would take up significant space.
    Quote Quote  
  20. That is my approach as well downsizing with black bars as well, I actually do exactly that. And only after resizing you can crop to the mod, possibly leave tiny black bars, if you do not want to crop to live image - I do not recommend that, who cares that there is 2 pixels left or right.
    You end up exactly with 100% same aspect ratio.

    But I had some heated discussion about that, supposedly resize is not correct at the border etc. , folks usually love to crop -resize - and actually possibly crop again, that makes no sense at all. So supposedly one downsizes image, which translates to downgrading and then persisting about not correct resize that actually brings AR error. Sometimes one has to think straight, what actually makes sense.
    Quote Quote  
  21. Originally Posted by _Al_ View Post
    But I had some heated discussion about that, supposedly resize is not correct at the border etc. , folks usually love to crop -resize - and actually possibly crop again, that makes no sense at all. So supposedly one downsizes image, which translates to downgrading and then persisting about not correct resize that actually brings AR error. Sometimes one has to think straight, what actually makes sense.
    A resampler will technically be incorrect at border of black pixels, because the black pixels add contamination. For example , if you take bicubic or spline, it uses 16 pixels (4x4 grid)

    Eitherway there are tradeoffs . Best is do nothing. Or decide which tradeoff you're willing to accept
    Quote Quote  
  22. Yes, but getting clean lines for that resize mostly folks cut the live footage anyway and loose that border anyway, that is happening all the time. I was going thru this long time ago when setting auto process of backing up BD's. Problem is most of the time this logic is used, crop-resize - (and possible crop again), not realizing that that border is lost anyway and aspect ration is lost as well. For example op's case, , did he actually got exactly 440 pixels from sides and end up exactly cutting black when the only thing left was live image? Was not edge already screwed up when during authoring, not sure if edges are already exact clean so to speak.
    Quote Quote  
  23. spiritgumm,
    maybe have a play with CropResize (assuming you use Avisynth). By default it outputs a mod4 width and/or height when it's making the decisions, but you can change that. Enabling a cropping preview and Info=true will show you exactly what it's going to do.

    I upscaled an image and added borders to use as the starting point, based on your description. You probably won't be able to resize to exactly 1.37 dimensions, so the script will do a bit of extra cropping if need be to prevent aspect error. You can specify just the width or the height if you prefer and the script will take care the other.

    Source

    Image
    [Attachment 68746 - Click to enlarge]


    Cropping and resizing based on an output height of 720, as an example.
    Well, it's not actually cropped or resized in the screenshot because the preview is enabled. The script will crop an extra 1.458 pixels from the top and bottom to output 988x720, which results in an aspect ratio of 1.3722.

    CropResize(0,720, 440,0,-440,0, CPreview=2, Info=true)

    Image
    [Attachment 68747 - Click to enlarge]


    Or you can try different heights. A height of 692 will get you much closer to the original DAR and the script only has to crop half a pixel more each side to prevent aspect error. The output will be 948x692 with a DAR of 1.3699.

    CropResize(0,692, 440,0,-440,0, CPreview=2, Info=true)

    Image
    [Attachment 68748 - Click to enlarge]


    As it's so close you can always specify the original DAR for the output. Info=true will tell you the SAR to use for encoding (9601:9598 in this case). If a player pays attention to that the DAR will be correct, but if it doesn't the aspect error will be too small to matter. The correct display dimensions would be 948.3 x 692, but if a player displays it as 948 x 692 instead, you won't notice.

    CropResize(948,692, 440,0,-440,0, OutDAR=2960.0/2160.0, CPreview=2, Info=true)

    Image
    [Attachment 68749 - Click to enlarge]


    If it was me, I'd just sacrifice a pixel or two and not worry about making it anamorphic.

    CropResize(0,692, 440,0,-440,0)

    Image
    [Attachment 68750 - Click to enlarge]
    Last edited by hello_hello; 20th Jan 2023 at 07:50.
    Quote Quote  
  24. Member spiritgumm's Avatar
    Join Date
    Jan 2004
    Location
    United States
    Search Comp PM
    Thanks, this will take me alittle time to digest.
    Quote Quote  
  25. In case it's not obvious, the script uses the resizer to apply any extra non-mod or sub-pixel cropping required, so for the last example

    CropResize(0,692, 440,0,-440,0)

    would be the same as

    CropResize(948,692, 440,0,-440,0)

    and would be the same as this (using the numbers shown by Info=true which are rounded to 3 decimal places for cropping when they're displayed)

    CropResize(948,692, 440.462,0,-440.462,0)

    and the script is actually doing this

    Crop(440,0,-440,0).Spline36Resize(948,692, 0.462,0,-0.462,0)

    So it's nothing you can't do yourself, but the script makes it easier by doing the math for you, and by default it'll crop the least amount of extra picture required to prevent aspect error, whether it be from the width or the height. For the example above:

    3840 - 440 - 440 - 0.462 - 0.462 = 2959.076

    2959.076 / 2160 = 1.369942

    948 / 692 = 1.369942

    If you want to use a different resizer for CropResize other than the default of Spline36Resize, you can.

    CropResize(948,692, 440,0,-440,0, Resizer="BicubicResize")

    If you specify both an output width and height, CropResize will crop as much extra as required to prevent aspect error, so if in doubt, but you know the output width or height you want, just specify one of them.

    CropResize(0,720, 440,0,-440,0) or CropResize(1280,0, 440,0,-440,0) etc.
    Last edited by hello_hello; 20th Jan 2023 at 07:54.
    Quote Quote  



Similar Threads

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