Saturday, October 13, 2007

Thumbnails from SWF video

I don't know if this'll ever be useful to anyone, but it was information I needed, and it was extremely hard to come by.

Here's how you extract a thumbnail from an video stored in an swf file. I'll leave the apt-get install dependencies as an exercise to the reader.

#!/bin/bash
SWF="$1"
AVI="${SWF/swf/avi}"
JPG="${SWF/.swf/%d.jpg}"
flasm -x "${SWF}"
mencoder -endpos 5 "${SWF}" -o /dev/null -nosound -ovc xvid -xvidencopts pass=1:turbo

mencoder -endpos 5 "${SWF}" -o "${AVI}" -nosound -ovc xvid -xvidencopts pass=2:bitrate=1600

ffmpeg -i "${AVI}" -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 120x90 "${JPG}"


BTW, this also converts the SWF to an AVI along the way, so if that's useful to you, great. (Modify the endpos and get rid of -nosound if you really wanted the AVI.)

3 comments:

Anonymous said...

This doesn't work for me. When I run the first mencoder line I get an error:

[swf @ 0x86e74c8]No media found in SWF

This is after running flasm on the file and it successfully decompresses the swf. It definitely is a valid swf file.

Did you run into this problem?

Unknown said...

Mike: I'm not really an expert on the format, but aiui some flash files embed the video data and some simply link to it. Check the file size to find out which one you have. :-) If the video data is linked, the HTTPGuideDog extension for firefox should help you pull that file.

Unknown said...

I am receiving an error as well. I am able to successfully compress the video with flasm, this is what I get when the first mencoder command runs

mencoder -endpos 5 video.swf -o /dev/null -nosound -ovc xvid -xvidencopts pass=1:turbo
MEncoder SVN-r29237-4.4.1 (C) 2000-2009 MPlayer Team
success: format: 0 data: 0x0 - 0x122b77
libavformat file format detected.
[swf @ 0x85ddd70]Compressed SWF format not supported
LAVF_header: av_open_input_stream() failed
libavformat file format detected.
LAVF_header: av_open_input_stream() failed
============ Sorry, this file format is not recognized/supported =============
=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===
Cannot open demuxer.