Triaging Videos by Adding Captions to Mplayer (Shallow Thoughts)

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Fri, 04 Aug 2023

Triaging Videos by Adding Captions to Mplayer

I've recently hit a wall that I'd been avoiding: how to triage a bunch of new videos and decide which ones are worth keeping.

For still photos, I do that with my Pho program if I just want to make yes or no decisions, or maybe mark two or three categories. When the time comes for real tagging — which images have sunsets, which have bicycles, which have coyotes and so on — I use my MetaPho. I take a lot of photos, so efficient triaging and tagging is important to me.

But what about videos? In the past, mostly either I decided the videos weren't good enough to be worth the difficulty of figuring out which ones to keep and so deleted them all; or else I kept them all, with the result that I have gigabytes of mediocre videos taking up way too much disk space and backup time, which I'll probably never go back to since they aren't tagged at all.

But lately, I've been accumulating some videos I'd like to keep, because

And it's really been bugging me that there's no good way to triage all these videos. So I made a way. Actually two ways.

Mplayer with a Caption

I tried running mplayer *.mp4 and making notes on paper like "Delete the second, third and sixth video" and "#4-6 are that neat 3-D printed plane." Then after they've all played, I have to ls *.mp4 and figure out which filenames are the second, third, fourth and so on. I couldn't take notes by filename because mplayer doesn't show the filename of the video it's playing, and vlc, which does, is more of a pain to use on a list of videos because you have to keep clicking the Next button.

So I did a little reading about mplayer. Turns out there's a way to make it display the filename (or any other text) superimposed on top of the video: use a caption file. A caption file has the extension .srt (this apparently stands for SubRip Title after a video program from Microsoft that used the format), and you can read more about the format in that Wikipedia link.

If all you want is one line to show during the entirety of the video, make a file that looks like

00:00:00,0 --> 01:00:00,0
Then use -sub to specify the caption file.

All the docs I found were a little vague on the exact syntax for -sub, especially for multiple video files, so it took a little experimentation, but eventually I had a script which I unimaginatively called

import subprocess
import os, sys

def create_subtitle_file(filename):
    filename = os.path.basename(filename)
    filebase, ext = os.path.splitext(filename)
    subfilename = "/tmp/" % filebase
    if os.path.exists(subfilename):
        return subfilename
    with open(subfilename, "w") as subfp:
        print("1\n00:00:00,0 --> 01:00:00,0\n%s" % filename, file=subfp)
    return subfilename

if __name__ == '__main__':
    args = [ "mplayer" ]
    for filename in sys.argv[1:]:

Run it with python *.mp4 (or whatever your list of videos is), and it will show all the videos in sequence with their filenames showing.

That more or less worked, and was a lot better than anything I'd tried before. Though I still had to take notes on paper, pausing mplayer with the spacebar whenever I needed to jot down a filename.

But during my research, I'd also discovered VLC's Python bindings. And I ended up using them to make a better solution ... which I'll describe in the next article: Triaging Videos Using VLC's Python Bindings.

Rant Alert

Besides, with video on Linux I've learned that it's always important to be able to do what you need in multiple ways with multiple programs, since any given video program may or may not work on any given day. (Video is a significant weak point of Linux and open source, sadly.) For instance, as I was writing this article, I ran my script intending to show a screenshot — but today is one of those days where mplayer on Debian has decided not to work at all, though vlc is working fine. A few months ago it was the opposite: vlc didn't work but mplayer did. Sigh. I've found the same with video editors: one week Shotcut is working, the next week Shotcut is broken but OpenShot works. You just have to roll with the punches sometimes, and fortunately, there are a lot of options to choose from.

Tags: ,
[ 20:23 Aug 04, 2023    More linux | permalink to this entry | ]

Comments via Disqus:

blog comments powered by Disqus