VideoHelp Forum
+ Reply to Thread
Results 1 to 6 of 6
Thread
  1. Member
    Join Date
    Feb 2006
    Location
    England
    Search PM
    Hello

    I don't know if this is the right forum. I apologise if not.

    I have taken 1000s of images off my iPhone and want to see their aspect ratios. I can sort them in windows by dimension etc, but not aspect ratio. Most of them are 4:3, which is the ratio I want. I want to be able to see which ones aren't 4:3 so I can edit them. Is there a quick way of doing this and seeing aspect ratios without having to do the math for each and every one?

    Thanks

    Ani
    Jagabo, please do not reply to this post. Thank you.
    Quote Quote  
  2. You can use Python,
    you define:
    path to mediainfo
    name of directory
    searched aspect ratio
    extension for those files

    then one subdirectory will be created with media files (and those extensions) that have desired aspect ratio and other directory with rest of those files of the same extension
    Code:
    from subprocess import Popen, PIPE
    import json
    from pathlib import Path
    import shutil
    
    #https://mediaarea.net/en/MediaInfo/Download/Windows
    MEDIAINFO = r"F:\tools\MediaInfo_CLI_22.09_Windows_x64\MediaInfo.exe"
    DIRECTORY = r"F:\testing aspet ratio for images\images"
    EXTENSION = "PNG"
    SEARCHED_ASPECT_RATIO = 16/9
    
    
    generator_of_paths = Path(DIRECTORY).glob(f'*.{EXTENSION}')   #generator is a better choise as oppose to using list
    dir_searched_ar = Path(DIRECTORY) / 'searched_ar_files'
    dir_searched_ar.mkdir(parents=True, exist_ok=True) #creates that subdirectory if it does not exist
    dir_rest = Path(DIRECTORY) / 'rest_of_files'
    dir_rest.mkdir(parents=True, exist_ok=True)
    
    for path in generator_of_paths:
        cmd  = f'"{MEDIAINFO}" --Output=JSON  "{path}"'
        p = Popen(cmd, stderr=PIPE, stdout=PIPE)
        stdout, stderr = p.communicate()
        data = json.loads(stdout)  #conversion from stdout(it is json format), to python's dictionary object
    ##    print(json.dumps(data, indent=2)) #use this, it prints pretty, formatted, to orient yourself in that dictionary
        width =  data['media']['track'][1]['Width']  #[0] means general section, [1] is for file properties if image or video
        height = data['media']['track'][1]['Height']
        ar = int(width)/int(height)
        if SEARCHED_ASPECT_RATIO-0.1 < ar < SEARCHED_ASPECT_RATIO+0.1:
            shutil.copy2(path, dir_searched_ar)
        else:
            shutil.copy2(path, dir_rest)
    Image
    [Attachment 68274 - Click to enlarge]
    Last edited by _Al_; 22nd Dec 2022 at 21:25.
    Quote Quote  
  3. Put this in a batch file in a folder full of jpg images and it will create a list of all those with exactly 4:3 AR:

    Code:
    @echo off
    del 4x3.txt
    for %%F in (*.jpg) do (call :CHECK_AR "%%~nxF")
    goto :END
    
    
    :CHECK_AR
    
    "G:\Program Files\MediaInfoCLI\MediaInfo.exe" --inform=Image;%%Width%% "%~dpnx1" > "test.txt"
    set /p width= < "test.txt" 
    "G:\Program Files\MediaInfoCLI\MediaInfo.exe" --inform=Image;%%Height%% "%~dpnx1" > "test.txt"
    set /p height= < "test.txt"
    set /a arw=%width%*3
    set /a arh=%height*4
    if %arw% EQU %arh% echo "%~nx1" %width%x%height% >>4x3.txt
    EXIT /B
    
    
    :END
    
    del "test.txt"
    The output will be in a file called 4x3.txt:

    Code:
    "DSCN0059.JPG" 2048x1536 
    "P1010035.JPG" 2304x1728
    Other files in the same folder were not 4:3.

    You will need to change the path to the CLI version of MediaInfo.
    Last edited by jagabo; 22nd Dec 2022 at 20:45.
    Quote Quote  
  4. if just needing a list, as jagabo gets, using python, you can just use:
    Code:
    from subprocess import Popen, PIPE
    from pathlib import Path
    
    #https://mediaarea.net/en/MediaInfo/Download/Windows
    MEDIAINFO = r"F:\tools\MediaInfo_CLI_22.09_Windows_x64\MediaInfo.exe"
    DIRECTORY = r"F:\testing aspet ratio for images\images"
    EXTENSION = "JPG"
    SEARCHED_ASPECT_RATIO = 4/3
    
    
    generator_of_paths = Path(DIRECTORY).glob(f'*.{EXTENSION}')
    
    for path in generator_of_paths:
        w, _ = Popen(f'"{MEDIAINFO}" --inform=Image;%Width%  "{path}"', stdout=PIPE).communicate()
        h, _ = Popen(f'"{MEDIAINFO}" --inform=Image;%Height%  "{path}"', stdout=PIPE).communicate()
        w = int(w.decode())          #stdout is in bytes, needs to be decoded to string first
        h = int(h.decode())
        if SEARCHED_ASPECT_RATIO-0.1 < w/h < SEARCHED_ASPECT_RATIO+0.1:
            print(f'{w}x{h}, {path.name}')
    Last edited by _Al_; 22nd Dec 2022 at 21:28.
    Quote Quote  
  5. Member netmask56's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Search Comp PM
    XnViewMP you can check and sort by ratio
    SONY 75" Full array 200Hz LED TV, Yamaha A1070 amp, Zidoo UHD3000, BeyonWiz PVR V2 (Enigma2 clone), Chromecast, Windows 11 Professional, QNAP NAS TS851
    Quote Quote  
  6. Member
    Join Date
    Feb 2006
    Location
    England
    Search PM
    Thank you guys so much! Merry Christmas!
    Jagabo, please do not reply to this post. Thank you.
    Quote Quote  



Similar Threads

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