How to Only Play the First N-Seconds of Each Track in a Playlist With VLC
Background
There’s a particular YouTube chef who uses background music (BGM) for his videos. This BGM sounds very familiar to me and I could swear that I heard it in a JRPG before but I couldn’t place it. He listed the BGM credits and I found a potential Japanese website that was the source of BGM for many blogger/streamer/tubers. I was able to browse around the site and listen to various samples, but it was too slow attempting to go through them one by one. I ended up writing a PowerShell script to read through all the pages and download the mp3s. This will be the subject of another post.
I had all the mp3s, but it was a combined 19 hours long and more than a gigabyte in size! Ain’t nobody have time for that! In order to speed things up I only really needed to hear the first few seconds of each song in order to tell whether it was the one I was looking for.
My favorite media player for both video and audio is VLC. It’s a no frills media player that works with almost any format thrown at it. It just works and it’s not bloated. Can I run VLC from the command line in order to achieve what I want? It turns out, yes!
Playing the First Few Seconds of a Playlist Item in Windows
From Command Prompt
The command will look something like this where you replace <path/toplaylist.xspf> with the path to your playlist. If there are spaces you will want to enclose in quotes. Replace 10 with the number of seconds you wish to play the track for. The “start” command will execute vlc. (Obviously VLC needs to be installed first)
start vlc --playlist-autostart <path/to/playlist.xspf> --run-time=10
Here’s an example where where I point VLC to my All_Combined.xspf playlist and set the runtime to 5.
start vlc --playlist-autostart "C:\Users\Khaaaaaaaan\Music\Kanzaki\All_Combined.xspf" --run-time=5
From PowerShell or Windows Terminal
If you use the new Windows Terminal or a Powershell prompt, you will need to modify the command line as below. Start-process is used instead of start, you need to specify the filepath argument with the value VLC, and you need to enclose your commandline arguments in quotes. If you are using quotes inside the argument list, you will need to escape those quotes. Powershell uses the backtick “`” to do so.
start-process -FilePath "vlc" -ArgumentList "--playlist-autostart `"C:\Users\Khaaaaaaaan
n\Music\Kanzaki\All_Combined.xspf`" --run-time=5"
Playing the First Few Seconds of a Playlist Item in *nix
It’s similar and even simpler to do this via linux.
vlc --playlist-autostart <path/to/playlist.xspf> --run-time=10
References
https://wiki.videolan.org/Documentation:Command_line/#Playlist_options
https://askubuntu.com/questions/997691/how-to-play-first-n-seconds-of-each-file-from-a-playlist