Convert compressed swf to mp4

skmvasu picture skmvasu · Nov 25, 2013 · Viewed 40.9k times · Source

I'm looking for a batch script to convert swf to mp4, lossless. I tried using both ffmpeg and handbrake, but apparently swf is compressed and I can't convert them this way.

ffmpeg -i input -c:v libx264 -preset ultrafast -qp 0 output.mkv

HandBrakeCLI -i source -o destination

I know I acn use a tool like xilisoft, but I've more than 3000 videos and would need to run this automatically. Is there a script/ algorithm that can help me automate this process?

Answer

jaygooby picture jaygooby · Jan 9, 2014

Get gnash:

git clone git://git.sv.gnu.org/gnash.git

You'll need a bunch of dependencies before you can build it (should be able to apt-get them all):

libsdl-dev
libboost-dev
libagg-dev

Then configure and build the gnash video dumper:

cd gnash

./autogen.sh

./configure --enable-renderer=agg \
               --enable-gui=dump \
               --disable-menus \
               --enable-media=ffmpeg \
               --disable-jemalloc

make

you can then point dump-gnash at a swf and it will render out the raw video and audio

dump-gnash -1 \
                   -D /tmp/out.raw@30 \
                   -A /tmp/out.wav \                      
                   -P "FlashVars=myURL=http://example.com/blah&online=true" \
                   http://example.com/blah/some.swf \

This will write out /tmp/out.raw (which is bgra aka rgb32 video) at 30fps (the @30 bit) and /tmp/out.wav

These need re-combining into e.g. mp4 using:

ffmpeg -i /tmp/out.wav \
       -f rawvideo \
       -pix_fmt rgb32 \
       -s:v 800x550 \
       -r 30 \
       -i /tmp/out.raw \
       -c:v libx264 \
       -r 30 \
       -b 160k \
       /tmp/out.mp4

because its raw video, ffmpeg needs to know colourspace (rga32) dimensions and input fps. We tell it to combine the audio (160kbps mp3), render the video back out at 30fps

You'll need additional flags to get the lossless mp4.