Convert compressed swf to mp4
Asked Answered
E

4

27

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?

Engrossment answered 25/11, 2013 at 13:26 Comment(4)
Hi - did you ever figure out how to do this? thanksTurnout
Max- No luck yet. For now I've purchased the other version from the vendor himself.Engrossment
ok, thanks! <padding></padding>Turnout
I guess maybe a little late, but I think I found out how to do this. I will provide a answer below in a little while.Duo
J
27

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.

Jackshaft answered 9/1, 2014 at 14:36 Comment(8)
Hey Jay, this is really useful! However, when I do this, I find backgrounds and text are not displayed. Any idea why this might be the case?Wingo
Could be for a variety of reasons; do you know whether the swf was built with AS2 or 3? I had some problems where a background wasn't rendering because one swf was loading another and the movie was a combination of the two, gnash didn't always deal with this correctly.Jackshaft
Gnash has added a dependencies installer now for debian-types: deb-attempt-install-dependencies.shTonsorial
I can't get this tool to compile on mac. I'm getting compilation errors.Lithesome
Thanks to stackoverflow.com/users/102250/jan-larres for the suggested edit about the missing .raw. I couldn't approve the edit, due to some rather over-zealous edit rejections by various reviewersJackshaft
Hi, just used this. I had to specify that the -b option applied to the audio by using -b:a instead. I also replaced the second -r with -r:a just in case, but maybe it´s not needed.Coel
Thank you very much for your lovely suggestion. I've installed gnash in my slack 14x and it's working but when I use your script (thanks again for the script) it generates a huge space as within a few seconds it gobbles up 6 gigs so I had to kill the operation. Is there any other way or could you suggest how much disc space is required to convert a round about 50mb swf file?Dodd
I even tried to install gnash in ubuntu with dependent packages but couldn't configure as the error was gconf-2.o is missing. I installed gconf-2.0 but autoconf can't find it.Dodd
D
11
OS: Ubuntu (Linux)

I don't exactly know if this is lossless but at least I got the convert part working(ffmpeg).

dependencies

sudo apt-get install ffmpeg swftools

Decompress

First I decompressed using swfcombine:

swfcombine -d file.swf -o file_new.swf

Convert

Next I converted using ffmpeg which might not be lossless with these parameters

ffmpeg -i file.swf video.mp4
Duo answered 16/10, 2014 at 12:27 Comment(3)
This work but won't render/ommits new assets added via swfcombine as described in marc.info/?l=swftools-common&m=138732909815669&w=2 - would you have any idea how to make sure new images are not left aside?Colossal
The video is all garbled for me.Lithesome
It works for me with sudo apt-get install libav-tools, not as shown above.Doha
T
4

You may use this script:

#!/bin/bash

SWFFILE=$1
MP4FILE=${SWFFILE%.*}.mp4
TMPFILE=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).bin
TMPWAV=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).wav
TMPMP4=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 32 | head -n 1).mp4

# create raw-dump
GNASHCMD="dump-gnash -1 -r 3 -v -D $TMPFILE -A $TMPWAV $SWFFILE"
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/^.*=//')"

# create raw, uncompressed mp4 file
mplayer $TMPFILE -vo yuv4mpeg:file=$TMPMP4 -demuxer rawvideo -rawvideo fps=$FPS:w=$WIDTH:h=$HEIGHT:format=bgra

# create compressed mp4 with ffmpeg
ffmpeg -i $TMPMP4 -i $TMPWAV $MP4FILE

# clean up
rm -rf $TMPFILE
rm -rf $TMPMP4
rm -rf $TMPWAV

Works for me!

Taille answered 3/9, 2016 at 7:29 Comment(4)
I had to add "-strict -2" Before the output on ffmpeg. I also had to manually set the --max-advances for a bunch of files due to loops in the swf. Otherwise, this worked great.Eo
Thanks for the script. I tried to convert a 17mb swf file but it's taking a huge amount of disk space as 22gigs have been exhausted yet unfinished. Is something going wrong?Dodd
@Dodd try to compress mp4 on the fly using h264 or 265 encoder or something. Did not use this script for a long time, look at ffmpeg switches.Taille
Thank you. I'm really clueless and I haven't got mplayer. I use slack with bare minimum packages and my space is exhausted installing xurlrunner.Dodd
O
3

I just would like to say that there is not reliable way to convert SWF to MP4. Because SWF-file is a program generally. In simplest case SWF-file contains only video (and audio as well). Solutions provided by jaygooby, Alfred and Aleksey Kontsevich work perfectly in such cases.

But many SWF-files contain theirs own Play/Pause buttons, volume controls, etc. When you open such file in Gnash (or whatever player) you need to perform additional action (for example, click on an embedded Play button) in order to really start playing. Yes, it's possible to automate this stuff in some way (e.g. Xvfb, xdotool, etc). At the same time there are a lot of caveats there (especially audio stream). I even wrote an article about such approach (that's in Russian).


PS1 Please do not consider this answer and the latter link as an advertisement of my site.

PS2 This stuff should go as comment. But it's published as answer because of text format.

Ominous answered 6/5, 2017 at 13:41 Comment(1)
I've updated the URL so it points to actual page instead of web archive.Ominous

© 2022 - 2024 — McMap. All rights reserved.