Duration on thumbnails on my desktop

I was looking at a folder full of videos, trying to decide which one to watch. The title and the thumbnail help me decide, but a third criteria popped up in my head - how long is the video?
So I was annoyed that this piece of information wasn't readily available.
But why not do something about that?
On my computer it turns out the thumbnails that the file manager (Nemo) shows are generated by totem-video-thumbnailer
, via a configuration file in /usr/share/thumbnailers
, so I set out to make a wrapper, that would put the duration into the thumbnail.
Here is the script:
#!/bin/bash
# video-duration-thumbnailer - wrapper for totem-video-thumbnailer
#
# Adds duration to the thumbnail.
#
# Put this script somewhere, edit
# /usr/share/thumbnailers/totem.thumbnailer changing
# "Exec=/usr/bin/totem-video-thumbnailer -s %s %u %o" to
# 'Exec=YOURPATH/video-duration-thumbnailer -s %s %u %o'
#
# Thanks to Klaus for the Python snippet for url decoding.
#
# Copyright (C) 2025. Under GPLv2. By Adam Sjøgren <asjo@koldfront.dk>
INPUT=$3
OUTPUT=$4
# Run the original thumbnailer:
/usr/bin/totem-video-thumbnailer "$@"
# If possible, overlay duration:
if echo "$INPUT" | grep --quiet 'file://'; then
FILE=$(echo "$INPUT" | python -c 'import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read().strip()))')
DURATION=$(ffprobe -i "$FILE" -show_entries format=duration -v quiet -of csv="p=0" -sexagesimal | cut -d. -f 1)
TMPFILE=$(mktemp -t vtt-XXXXXX)
convert "$OUTPUT" -gravity SouthEast -font DejaVu-Sans-Condensed -pointsize 24 -fill white -stroke gray -annotate +2+2 "$DURATION" "$TMPFILE"
mv "$TMPFILE" "$OUTPUT"
fi
And now when I look at a folder of videos the duration is shown (after pressing Ctrl-R to update the thumbnails)!
Add comment
How to in excruciating detail…
To avoid spam many websites make you fill out a CAPTCHA, or log in via an account at a corporation such as Twitter, Facebook, Google or even Microsoft GitHub.
I have chosen to use a more old school method of spam prevention.
To post a comment here, you need to:
- Configure a newsreader¹ to connect to the server
- Open the newsgroup called
¹ Such as Thunderbird, Pan, slrn, tin or Gnus (part of Emacs).koldfront.dk
on port1119
using nntps (nntp over TLS).lantern.koldfront
and post a follow up to the article.Or, you can fill in this form: