Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert compressed swf to mp4

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?

like image 734
skmvasu Avatar asked Nov 25 '13 13:11

skmvasu


3 Answers

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.

like image 200
jaygooby Avatar answered Nov 20 '22 16:11

jaygooby


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
like image 22
Alfred Avatar answered Nov 20 '22 15:11

Alfred


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!

like image 4
Aleksey Kontsevich Avatar answered Nov 20 '22 15:11

Aleksey Kontsevich