Using FFmpeg alone to download .ts files listed in an .m3u8 playlist without merging them is somewhat limited. FFmpeg generally processes streams directly, which means it tends to treat input as a single entity for output. However, you can approach this task in a couple of ways, although both involve some level of manual process or the need for additional scripting.
Method 1: Manual Download
You can manually download individual .ts files if you open the .m3u8 file in a text editor and then use a tool like curl or wget for each of the segment links. This is straightforward but can be tedious for playlists with a large number of segments.
Method 2: Scripting
Alternatively, you can write a script that parses the .m3u8 playlist, extracts each .ts file URL, and then uses a command line tool like curl, wget, or even FFmpeg itself to download each file separately. Here’s a simple example of how you might do it using a bash script:
-
Create a script: download_ts_files.sh
#!/bin/bash
# Usage: ./download_ts_files.sh "http://example.com/path/playlist.m3u8"
URL="$1"
PREFIX=$(dirname "$URL")
# Fetch the playlist
curl -s "$URL" > playlist.m3u8
# Extract .ts files from the playlist
grep -o "^[^#].*\.ts" playlist.m3u8 > segments.txt
# Download each segment
mkdir -p ts_files
cd ts_files
while read -r line; do
echo "Downloading $line ..."
curl -O -s "${PREFIX}/$line"
done < ../segments.txt
echo "Download Complete!"
-
Make the script executable:
chmod +x download_ts_files.sh
-
Run the script by supplying the URL of the m3u8 file:
./download_ts_files.sh "http://example.com/path/playlist.m3u8"
This script does the following:
- Downloads the M3U8 file.
- Extracts all lines that end with
.ts assuming these are the video segments.
- Downloads each
.ts file into a folder called ts_files.
Notes:
- Ensure the script is adjusted according to your specific URL and path structures, as different servers might host playlists and segments differently.
- This script assumes all TS files are listed directly in the M3U8 file. Nested playlists would require deeper parsing and potentially recursive script adaptations.
While these methods are a bit around FFmpeg’s primary functions, using FFmpeg solely to download separate .ts segments without any form of processing or merging them isn't straightforward. FFmpeg is inherently designed to process and convert media streams rather than being used as a bulk media downloader.