HOW FILES ARE CATEGORIZED ON ANDROID?
Let's simplify things. You tap a text document, it opens with text editor. You click on a picture, it opens with image viewer. Whether to open a file with a document viewer, or a photo editor, or a media player, or something else, is determined by MIME type, or Media Type, or in simple words File Type.
The simple and easy way to determine file type is the file extension; we know a file ending with .mp4
is a video file. That's how Windows set preferred program to open a file. *NIX operating systems usually rely on file's magic to determine mime type. That's what file command does. Android's toybox file doesn't seem to have a large collection of magics, so the primary source to guess file types on Android is file extensions.
That said, the size of Videos that appear under Internal Storage usage details, is the total size of files which have mime type video/*, based on extensions vs file category mapping used by Settings app (1, 2, 3, 4, 5). If you think the size shown is inaccurate, you can cross check yourself. Use some app or simply a terminal emulator like Termux to find all video files:
~$ find /sdcard/ -type f | grep -iE '\.wrf$|\.movie$|\.wvx$|\.wmx$|\.wm$|\.asx$|\.mng$|\.lsx$|\.lsf$|\.mxu$|\.qt$|\.vob$|\.mpe$|\.fli$|\.dv$|\.dif$|\.dl$|\.mpeg$|\.mpg$|\.mp4$|\.m4v$|\.mov$|\.3gp$|\.3gpp$|\.3g2$|\.3gpp2$|\.mkv$|\.webm$|\.ts$|\.avi$|\.wmv$|\.asf$'
* If using Termux, grant Storage permission to allow /sdcard
access.
This will find every file on you storage which is considered video by OS, though one might not be a video in actual and just disguising itself with a video file extension.
To find out individual file sizes and total size, extend the command a bit:
~$ find /sdcard/ -type f | grep -iE '\.wrf$|\.movie$|\.wvx$|\.wmx$|\.wm$|\.asx$|\.mng$|\.lsx$|\.lsf$|\.mxu$|\.qt$|\.vob$|\.mpe$|\.fli$|\.dv$|\.dif$|\.dl$|\.mpeg$|\.mpg$|\.mp4$|\.m4v$|\.mov$|\.3gp$|\.3gpp$|\.3g2$|\.3gpp2$|\.mkv$|\.webm$|\.ts$|\.avi$|\.wmv$|\.asf$' | xargs -I {} du -b '{}' | sort -n | awk '{sum += $1} {print} END {print sum}'
* All commands are very basic, usually part of busybox distributions.
This will show the individual and total file size in bytes. Convert that to MBs or GBs, and that should match the size appearing in Settings. In the same way, you can calculate size of other file types like audio
and images
.
The same categorized files can be viewed in the left menu of Android's default Files
app (at least on Pie). However there could be possible differences. For instance, a file with .mpe
extension will reflect in videos size shown in Settings, but won't appear under videos of Files
app or other gallery apps. It's because the file extension vs mime type mapping which media scanner uses doesn't include .mpe
extension in video category. In addition to file extension, media scanner takes further steps to segregate files for default apps and preferred activities.
Another way to get total size of video files is dumpsys
diskstats
service which reads from file /data/system/diskstats_cache.json
. DiskStatsLogService runs once every 24 hours when device is idle and charging, and the extensions vs file category mapping it relies on is similar to the one used by Settings. So the sizes should be same when diskstats_cache
file is updated:
~$ dumpsys diskstats | grep Videos
RELATED: How disk space is used on Android device?