13

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
    Commented Sep 29, 2020 at 12:06

10 Answers 10

7

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.

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"
    });
})();
4
  • 1
    Thanks, the script takes several minutes but does a great job!
    – Jurgenfd
    Commented 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? Commented 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
    Commented Nov 11, 2022 at 9:54
  • 1
    For anyone else getting strange results with this script: in my case, files more than about 2.2GB are returning negative size values. This meant my 'sorted' album had the biggest stuff first, followed by everything else in ascending order. The better solution IMO is to use PowerPhotos which sorts correctly without scripts (thanks @SpaceJosh)
    – Dylan Hand
    Commented Aug 5 at 13:08
7

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
    Commented 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. 😑 Commented Mar 5, 2023 at 15:08
3

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

2
  • 2
    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
    Commented Feb 4 at 1:59
  • Will that sorted view let you Delete [everywhere]?
    – cellepo
    Commented Jun 14 at 2:15
2

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 :)

Note that to enable the size column, you must right-click the top bar and make sure it's selected.

Screenshot of the app PowerPhotos showing the feature sorting by size

1

You can use this script found on the apple forums made by léonie that works perfectly.

Create an album with videos, select all the videos, run the script and set an appropriate threshold. It will create two albums one smaller than the input and one larger than the input.

Here's the copied source code in case it goes down in the original source

-- ✄ ✄  --  snip -- copy from here
(* How to use this script:

This script will split the selection into two albums -
- one album with pictures or videos larger than the given file size threshold
- one album with pictures  or videos smaller  than the given file size threshold

Open this script in Script Editor. Launch Photos.
Select the photos and videos you want to distribute between the albums.

When all all photo are selected, press the "Run" button in Script Editor.

Author: léonie
*)

--the file size threshold in kB
set defaultFileSizeThreshold to 10240 -- 10 MB,  change this to the file  size threshold  you want for a photo to be counted as small

set dialogResult to display dialog ¬
  "Enter the file size threshold for small photos or videos in kB : " buttons {"Cancel", "OK"} ¬

default answer (defaultFileSizeThreshold as text)
set FileSizeThresholdkB to (text returned of dialogResult) as integer-- file size in kB
set FileSizeThreshold to FileSizeThresholdkB * 1024 -- file size in Byte


set smallAlbumName to "smallerThan" & FileSizeThresholdkB-- the album to collect the small photos

set largeAlbumName to "largerThan" & FileSizeThresholdkB-- the album to collect the larger photos

tell application "Photos"

activate

-- Ensure that the albums do exist
  try
  set imageSel to (get selection)
  on error errTexttwonumbererrNumtwo
  display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo
  end try

-- return the size of the first item of imageSel

  try
  if not (exists container smallAlbumName) then

makenewalbumnamedsmallAlbumName
  end if
  set theSmallAlbum to containersmallAlbumName

  if not (exists container largeAlbumName) then

makenewalbumnamedlargeAlbumName
  end if
  set theLargeAlbum to containerlargeAlbumName

  if not (exists container "SkippedPhotos") then
  make new album named "SkippedPhotos"
  end if
  set theSkippedAlbum to container "SkippedPhotos"


  on error errTexttwonumbererrNumtwo
  display dialog "Cannot open albums: " & errNumtwo & return & errTexttwo
  end try


-- process the selected photos from the All Photos album

  set smallPhotos to {} -- the list of small photos
  set largePhotos to {} -- the list of larger photos
  set skippedPhotos to {} -- the list of skipped  photos



-- check, if the album or the selected photos do contain images

  if imageSel is {} then
  error "Please select some images."
  else
  repeat with im in imageSel
  try

  tell im--get the file size
  set s to its size
  end tell
  on error errText number errNum
  display dialog "Error: " & errNum & return & errText & "Trying again"
  try
  delay 2
  tell im
  set s to its size

  end tell
  on error errTexttwonumbererrNumtwo
  display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
  end try

  end try
  set noSize to (s is missing value)
  if noSize then
  set skippedPhotos to {im} & skippedPhotos
  else
  if (s ≤ FileSizeThreshold) then
  set smallPhotos to {im} & smallPhotos
  else
  set largePhotos to {im} & largePhotos

  end if
  end if

  end repeat


addsmallPhotostotheSmallAlbum

addlargePhotostotheLargeAlbum

addskippedPhotostotheSkippedAlbum

  return "small photos: " & (length of smallPhotos) & ", larger photos : " & (length of largePhotos) & ", skipped: " & (length of skippedPhotos)

  end if

end tell
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"
    });
})();

-1

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.

1
  • This is a decent Answer; I don't understand why it has been downvoted?
    – cellepo
    Commented Jun 14 at 1:30

You must log in to answer this question.

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