How to Reduce iCloud Storage by Shrinking Videos

In fact, removing unnecessary segments from 4k videos can be a more effective way of saving space.


When I view videos in the “Photos” gallery, it shows me when and where I took them.

This is a great feature that helps me reminisce my memories. However, the original 4k videos take up too much space in iCloud.

For example, even with HEVC (High Efficiency Video Coding), a 2:30 video will take up 1GB of space. My 200GB iCloud plan is almost full.

Therefore, I plan to compress the videos slightly to save some space.

But,

FFmpeg video conversion loses GPS even with metadata

Luckily, I found a solution.

Tools

  • FFmpeg
  • Exiftool

Export the original videos to a folder

A common method to export videos from “Photos” to a folder is to have “Photos” convert the videos.

Therefore, you must select all the videos you want to export and then go to:

File -> Export -> Export Unmodified Original For...

Shrink each video

The default stream for iPhones is:

#0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709)

So re-encoding with -pix_fmt yuv420p10le (10-bit) doesn’t help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ffmov() {
mkdir -p shrunk

# ffmpeg with h265
ffmpeg -i "$1" -c:v libx265 -crf 28 -c:a copy -c:s copy -tag:v hvc1 shrunk/"$1"
overwriteExif "$1"
}

overwriteExif() {

# copy Exif info from the original video to the shrunk *.mov
exiftool -tagsFromFile "$1" shrunk/"$1"
exiftool shrunk/"$1"
rm shrunk/"$1_original"
}

shrinkVideos() {
## walk through all *.mov
for f in *.mov
do
echo $f
ffmov $f
done
}

You can then copy and paste this code into the Terminal, navigate to the VideoFolder using cd VideoFolder, and then run shrinkVideos.

The shrinking process will take a long time.

On my MacBook Pro (15-inch, 2018), it takes only 0.3x longer. But in general, the videos will be reduced by 5x without too much loss of quality.

Once everything is done, the shrunken videos will be in the shrunk/ folder.

You can then compare them, delete the original videos, and import the shrunken videos.

Okay, at last I couldn’t stand the slow speed, so I used Nvidia 1080 GPU for acceleration. To learn more, visit: CUDA GPU Accelerated h264/h265/HEVC Video Encoding with Staxrip.

Next step is to tag the converted videos as hvc1, otherwise, an error will occur when importing the photos:

Invalid: The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)

So the whole step is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
ffhvc1() {
echo "$1 -> $1.mov"
ffmpeg -i "$1" -c:v copy -c:a copy -c:s copy -tag:v hvc1 "$1.mov"

echo "$1.mov -> $1"
rm "$1"; mv "$1.mov" "$1"
}

overwriteExif() {
# copy Exif info from the original video to the shrunk *.mov
exiftool -tagsFromFile "$1" shrunk/"$1"
exiftool shrunk/"$1"
rm shrunk/"$1_original"
}

shrinkVideos() {
## walk through all *.mov
for f in *.mov
do
echo "$f"
ffhvc1 "shrunk/$f"
overwriteExif "$f"
done
}

# use Staxrip to convert all videos to shrunk/
# then run `shrinkVideos`

Hope this helps you.

Translated by gpt-3.5-turbo