Skip to content
Snippets Groups Projects
Commit 2c45a9c8 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

#10: Write Bash+ffmpeg script to extract MP3 from SWF

parent dc14f1d5
Branches
No related tags found
No related merge requests found
#!/usr/bin/env bash
# Extract all MP3 (MPEG) audio streams from a Flash SWF file
# Dependencies: ffmpeg, ffprobe, jq
if [ -z "$1" ]; then
echo "Usage: $0 <file>"
exit 1
fi
input=$1
# List all streams in the file as JSON, filter all with codec "mp3" and print their index
streams="$(ffprobe -show_streams $input -of json 2>/dev/null | jq -r '.streams | map(select(.codec_name == "mp3")) | map(.index) | join("\n")')"
echo "$input: found $(wc -l <<< $streams) MP3 streams: $streams"
# Assemble ffmpeg command line by adding '-map' argument and outfile for each stream
cmd="ffmpeg -i $input -vn -c:a copy"
outputs=""
i=0
while read -r stream_id ; do
cmd="$cmd -map 0:$stream_id $input.$i.mp3"
i=$((i+1))
done <<< "$streams"
# Run ffmpeg
echo "Executing: '$cmd'"
$cmd
echo "Extracted $i MP3 files from $input."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment