Update (Aug 15, 2008): The AMF0Parser library has been updated to support the Date type in the metas, added among others by the “inlet media FLVTool2″ tool.

If you’ve done Flash banners or micro-sites that embed video with cue points for synchronization before, you know that it’s a pain in the arse. There doesn’t seem to be any tool around to modify the damn points once the file is encoded, so you’ve got to re-encode the file over and over to have your things synced correctly.

If you’ve tried to reverse engineer the FLV format before, you know that it’s a pain in the arse as well. The AMF0 format is anything but intuitive, and the documentation has been lacking for a long long time — although there’s apparently an SDK now. Luckily, there was OSFlash, and SabreAMF and AMFPHP that could be used as a documentation source.

If you recognize yourself, this might be your lucky day. After many hours of trial and error, I’ve finally been able to reverse engineer it, and to build a library that extract essential FLV information, reads the Meta, and allows you to write them back — including the cue points.

First, you’ll need to FLVInfo2 and the AMF0Parser libraries, below. The FLVInfo2 library has three main functions:

  • getInfo, which returns information gotten from analyzing the FLV file and it’s meta. Frame rate, bit rate, audio/video codec, width, height, etc.
    (
        [signature] => 1
        [hasVideo] => 1
        [hasAudio] => 1
        [minimalFlashVersion] => 8
        [video] => stdClass Object
            (
                [codec] => 4
                [width] => 320
                [height] => 240
                [keyframeRatio] => 0.0180537208278
                [keyframeEvery] => 55.3902439024
                [fps] => 15
                [bitrate] => 448
                [codecStr] => On2 VP6
            )
    
        [audio] => stdClass Object
            (
                [codec] => 2
                [frequency] => 22
                [depth] => 16
                [channels] => 2
                [bitrate] => 48
                [codecStr] => MP3
            )
    )
  • getMeta, which returns the meta data, and the cue points
    Array
    (
        [metas] => Array
            (
                [0] => Array
                    (
                        [0] => onMetaData
                        [1] => Array
                            (
                                [duration] => 151.46
                                [width] => 320
                                [height] => 240
                                [videodatarate] => 500
                                [canSeekToEnd] => 1
                                [videocodecid] => 4
                                [audiodatarate] => 48
                                [audiocodecid] => 2
                                [framerate] => 15
                                [creationdate] => Tue Jun 17 13:06:15 2008
                                [Encoded_By] => orangetango Video Encoder
                                [Encoded_With] => orangetango Video Encoder
                                [metadatacreator] => orangetango FLV meta data writer
                            )
                    )
            )
        [cuepoints] => Array
            (
                [0] => Array
                    (
                        [0] => onCuePoint
                        [1] => Array
                            (
                                [name] => name1
                                [time] => 4.41
                                [type] => event
                            )
                    )
                [1] => Array
                    (
                        [0] => onCuePoint
                        [1] => Array
                            (
                                [name] => name1_end
                                [time] => 6.7
                                [type] => event
                            )
                    )
            )
    )
  • rewriteMeta, which inputs an FLV file, meta data and cue points, and outputs a new FLV file.

As a practical example, you find the rewriteTagsForFile function in the example.php file, that rewrites the meta data and gets the cue points from a FLVCoreCuePoints XML file.

PHP Source flvinfo2.php (175k)

PHP Source AMF0Parser.php (96k, updated Aug 15, 2008)

PHP Source example.php (12k)

Flash Video logo found on Wikipedia.


If you like this acrticle, leaving a comment, Digging it, adding it to your del.icio.us bookmarks is always appreciated.

category Flash, PHP Friday 4 July 2008
Del.icio.usTechnoratiBlogmarksStumbleUponFacebookBlogLinesReddit

3 Responses :

  1. Mario H.

    Hi Tommy,
    it’s great, you’ve developed this scripts. I was thinking about programming a script like this too.
    But could you please upload/link flvinfo2.php too?
    Thx
    Mario H.

  2. tlacroix

    Hi Mario,

    Thanks for noticing, I made a mistake when created the link into the file. It has now been corrected.

    You’ll find the code here:
    http://www.tommylacroix.com/wp-content/uploads/2008/07/flvinfo2.phps

    Cheers,

    Tommy.

  3. Mario H.

    Thank you very much, also for your very quick reply! Your scripts/libraries are working great.
    You saved me a lot of work.

Leave a Reply

CAPTCHA image