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..

ERROR: EOFError
ERROR: /usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:37:in `read'
ERROR: /usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:243:in `read__STRING'
ERROR: /usr/local/lib/site_ruby/1.8/flv/audio_tag.rb:56:in `read_header'
ERROR: /usr/local/lib/site_ruby/1.8/flv/audio_tag.rb:47:in `after_initialize'
ERROR: /usr/local/lib/site_ruby/1.8/flv/tag.rb:56:in `initialize'
ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:447:in `new'
ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:447:in `read_tags'
ERROR: /usr/local/lib/site_ruby/1.8/flv/stream.rb:58:in `initialize'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:272:in `new'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:272:in `open_stream'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:238:in `process_files'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:225:in `each'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:225:in `process_files'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2/base.rb:44:in `execute!'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2.rb:168:in `execute!'
ERROR: /usr/local/lib/site_ruby/1.8/flvtool2.rb:228
ERROR: /usr/bin/flvtool2:2:in `require'
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:

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

Unpack

tar xfvj Flvtool++.tar.bz2

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

apt-get install build-essential

Compiling

make

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

g++ -O2 -c -Wall -D_FILE_OFFSET_BITS=64 flvtool.cpp -o flvtool.o
AMF.h:35: error: invalid pure specifier (only `= 0' is allowed) before ';' token
flvtool.cpp: In function 'int main(int, char**)':
flvtool.cpp:192: warning: too many arguments for format
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:

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

into:

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

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

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

Into:

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.

mkdir bin
make

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

./bin/flvtool++
#outputs:

flvtool++ version 1640 2007/05/24 14:39:18
usage:
  flvtool++ <input file> <output file> (<start time> <end time>)
  flvtool++ -i <input file>

Web mentions

Comments

  • DrSlump

    DrSlump

    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
  • Evert

    Evert

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

    iongion

    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!
  • Anonymous

    I already compiled yamdi for windows, yo ucan download it from yamdi's forum at sourceforge. regards Ali...
  • mrs applebee

    mrs applebee

    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!!!
  • Nin

    Nin

    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
  • daniels

    daniels

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

    Evert

    Trying to figure out how thats related :)
  • Marc

    Marc

    You could also try my FLVmeta ^_^