FLVTool2 broken

To make FLV's coming from flash streaming servers (FCS/FMS/Red5) properly work as a progressive download, it's often required to use a tool to inject 'missing' meta-data.

Up until now I used FLVTool2 for this, but it seems to load the entire FLV into memory (badd!), and now I'm getting nasty errors as well..

  1. ERROR: EOFError
  2. ERROR: /usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:37:in `read'
  3. ERROR: /usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:243:in `read__STRING'
  4. ERROR: /usr/local/lib/site_ruby/1.8/flv/audio_tag.rb:56:in `read_header'
  5. ERROR: /usr/local/lib/site_ruby/1.8/flv/audio_tag.rb:47:in `after_initialize'
  6. ERROR: /usr/local/lib/site_ruby/1.8/flv/tag.rb:56:in `initialize'
  7. ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:447:in `new'
  8. ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:447:in `read_tags'
  9. ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:58:in `initialize'
  10. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:272:in `new'
  11. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:272:in `open_stream'
  12. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:238:in `process_files'
  13. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:225:in `each'
  14. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:225:in `process_files'
  15. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:44:in `execute!'
  16. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2.rb:168:in `execute!'
  17. ERROR: /usr/local/lib/site_ruby/1.8/flvtool2.rb:228
  18. ERROR: /usr/bin/flvtool2:2:in `require'
  19. ERROR: /usr/bin/flvtool2:2

I wanted to try out FLVTool++ anyway, as it seems like a much more scalable solution.. This is how its installed on debian:

Grab the source:

  1. wget "http://rcdn.org:8080/images/4/44/Flvtool%2B%2B.tar.bz2"

Unpack

  1. tar xfvj Flvtool++.tar.bz2

Make sure you have a compiler installed (as root).

  1. apt-get install build-essential

Compiling

  1. make

AArrghh! It doesn't compile :(. This is the error it gave me:

  1. g++ -O2 -c -Wall -D_FILE_OFFSET_BITS=64 flvtool.cpp -o flvtool.o
  2. AMF.h:35: error: invalid pure specifier (only `= 0' is allowed) before ';' token
  3. flvtool.cpp: In function 'int main(int, char**)':
  4. flvtool.cpp:192: warning: too many arguments for format
  5. make: *** [flvtool.o] Error 1

Ok, lets dig into this code a bit.. the errors seems to give a few useful hints..

First thing I did was go to line 35 in AMF.h and change:

  1. virtual std::ostream& operator << (std::ostream& os) const = NULL;

into:

  1. virtual std::ostream& operator << (std::ostream& os) const = 0;

Next, open flvtool.cpp (line 192) and change:

  1. fprintf(stderr, "usage:\n", argv[0]);

Into:

  1. fprintf(stderr, "usage:\n");

Now, for some reason you also need to manually create the bin/ directory in your source directory, after that you can start compiling again.

  1. mkdir bin
  2. make

Success! Your bin/ directory will now contain the flvtool++ binary

  1. ./bin/flvtool++
  2. #outputs:
  3.  
  4. flvtool++ version 1640 2007/05/24 14:39:18
  5. usage:
  6. flvtool++ <input file> <output file> (<start time> <end time>)
  7. flvtool++ -i <input file>

9 Responses to FLVTool2 broken

  1. 62 DrSlump 2007-07-19 6:31 pm

    I'm going to do a bit of self promotion :)

    Some months ago I started a PHP project to handle FLV files streaming. The project is in standby right now since I don't have the need neither the time to further develop it, but it should be stable enough to just extract and inject the metadata.

    The C++ based solution sure will be faster and more efficient but installing a custom binary or even compiling it is not always an option on many hosts.

    http://blog.netxus.es/projects/flv4php

  2. 63 Evert 2007-07-19 7:52 pm

    Dr Slump,

    I actually also have an implementation of this in PHP. The main problem is, like you stated, its not really efficient.

    Evert

  3. 59 iongion 2007-07-20 7:46 am

    Gion,

    Why don't you use this project http://yamdi.sourceforge.net it very reliable, the developer is really open to solve bugs in his free time, it is a C standalone executable, it is easy to modify and adapt to windows, it works great with large/huge files because it uses memory mapped fies. (When compiling for windows, you will need the mmap equivalent for windows and there are a lot of samples of how to use Win32 api to emulate mmap).

    Cheers and good luck!

  4. 60 Anonymous 2007-09-29 1:28 pm

    I already compiled yamdi for windows, yo ucan download it from yamdi's forum at sourceforge.

    regards
    Ali...

  5. 61 mrs applebee 2007-10-02 8:23 am

    I installed FLVtool and did the sudo ruby setup.rb install. But I got my mac from my boss and typed my password. Apperently I need his 'cause I always get "-bash: ./flvtool2: Permission denied"

    I tried re-installing several times (by deleting folder in my finder) but I cannot continue, I always get stuck on the password: or I can't type it, or it does the job but when I process an flv file I get the message "permission denied"

    can anyone help me out here? I'm desparate! Need to publish my talks on parleys asap!!!

  6. 64 Nin 2008-01-25 8:54 am

    I'm getting the following errors when I try to execute the FlvTool2 on Windows:

    C:\temp\TmpToolbox>ffmpeg -i MOV00283.MPG -ar 44100 -s 320x240 -r 12 movie.f
    flvtool2 -U stdin movie.flv
    FFmpeg version SVN-r11143, Copyright (c) 2000-2007 Fabrice Bellard, et al.
    configuration: --enable-gpl --enable-pp --enable-swscaler --enable-pthread
    enable-liba52 --enable-avisynth --enable-libamr-nb --enable-libamr-wb --enab
    ibfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --enable-libnut
    able-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --cpu=i6
    -enable-memalign-hack --extra-ldflags=-static
    libavutil version: 49.5.0
    libavcodec version: 51.48.0
    libavformat version: 52.1.0
    built on Dec 3 2007 17:42:57, gcc: 4.2.2 (mingw32)
    Input #0, mpeg, from 'MOV00283.MPG':
    Duration: 00:00:03.8, start: 0.110000, bitrate: 2925 kb/s
    Stream #0.0[0x1c0]: Audio: mp2, 32000 Hz, mono, 64 kb/s
    Stream #0.1[0x1e0]: Video: mpeg1video, yuv420p, 640x480 [PAR 1:1 DAR 4:3
    04857 kb/s, 25.00 tb(r)
    File 'movie.flv' already exists. Overwrite ? [y/N] y
    Output #0, flv, to 'movie.flv':
    Stream #0.0: Video: flv, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 200
    s, 12.00 tb(c)
    Stream #0.1: Audio: libmp3lame, 44100 Hz, mono, 64 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Stream #0.0 -> #0.1
    Press [q] to stop encoding
    frame= 49 fps= 0 q=4.3 Lsize= 212kB time=4.0 bitrate= 434.3kbits/s
    video:177kB audio:31kB global headers:0kB muxing overhead 1.641348%
    ERROR: undefined method `timestamp' for nil:NilClass
    ERROR: flv/stream.rb:285:in `lasttimestamp'
    ERROR: flv/stream.rb:274:in `duration'
    ERROR: flvtool2/base.rb:181:in `add_meta_data_tag'
    ERROR: flvtool2/base.rb:137:in `update'
    ERROR: flvtool2/base.rb:47:in `send'
    ERROR: flvtool2/base.rb:47:in `execute!'
    ERROR: flvtool2/base.rb:46:in `each'
    ERROR: flvtool2/base.rb:46:in `execute!'
    ERROR: flvtool2/base.rb:206:in `process_files'
    ERROR: flvtool2/base.rb:44:in `execute!'
    ERROR: flvtool2.rb:168:in `execute!'
    ERROR: flvtool2.rb:228

  7. 58 daniels 2008-08-29 1:10 pm

    or this :
    fprintf(stderr, "usage: %s\n", argv[0]);

  8. 57 Evert 2008-08-29 1:26 pm

    Trying to figure out how thats related :)

  9. 65 Marc 2009-04-29 8:07 pm

    You could also try my FLVmeta ^_^



About

My name is Evert, and I've been writing semi-regularly on this blog since 2006.

I'm currently available for contract work.

more info.

Subscribe

Dropbox

Dropbox is a simple cross-platform online backup and sync application. The first 2GB of space is free, and both you and me get an extra 250MB extra space if you sign up through this link.