www.geekybob.com

Just a short, simple blog for Bob to share his thoughts.

Using XSPF files with VLC to Specify Start and End Times Within a Media File

29 June 2025 • by Bob • VLC

I have a small confession to make: despite my posts about My Top Ten Favorite Rock Songs, My Favorite Guitar Solos, and My List of 20 Most Influential Albums, I am a huge fan of Classical Music. My wife and I used to be season ticket holders for the Seattle Symphony, and together we've traveled around the globe to see symphonies, concerti, operas, and other classical music performances in myriad venues. While that might seem counter-intuitive for a dyed-in-the-wool rock music fan such as myself, it really make sense when you consider that what I'm actually a fan of is superior musical skill, and you'll typically find far more musical talent in an orchestra than you'll find in the typical pop, rock, or hip-hop group. (Although Jazz is often in the same realm as Classical.)

One of the greatest recurring classical music events is the BBC Proms, which is an annual event that has been held for over a century (since 1895!). Way back in 2012, the BBC Proms featured a performance with the São Paulo Symphony Orchestra of Alberto Ginastera's suite of Four Dances from Estancia (Opus 8A), which is a series of excerpts from his larger Estancia ballet. Thankfully I had the presence of mind to download the video from YouTube, because it's no longer available. And with that in mind, here is the full-length video that I downloaded:

Sadly, this video isn't the best quality, but it was uploaded 13 years ago, and at the time creators weren't uploading a lot of high definition videos. Nevertheless, I'm glad to have this copy of the performance, because conductor Marin Alsop is an absolute joy to watch, and her interpretation of Ginastera's Estancia suite is particularly well done. (And meaning no disrespect, I prefer Aslop's interpretation over Gustavo Dudamel's version at the BBC Proms from a few years prior, but I digress.)

Of the four pieces in the Estancia suite, my favorite by far is the fourth, which is titled "Malambo." Somewhere around the 01:55 point in the fourth movement of the suite it takes off into a frenzied display of Latin American musical wizardry, and I love to listen to it when I'm writing code. Occasionally I only want to hear just the fourth movement from the suite, and it's always a little weird trying to skip ahead to find the correct place within the full-length video to start listening.

Many years ago, my primary video player was Windows Media Player, which was a built-in feature on Windows systems, and in its day it was a pretty good media player. One of its most-useful features for me was its support for its proprietary, XML-based Windows Media Metafiles, which allowed me to create custom files that specified the beginning and ending for specific sections within a larger media file. For example, the following ASX syntax allowed me to separate the video of the full Estancia suite that I shared earlier into each of the four movements:

<ASX VERSION="3.0">
  <TITLE>Ginastera - Estancia Suite</TITLE>
  <AUTHOR>Sao Paulo Symphony Orchestra</AUTHOR>
  <COPYRIGHT>BBC Proms</COPYRIGHT>
  <ENTRY>
    <TITLE>Estancia Suite - The Land Workers</TITLE>
    <REF HREF="BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4" />
    <DURATION VALUE="00:03:10.0" />
  </ENTRY>
  <ENTRY>
    <TITLE>Estancia Suite - Wheat Dance</TITLE>
    <REF HREF="BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4" />
    <STARTTIME VALUE="00:03:10.0" />
    <DURATION VALUE="00:03:02.0" />
  </ENTRY>
  <ENTRY>
    <TITLE>Estancia Suite - The Cattle Men</TITLE>
    <REF HREF="BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4" />
    <STARTTIME VALUE="00:06:12.0" />
    <DURATION VALUE="00:01:53.0" />
  </ENTRY>
  <ENTRY>
    <TITLE>Estancia Suite - Malambo</TITLE>
    <REF HREF="BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4" />
    <STARTTIME VALUE="00:08:05.0" />
  </ENTRY>
</ASX>

However, the syntax for Windows Media Metafiles is considerably limited. If you look through the Windows Media Metafile Elements Reference, you'll notice that there aren't a lot of options. Of particular note in my preceding ASX example was that I could only specify the start time and duration for each section, rather than the start time and end time, which was preferable (by far).

Over time, I ceased using Windows Media Player in favor of the far superior VLC Media Player (otherwise known as the VideoLAN Client, or "VLC" for short). Among VLC's many improvments over Windows Media Player is its support for a different XML-based syntax, the XML Shareable Playlist Format (or "XSPF" for short, which is pronounced "spiff"). XSPF supports a far greater number of elements than Windows Media Metafiles, and through a series of VideoLAN's extensions it supports an even greater number of options that are specific to VLC.

Before I continue with some examples, I should share the reference links that I used when creating XSPF files for VLC:

URL Description
http://wiki.videolan.org/XSPF Provides a simple introduction to VLC and the XSPF format.
http://www.xspf.org/spec Defines the full specification for the XSPF format.
http://wiki.videolan.org/VLC_command-line_help Provides a full list of all the VLC command line options, which can be specified as XSPF options.

I'll spare you the tales of trials and errors that I went through before arriving at the following XSPF example, which provided the same level of functionality that I had with the ASX sample that I provided earlier, albeit with some improvements that I will describe in a moment:

<?xml version="1.0" encoding="UTF-8"?>
<playlist xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/" version="1">
  <title>Ginastera - Estancia Suite</title>
  <creator>Sao Paulo Symphony Orchestra</creator>
  <license>BBC Proms</license>
  <trackList>
    <track>
      <title>Estancia Suite - The Land Workers</title>
      <location>BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4</location>
      <extension application="http://www.videolan.org/vlc/playlist/0">
        <vlc:option>start-time=0</vlc:option>
        <vlc:option>stop-time=191</vlc:option>
      </extension>
    </track>
    <track>
      <title>Estancia Suite - Wheat Dance</title>
      <location>BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4</location>
      <extension application="http://www.videolan.org/vlc/playlist/0">
        <vlc:option>start-time=191</vlc:option>
        <vlc:option>stop-time=373</vlc:option>
      </extension>
    </track>
    <track>
      <title>Estancia Suite - The Cattle Men</title>
      <location>BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4</location>
      <extension application="http://www.videolan.org/vlc/playlist/0">
        <vlc:option>start-time=373</vlc:option>
        <vlc:option>stop-time=486</vlc:option>
      </extension>
    </track>
    <track>
      <title>Estancia Suite - Malambo</title>
      <location>BBC-Proms-Ginastera-Estancia-Suite-Sao-Paulo-Symphony-Orchestra.mp4</location>
      <extension application="http://www.videolan.org/vlc/playlist/0">
        <vlc:option>start-time=486</vlc:option>
      </extension>
    </track>
  </trackList>
</playlist>

As you can see, instead of the <STARTTIME> and <DURATION> elements from the ASX file, the XSPF file has <vlc:option>start-time</vlc:option> and <vlc:option>stop-time</vlc:option> elements that are defined within an <extension> element that is specific to VLC. The values for the new entries are offset in seconds from the start of the file, and the stop time is far easier to compute than the duration from the ASX file.

You can download this example XSPF file by clicking here.

One last note is that the "start-time" and "stop-time" options are from the VLC command-line help URL that I listed earlier. In short, the many options that can be specified on VLC's command line can be specified in <vlc:option> elements, which adds an enormous amount of flexibility when creating XSPF files. For example, instead of specifying the "stop-time" as I did in my example, you could specify the "run-time", which would allow you to specify the number of seconds for playback for a track rather than the offset in seconds from the beginning of the larger media file as I had done. There are lots of options to choose from, but they're outside the scope of this blog.


FOOTNOTE: I should mention that I first learned of Alberto Ginastera while listening to WRR FM in Dallas, TX, which is one of my favorite classical music stations on the planet. WRR plays a wide array of music from hundreds of composers - both classical and contemporary - from across the globe. I much prefer WRR over our local KUAT FM here in Tucson, AZ, which is a terrible classical music station that routinely slogs its way through dozens of utterly forgettable pieces of musical tripe that no one cares to listen to. KUAT FM seems to focus on broadcasting bizarre pieces of auditory garbage, which quite often feature long passages of discordant cacophony that scare my grandchildren. So if your goal is to hate classical music as a genre, then KUAT FM should be your "go to" station. But if you love classical music, then WRR FM is your best bet.


Tags: VLC