11

I need to find the largest video files, because my videos takes a lot of space

enter image description here

but I dont know how to do this:

enter image description here

It seems to not to be there any option for filtering by size

1
  • This won't really solve your problem, so I'm not posting this as an answer, but you are right: Photos.app lacks this feature (and many others that would be needed to make it a proper photo database). Since your images are stored in a library-type database which has different file names in it than you'd see in your collection , you can't even do what you need using Terminal or Finder. Suggestion: Go by intuition now (drop longest / highest quality videos first) and switch to a better tool.
    – jstarek
    Sep 29, 2020 at 12:06

9 Answers 9

7

Here's a crude JXA script, that sorts items in a given album by size.

Using it is a bit cumbersome.

First, prepare your Photos library:

  • Create an album named “Input” at the root of your library
  • Create an album named “Input sorted” also at the root
  • In the first album, add the items you want sorted. In your case, that'd be all your videos.
  • In the second album, add two items, any items. Within the album, reorder the items, by dragging the second one before the first. This strange dance will have the effect of disabling Photo's auto-sorting of this album. You can then remove these items from the album.

You can now run the script:

  • Copy-paste the script below in a new document in Script Editor.app

  • Switch the document to JavaScript using the dropdown in the toolbar: the toolbar sits near the top of the window, below the title bar

    (if the toolbar isn't visible, toggle it with View > Show Toolbar)

  • Click the Run button in the toolbar.

The script:

(function() {
    // Config
    const albumToSort = "Input";
    const sortCriteria = "size";

    // Functions
    function toRealArray(automationArray) {
        let result = [];
    
        for (let i = 0; i < automationArray.length; i++) {
            result.push(automationArray[i]);
        }
    
        return result;
    }

    // Initialize
    let photosApp = Application('Photos');
    let app = Application.currentApplication();
    app.includeStandardAdditions = true;

    // Get album
    const sourceAlbum = photosApp.albums.byName(albumToSort);

    // Create destination album
    const destinationAlbumName = sourceAlbum.name() + " sorted";
    const destinationAlbum = photosApp.albums.byName(destinationAlbumName);

    // Get and sort items
    const items = toRealArray(sourceAlbum.mediaItems());
    items.sort((a, b) => 
        a[sortCriteria]() - b[sortCriteria]()
    );

    // Add items to destination, in order
    items.forEach(item =>
        photosApp.add([item], {to: destinationAlbum})
    );

    // Show completion notification
    app.displayNotification("Album has been sorted.", {
        withTitle: "Sort album"
    });
})();
3
  • 1
    Thanks, the script takes several minutes but does a great job!
    – Jurgenfd
    Mar 20, 2022 at 14:48
  • @Cykelero Nice script that works well. The only issue is that it can't be run a second time as the photosApp variable already exists and the script reports the error message: "Error: SyntaxError: Can't create duplicate variable: 'photosApp'". Is there a way to initialise the variable, so that the script can be run more than once? Nov 8, 2022 at 1:14
  • 1
    @AlexIxeras Ah, thanks for bringing that up! It's a quirk in Script Editor. To re-run the script, you must first compile it (hammer button in the toolbar). I've also updated the source in my post; the new version can be re-run without needing to recompile every time.
    – Cykelero
    Nov 11, 2022 at 9:54
5

As you surmised and @jstarek noted in their comment, the Photos app does not have a simple feature to sort by size. So there’s no easy way to answer your question, but here’s what I would do in your case.

The images are kept in a database with an underlying file structure that uses program generated unique names for the files. But, with a bit of work, it is possible to see the files in Finder, sort by size and correlate them to the photos app to delete them. The images are contained in a “package” file usually named “Photos Library.photoslibrary” in your Pictures folder. To find it, open the Photos app and check under Photos->Preferences for the Library location and click “Show in Finder”. Now control-click on the file and select “Show Package Contents” from the pop-up menu. The package is really just a folder with subfolders as usual. Open the “originals” folder and you will see a list of subfolders with names like 0, 1, 2, etc. - these contain the image files. Set finder to view by columns, open one of the numbered subfolders and click the Size column heading to sort by file size. The files all have unique IDs for names, but you can still double-click these files to open them with their default viewer and play the video.

enter image description here

The Photos app keeps a thumbnail image for each of these with a link to the file in its database. Now you have two choices: go back to the Photos app and browse for the video that you found and delete it, or keep the Photos app closed and simply move the file to the trash. The first way is more work, but safe since you won’t be temporarily corrupting the library. If you do the latter, the Photos app will still have the thumbnail image, but the link to the original file will be broken when you select the thumbnail. You can then delete the thumbnail from Photos.

So, it’s a bit of work and might be a little scary, but maybe you’ll find it useful.

5

Here is a SQL query you can use on the Mac OS Photos database to identify the largest things in the library and then go in and delete them through the App's UI.

I am purposefully leaving this answer not as a "DIY step-by-step instructions" because you should not be tinkering around with the Photos' SQLite database if you don't know what you're doing.

SELECT ZORIGINALFILENAME, ZDATALENGTH, ZASSET.ZTRASHEDSTATE  FROM ZADDITIONALASSETATTRIBUTES JOIN ZASSET ON ZADDITIONALASSETATTRIBUTES.Z_PK = ZASSET.ZADDITIONALATTRIBUTES JOIN ZINTERNALRESOURCE ON ZINTERNALRESOURCE.ZASSET = ZASSET.Z_PK WHERE ZASSET.ZTRASHEDSTATE = 0 ORDER BY ZDATALENGTH DESC LIMIT 100
2
  • Brilliant, better answer than I'd hoped for. I amended the select to show mb (photos uses 10^3, not 2^10, so I did too) like: round(cast(ZDATALENGTH as real) / 1000 / 1000) mb. Then realized the filenames were repeating (thumbnails?) so wrapped this in a group by: select count(*), fn, group_concat(mb) from (…) group by 2 order by mb desc. Wanted to search the photos app file by file adding to an album.
    – djeikyb
    Feb 8, 2023 at 7:36
  • Shame on Apple for this being the way to find out which videos are filling up your iCloud space that can’t be expanded beyond 4TB. 😑 Mar 5, 2023 at 15:08
2

Using bash scripting you can at least find them fast. Below is an example to list the ten largest movies from your library.

cd ~/Pictures/Photos\ Library.photoslibrary/originals
find . -name '*.mov' -print0 | xargs -0 ls -l | sort -nr -k 5 | head
2

It seems not mentioned, there is a straightforward approach. Open the "Image Capture" after connect your iPhone to mac, then you would see enter image description here

You can sort by file kind and size whatever

1
  • 1
    Note that this only works if all photos are already download on your iPhone (i.e. if "Download and Keep Originals" is enabled in your device settings.
    – Blencer
    Feb 4 at 1:59
0

You can correlate the date in the directory with the date in Photos to find the biggest video. I'm going through this exercise to compress the videos via handbrake.

0

Based on @Cykelero answer which doesn't work for me (items are still sorted in alphabetical order) - here's one that filters anything over 1GB:

(function() {
    // Config
    const albumToSort = "Input";
    const sortCriteria = "size";

    // Functions
    function toRealArray(automationArray) {
        let result = [];

        for (let i = 0; i < automationArray.length; i++) {
            result.push(automationArray[i]);
        }

        return result;
    }

    // Initialize
    let photosApp = Application('Photos');
    let app = Application.currentApplication();
    app.includeStandardAdditions = true;

    // Get album
    const sourceAlbum = photosApp.albums.byName(albumToSort);

    // Create destination album
    const destinationAlbumName = sourceAlbum.name() + " sorted";
    const destinationAlbum = photosApp.albums.byName(destinationAlbumName);

    // Get and sort items
    let items = toRealArray(sourceAlbum.mediaItems());

    //filter by size
    items = items.filter( i => i.size() > 1000000000)

    // Add items to destination, in order
    items.forEach(item =>
        photosApp.add([item], {to: destinationAlbum})
    );

    // Show completion notification
    app.displayNotification("Album has been sorted.", {
        withTitle: "Sort album"
    });
})();

0

There's a sweet app called PowerPhotos that accomplishes exactly what you're trying to do and more. It's a paid app but sorting by size and other things can be done in the free trial. Hope this helps the people that come along here :)

Screenshot of the app PowerPhotos showing the feature sorting by size

-2

Here's another way:

plug in an external disk or storage.

Create a folder on it.

Open Photos and select all the videos.

Drag them to the new folder.

Wait a LONG time for the export to complete.

Sort the new folder by size.

OR, if you're happy with keeping them there, go back to Photos and delete them. That will save more space than is in the new folder, because Photos creates a lot of supporting files for its contents. (Actually the space is not reclaimed until you also clear out the "recently deleted" collection.)

If you don't get a notification when the export completes, you can compare the number of items selected in Photos to the number of items in the new folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .