FFMPEG can, from the command line, or a batch file, grab the first n seconds of a media file, (video or audio), and can merge those splits into a single file, (converting formats if needed).
- Free, gratis & open source + :-)
- Cross platform including Windows + :-)
- Can be used to do a lot more + :-)
- If you are doing this sort of thing regularly you can put it into a batch or script file + :-)
- Because it is so powerful there are a lot of options to consider - :-(
Python + MoviePy
Since actually using FFMPEG can be troublesome due to the shear number of options I often suggest using the python library moviepy which wraps FFMPEG up into a much nicer package. Also:
- Free, gratis & open source :-)
- Cross platform including Windows :-)
- Much easier! :-)
To install python for windows
(OS-X and Linux users will most probably already have python installed):
- Go to https://www.python.org/
- Download the Windows installer
- Run the installer & make sure that "Add Python to the Path" is selected and that "install pip" is selected.
To install MoviePy (any platform):
- Open a terminal Window
pip install moviepy OS-X & Linux uses will have to prefix this with
- Wait a few seconds while pip does it's work
py -3-32 -c"from moviepy.editor import *"
The last line will get moviepy to download and install FFMPEG where it expects it to be.
An example moviepy script that will sample the first 15 seconds of all the MP3 files in the current directory would be:
import glob, os
from moviepy.editor import *
outname = "sampler.mp3" # Name to save to
tracklist = "tracklist.txt" # Would provide an ordered list of filenames
duration = 15 # Duration of each clip in seconds
filelist = open(tracklist).read().split('\n')
else: # No tracklist
filelist = glob.glob('*.mp3') # Get a list of the mp3 files
if outname in filelist: # Make sure we don't include any existing sampler
# Read the clips in
#clips = [AudioFileClip(fname).set_end(duration) for fname in filelist] # No fade out
clips = [AudioFileClip(fname).set_end(15).audio_fadeout(0.5) for fname in filelist] # Half second fade out at the end of each clip
sampler = concatenate_audioclips(clips) # Concatenate
sampler.write_audiofile(outname) # Save sampler
print('Finished %d tracks written to %s!" % (len(clips), outname))
Note that, rather than the fade out in the example above, you could interleave your tracks with one that provides a half seconds silence, or even a brief needle being dragged noise, so as to provide a separation between tracks.
If the above is typed into a file called "sampler.py" somewhere on your path, (such as the python scripts directory), you can change directory to any that has your MP3 files, or other formats with small changes to the script above in and simply type
sampler.py go generate your sampler.