FLV to SWF and back

During the past couple of weeks, I’ve been working on a library that can convert SWF files to FLV files and vice versa. I’ve finally succeeded and release v0.10 tonight! If you are a media expert (or amateur!) I’d love some help testing this. Currently, I’ve only tested on Mac with FLV and SWF files generated by the On2 Flix Exporter for QuickTime. Media from other sources and testing on other platforms would be greatly appreciated.

The SWF and FLV file formats are media containers invented by Macromedia (now Adobe) for playback in Flash. Each file format has its own purpose, but with regard to just video and audio they are quite similar under the hood:

Both are tag-oriented container formats. FLV supports three types of tags (video, audio and meta) while SWF supports over 60 (video, audio, bytecode, shapes, sprites, fonts, etc) and is still growing. FLV represents a static media stream, like many of the QuickTime and Windows Media audio/video formats. SWF, on the other hand, is animated vector art with code, like SVG. Macromedia has been quite good about documenting the file formats, although they typically delay release of documentation for a generation (i.e. the Flash 6 documentation was published when Flash 7 came out) and require a license agreement.

The two tags types that SWF and FLV have in common (video and audio) share the same binary format for the media encoding, like MP3, H.263, VP6, ADCRM, ScreenVideo, NellyMoser, etc. Consequently it is feasible to convert audio and video data between the two file formats without requiring time-consuming transcoding or patented media encoding algorithms.

There are several complications involved in the conversion, however, that I had to overcome. For example SWF insists that there may be at most one audio packet per video frame and infers time from the video framerate. FLV on the other hand uses absolute time codes for every packet, whether video or audio.

While I was at it, I threw in an FLV to MP3 converter too since that’s just a subset of the FLV to SWF converter, and was handy for debugging.

I certainly have to give credit to the Ruby FLVTool2 library for helping me get v0.01 of my library (the initial FLV parsing part) out the door. That library helped me discover one place where Macromedia’s documentation was erroneous and helped me understand the undocumented FLV meta tag. Additionally, I must credit the SWF::File Perl library, which handles the SWF read/write portions of my transcoder. Yay open source!

7 thoughts on “FLV to SWF and back”

  1. Chris,

    I’m wondering if you’ve ever seen a fully functioning perl wrapper for ffmpeg that handles transcoding like so:

    ffmpeg -i foofoo.avi -ar 44100 -b 8000 foo.flv


    I’m thinking it doesn’t exist yet.

  2. Dave,

    No, I have not seen such a wrapper. My transcoder is different in that it doesn’t actually need to parse and re-encode the media. That makes it lightning fast, but limits it to working only with FLV and SWF.

    Certainly, one could write a generic transcoder that used the fast path for SWF to FLV and shelled out to ffmpeg for other transcodings. However, I think tools like VisualHub (neé iSquint) do a pretty good job of that already on the GUI side.


  3. I appreciate the response. I’m trying to get something enterprise-scale working; lots of uploads and transcodes, so I guess I have to hire someone to write the perl wrapper so’s I can call ffmpeg from a script. Thanks anyway 🙂

  4. I am trying to convert a flash file – version 5 as ‘file command’ detected – generated by vnc2swf.py. But the result produces only flash video files without video. mplayer reports – no video – and plays only sound. Have any idea?

  5. i am so basic at this so please help im trying to convert a swf to flv, iv looked everywhere and only find that i have to convert to video then flv the problem is that the quality isnt the same and the final product is rubbish

Comments are closed.