Search & Edit

Michael Murtaugh wrote a script which allows you to edit video sequences based on keywords in a subtitle file. The script uses videogrep, searches for words in the subtitle file, creates an Edit Decision List and plays the file in Mplayer. This way you can search through video files and make content accessible through comments, summaries or transcriptions in a subtitle file.

Here are some files you can use as an example. Download these and save them in the same folder on your hard drive.
* Subtitle file: barcelona.srt
* Video file: barcelona.avi (low res: 2.6 mb) (high res: 10 mb)
* The script: videogrep_edl
Have Mplayer installed.

You need to do a couple of things to get the script to work:
(1) You need a subtitle file in the ‘.sub’ format. Luckily though Mplayer will convert any subtitle file to any other subtitle format, so if you have one, you can make the necessary other; so for instance:

$ mplayer -sub ORIGINALSUB.srt -dumpmicrodvdsub ORIGINALMOVIE.avi

(where CAPS are the parts to fill in. In case of the example files; barcelona.srt and barcelona.avi
This will make a new file automatically called dumpsub.txt, so then you want to rename it to match the movie name (minus .avi and plus .sub), i.e.:

$ mv dumpsub.txt ORIGINALMOVIE.sub

(2) You need to edit the “framerate” variable in the script to match the movies frame rate — in my example it’s at 30 frames per second — but the way the script works now (it could of course be better!) it must match the movie. You can see the frame rate when you look at the video tab in the properties of the videofile. Open the script in an editor and set framerate=30

(3) To run the program you type:

$ videogrep_edl ORIGINALMOVIE.avi '\b(WORD)\b'

As long as the subtitle file is in the same directory (and has the same name) it should work.

The script uses Mplayer’s “edl” functionality which in fact, is designed to skip/censor certain portions of a movie (so in fact this script inverts the times to skip everything except the matching time codes, using “egrep” to do the searching so you could use it with “extended” regular expressions like:

$ videogrep_edl barcelona.avi '\b(People|Dealer|City|Water)\b'

where the pattern here (put inside single quotes) looks for “People” or “Dealer” as single words (the \b is the very handy “word-boundary” anchor, meaning the text should appear as a free standing word as opposed to anywhere in the text)…

the script generates “videogrep.edl” which is the file that it uses (via mplayer’s -edl option) at the end… the nice thing here is that the program stays fullscreen for the whole playout and a single press of Esc cancels the whole thing.

In the example subtitle file, the following words are included. Use one or several in your command to see the script in action:

People Barcelona Fingers Hands Bass Airguitar Gloves Advertising Birds Cage Dealer Street Singing Trees Taxi City Ride Cigars Restaurant Sky Houses Panorama Boats Trucks Fire Water TV Media Screen Busy Market

Posted on: Tuesday, September 12, 2006 by: in category: Annotation tools, Manuals