Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render swf to png or other image format

How can I, on linux, render a swf to a image file? I need to be able to load other swfs into that swf and run actionscript code.

Is it even possible on linux? I need to do it from PHP, it's fine if I have to use command-line tools.

like image 552
James T Avatar asked Mar 09 '12 21:03

James T


People also ask

Which programs use SWF files?

To open an SWF file, you can use VLC Player or the hidden Flash player from Adobe that developers often use.


2 Answers

swfrender from swftools works for basic SWF files.

swfdec-thumbnailer from swfdec-gnome works though it only gets the first frame of the swf.

To get any frame from swf using swfdec see the C code snippet in the following mailing list post.

gnash from gnash also works gnash -s<scale-image-factor> --screenshot last --screenshot-file output.png -1 -r1 input.swf, last image of the swf.

ffmpeg from ffmpeg also works for some swf formats ffmpeg -i movie.swf -f image2 -vcodec png movie%d.png

Also see the following guide for a commandline pipeline.

In order to call external programs from php you use the exec command documented here.

Note that for security reasons it is important to escape arguments passed to exec with another command like escapeshellcmd or escapeshellarg for security reasons.

Once you have converted to an image format whether for single frame or all frame, you can't run action script. Other non GNU / Linux tools support the export of the action script from from SWF.

If the SWF that you are exporting to PNG is too complicated for the other tools than you can use the Flash Plugin or Gnash and Xvfb along with screen capture software to capture either image frames of the SWF or a video format like avi. Then you can extract the images from the video format.

This virtual framebuffer method will support complicated SWF files, though it requires a lot of work as you need to use either Gnash and Xvfb and Screen Capture, or a browser , Xvfb and Selenium, if you want to capture a certain set of mouse / keyboard interactions with the SWF.

Gnash with and without the Virtual FrameBuffer should load the ActionScript before exporting, but may have issues with complicated ActionScript. Flash Plugin with Virtual Framebuffer will load the ActionScript before exporting.

Also see the following StackOverFlow questions, which you question is a duplicate of

  • Convert SWF to PNG
  • Render Flash (SWF) frame as image (PDF,PNG,JPG)
  • SWF to image (jpg, png, …) with PHP
like image 88
Appleman1234 Avatar answered Sep 25 '22 00:09

Appleman1234


This is the solution I ended up using.

You can use a tool like Xvfb (X11 server) and run the standalone flash player projector inside it (you may need to install a bunch of 32-bit libraries), then use a screen capture utility like import to capture the screen and crop it to size.

I found this page on rendering swf screenshots in linux helpful. It also says that you can use gnash to do this, however gnash won't work for flash player 9+.

like image 29
James T Avatar answered Sep 22 '22 00:09

James T