I need to find the largest video files, because my videos takes a lot of space
but I dont know how to do this:
It seems to not to be there any option for filtering by size
I need to find the largest video files, because my videos takes a lot of space
but I dont know how to do this:
It seems to not to be there any option for filtering by size
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.
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.
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:
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:
(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"
});
})();
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)
Commented
Aug 5 at 13:08
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
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.
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
It seems not mentioned, there is a straightforward approach. Open the "Image Capture" after connect your iPhone to mac, then you would see
You can sort by file kind and size whatever
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.
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
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.
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"
});
})();
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.