1

I have a large number of flash movies which i need to convert to mp4 files, to make them ios compatible. Each of the movies already has a basic html file (all called index.html) which will open the swf, setting the appropriate parameters to make it go.

Each video has the same format: the movie itself is 800px wide by 600px high. The bottom 60 px is taken up with a control bar with play button, scrubbber etc. I do not want to capture this (since the mp4 player will add its own controls): i only want to capture the top 540px. Each flash video has an xml file which it reads in, and i can scrape the duration of the flash movie from this, so that i can pass the duration of the movie to whatever does the recording.

I'm in linux, and I want to write a script which does the following:

  • reads the location of the next index.html file
  • opens it in chrome (or some kind of headless browser perhaps)
  • runs *something* which does the following:
    • presses the "play" button on the video, which for the sake of argument lets say is always at coordinates "30,570"
    • starts recording video and audio for X seconds, where X is passed through from my script.
    • after X seconds, stop recording, and save the output as an mp4 file to a specified location on my filesystem.

Let's say, as an example, that for the first video i have these parameters i can pass through to whatever tool is going to do this:

{url: "localhost:3000/my_video_input/1/index.html", duration: 250, output_file:"/home/max/my_video_output/1/video.mp4"}

Can anyone point me at a tool, or perhaps a javascript library, for doing this? Perhaps the solution involves writing javascript into the html file before loading it into the browser. If so then that's doable but i'd prefer something simpler :)

thanks in advance - max

EDIT - some more info. The flash apps are as2, not as3, in case that's relevant.

Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • Can we assume that you either don't have Flash Professional (the program to edit Flash files), or the original source files for these animations? – 1owk3y Jan 02 '14 at 19:47

2 Answers2

3

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 libboost libagg

Then configure and build the gnash (open source flash player) video dumper:

cd gnash

./autogen.sh

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

make

then you can 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 (the audio track).

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 \
       -c:v libx264 \
       -r 30 \
       -b 160k \
       /tmp/out.mp4

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

jaygooby
  • 2,436
  • 24
  • 42
  • Thanks @jaygooby! For the "pressing the play button" step i can get our flash guy to do a new version of the flash app which can start playing automatically if it gets a particular flashvar variable passed to it. – Max Williams Jan 10 '14 at 09:36
  • Please note that jaygooby does have a corrected version of his answer at https://stackoverflow.com/questions/20194270/convert-compressed-swf-to-mp4 – Alberto González Palomo Nov 16 '18 at 21:12
1

I'm going to assume by 'Flash Movies' you mean Flash animations which are controlled by a playhead, rather than FLV video files which are controlled by a playhead.

I doubt JavaScript will be able to do this. In my experience, if you want to read SWF content (specifically capturing SWF image content), the easiest way is with a container Flash script/app.

This answer will explain how to take a loaded Flash and capture image data from it (you'll need Flash Professional to implement this solution. The free trial should accommodate you here).

You will be able to specify the dimensions which are being captured. See the Adobe reference on BitmapData for more information.

You will need to control the animation to give your capturer script time to read/write the data. Thankfully because you are using Flash/SWFLoader you can read the number of frames in the loaded Flash, and also control the playback.

Then, output uncompressed video from the BitmapData series, which is addressed in this answer.

I will assume you have access to a tool which will take an entire folder of uncompressed videos and convert them to a different format. If not, there are plenty of free and commercial programs available for this and they will be your best method for this task (rather than writing a video encoding script in Flash yourself which I assure you won't be easy)

If your files are hosted on the web, a client-side language (JavaScript) will be of no use to you. You will need a server-side language (PHP for instance) to collect all of the file locations and display them for the client.

I advise writing a PHP script which makes an XML file which lists all of the SWF locations in a folder (and all subdirectories), and have Flash read that generated XML file so that it knows which URLs to call. I suggest you raise a separate question if you need help with that.

Community
  • 1
  • 1
1owk3y
  • 1,115
  • 1
  • 15
  • 30
  • Hi - yes, the former: they're not straight flv videos, they're more complicated flash "apps" with several components. So there's no scope for straightforward flv/mp4 conversion. Also, yes, uncompressed video is fine, i can convert from there. Also, i can access the files via a web browser but i also have access to the file filesystem so can read them directly if required. – Max Williams Jan 03 '14 at 09:44
  • Note that i need to capture the audio too, which a stack of bitmaps obviously won't have. – Max Williams Jan 03 '14 at 10:00
  • Regarding reading a file system using JavaScript, here's a good answer on the subject: http://stackoverflow.com/questions/15537424/get-a-list-of-all-folders-in-directory. tl;dr HTML5 *might* work, but the answerer still recommends a server side language (like PHP). If your server doesn't support that, just make a local server on your computer (WAMPServer makes it super-easy) and put the files there. If you've not worked with PHP before you'll be surprised how simple it is. – 1owk3y Jan 03 '14 at 20:05
  • Also, I'm pretty sure Flash can 'listen' to the sounds being played by the system, which you can write to a WAV file using a similar method to above. If not, your Windows sounds settings will allow you to loop the microphone input through the system output (accomodating this purpose). You'll need to let the Flash play without interruption to capture that. This answer covers that: http://stackoverflow.com/questions/10102860/flash-record-sound-locally – 1owk3y Jan 03 '14 at 20:11
  • Also, this whole setup won't be a small task, and if you're not familiar with the steps it's probably going to take a day or so to build this system. To save you a whole lot of work, I suggest you just go buy a video capture card ( http://en.wikipedia.org/wiki/TV_tuner_card#Video_capture), play all of the clips sequentially, fire up some video editing software, set the cropping area and start/end of each clip, and output them all at once. Easy peasy. – 1owk3y Jan 03 '14 at 20:16