Skip to content

Instantly share code, notes, and snippets.

@bmcbm
Last active November 30, 2024 15:00
Show Gist options
  • Save bmcbm/4a0afb6e49743c40d8ed4a34316059ef to your computer and use it in GitHub Desktop.
Save bmcbm/4a0afb6e49743c40d8ed4a34316059ef to your computer and use it in GitHub Desktop.
Scale video and images to save size on phone
So I was running out of space on my cell phone a Google Pixel 6a with 128 GB og storage.
Years of photos and videoes in particular was taking up almost all storage.
So either I could get a new phone with more storage or reduce the size of the files
(since I dont want to store my stuff on Google Cloud storage)
I went for the latter since the phone is working fine and to my liking.
To resize the images I use GNU parallel to run Imagemagick convert to reduce resolution
to 1080p (I do not convert the panoramas)
$ ls *jpg | grep -v PANO | parallel -j 16 convert {} -resize 1920x1920 ../scaled/{.}.scaled.jpg
For the videos I came across a nice tool called Shrinkwrap, that seems to do the trick for videos:
https://coderunner.io/shrink-videos-with-ffmpeg-and-preserve-metadata/
https://github.com/bennetimo/shrinkwrap/tree/master
I downloaded all videos from my phone to my Linux computer and ran Shrinkwrap to reduce
the videos to 720p which is fine for the phone screen.
$ docker run -v .:/files bennetimo/shrinkwrap --input-extension mp4 --ffmpeg-opts vf="scale=-1:720" --transcode-suffix ".720p" /files
And it worked fine for the old videos that was iomported from my prior phones.
But the video files that was shot with the Pixel Phone was not playable on my Linux box
after conversion. The vidoe player also complained about a missing codec and took
forever to start playing prior to conversion. Turns out that the Pixel phone encodes
the videos in HVEC format and uses a feature called Top Shot as well.
Luckily ffmpeg can transcode HVEC into standard h.264. Shrinklwrap also uses exiftool to
restore metadata and set original file creation dates on the transcoded files.
So to transcode the videos for storage on my phone I run this:
$ for i in $(ls PXL_*.mp4) ; do ffmpeg -i $i -map_metadata 0 -c:v libx264 -crf 23 -c:a copy -preset fast ${i%%.*}.h264.mp4 ; exiftool -tagsFromFile $i -extractEmbedded -all:all -FileModifyDate -overwrite_original ${i%%.*}.h264.mp4 ; done
This reduces the storage requirements on the phone about 85% without noticable
loss of quality on the phone screen.
I also transcode the HVEC video to h.264 for use on my home NAS. I just keep
the original resolution but increased compression a bit.
This also saves significant storage:
$ for i in $(ls PXL_*.mp4) ; do ffmpeg -i $i -map_metadata 0 -c:v libx264 -crf 23 -c:a copy -preset fast ${i%%.*}.h264.mp4 ; exiftool -tagsFromFile $i -extractEmbedded -all:all -FileModifyDate -overwrite_original ${i%%.*}.h264.mp4 ; done
#ffmpeg #shrinkwrap #GooglePixel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment