Skip to content

Instantly share code, notes, and snippets.

@Pagliacii
Created April 28, 2020 08:51
Show Gist options
  • Save Pagliacii/e6fd3c04908e694392abb5c4c61d3e66 to your computer and use it in GitHub Desktop.
Save Pagliacii/e6fd3c04908e694392abb5c4c61d3e66 to your computer and use it in GitHub Desktop.
Use gnash and ffmpeg to convert *.swf to *.mp4
#!/bin/bash
trap cleanup EXIT
set -eux
set -o pipefail
SWFFILE="$1"
MP4FILE="${SWFFILE%.*}.mp4"
RAWFILE=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).raw
WAVFILE=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).wav
cleanup() {
rm -f $RAWFILE $WAVFILE
}
# create raw-dump
GNASHCMD="dump-gnash -1 -D $RAWFILE@30 -A $WAVFILE $SWFFILE"
echo -e Extracting raw file and wav file...
OUTPUT="$(exec $GNASHCMD)"
# extract parameters
WIDTH="$(echo $OUTPUT | grep -o 'WIDTH=[^, }]*' | sed 's/^.*=//')"
HEIGHT="$(echo $OUTPUT | grep -o 'HEIGHT=[^, }]*' | sed 's/^.*=//')"
FPS="$(echo $OUTPUT | grep -o 'FPS_ACTUAL=[^, }]*' | sed 's/^.*=//')"
# combine audio and video to mp4 file with ffmpeg
echo Please waiting...
ffmpeg -i $WAVFILE \
-f rawvideo \
-pix_fmt rgb32 \
-s:v ${WIDTH}x${HEIGHT} \
-r $FPS \
-i $RAWFILE \
-c:v libx264 \
-r $FPS \
-b:a 16k \
$MP4FILE
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment