Wowza Community

Modifying flvtool2 to work with .flv files recorded using Wowza Pro (fix)

Problem

The metadata generation tool flvtool2 crashes when run on .flv files created using Wowza Media Server Pro.

Solution

There is a bug in flvtool2 1.0.6 which causes a unrecoverable failure when run against a .flv recorded using Wowza Media Server Pro. This problem is easily fixed with a minor modification to the flvtool2 source code. The following instructions assume that flvtool2 is either going to be run on Linux or on Windows from within a Linux emulation environment like Cygwin or MinGW.

  • Install the ruby and ruby-devel packages on your machine.

  • Download and unzip the flvtool2 1.0.6 source code (flvtool2-1.0.6.zip).

  • Change directory to flvtool2-1.0.6/lib/flv and open the file audio_tag.rb in a text editor.

  • Navigate to line 47 and change the code as follows:

    from:
        def after_initialize(new_object)
          @tag_type = AUDIO
          read_header
        end
    to:
        def after_initialize(new_object)
          @tag_type = AUDIO
          if data_size > 0
              read_header
          end
        end
    
    
  • Change directory up two levels (cd …/…) and execute the following commands to rebuild and install the flvtool2 application:

    ruby setup.rb config
    ruby setup.rb setup
    ruby setup.rb install
    
  • You are done. The tool should now function properly.

    I have submitted a bug to the flvtool2 team to try and get this resolved in a future release of the application. I will add a post to this thread when/if I hear back.

    NOTE: I believe this problem will also occur with .flv files recorded using Flash Media Server.

    Charlie

This change works wonderfully. Thanks so much!

I have compiled the flvtool2 with the bugfix from Charlie.

When I cut a (by Wowza)H.264/FLV recorded file with flvtool2 with the next command:

flvtool2 -CUa -i 10000 -o 20000 test_1.flv test_s1.flv

The file becomes completely unplayable, for instance with the simplevideo player from Wowza.

Do I use the wrong command?

I don’t have one. I did my work on Linux.

Charlie

Hi all

There is no possibility to get my windows server ready for emulating linux as described.

Is there any way to compile the corrected source as a win32 binary in order to work with wowza recorded flv files?

Has anybody done this before or is there a way to download such an flvtool2.exe already?

Thanks for your help

Mierco

Alternatively… I was able to get this working without having to recompile it… just edited the file: vi /usr/lib/ruby/site_ruby/1.8/flv/audio_tag.rb and then re-ran the command… and it worked! I didn’t have to download the source and recompile…

good luck!

Jake

Hi all

There is no possibility to get my windows server ready for emulating linux as described.

Is there any way to compile the corrected source as a win32 binary in order to work with wowza recorded flv files?

Has anybody done this before or is there a way to download such an flvtool2.exe already?

Thanks for your help

Mierco

Hi Mierco

i would like to know if you have got the binaries of the FLVtool2 which has changes as charlie pointed out so that it wud edit the flv files streamed from the FMS server

I am also interested in the Win32 binary with the changes.

I cannot get the flvtool2 source to compile using ruby on my windows machine. :rolleyes:

edit: I finally got it compiled, but now it says “program too big to fit in memory” when I run it. I am at a loss.

Can anyone upload the windows binary?

edit: nevermind, got around the error by using yamdi instead:

http://yamdi.sourceforge.net/

Much better than flvtool2!

I used the fix but still ran into problems with a ffmpeg h264-encoded stream. I went through the ruby code to see where it went wrong, and in fact it’s where the code tries to extract the width and height from each video frame. The code was written before h264 was added to the FLV spec. So, I wrote a fix for it and decided to share it here.

In the file (video_tag.rb), in the function read_header, after parsing the codec_id, check if it equals H263 or SVC and only read further if it does.

      bit_sequence = data_stream.read(9).unpack('B72').to_s

becomes:

      if @codec_id == H263VIDEOPACKET || @codec_id == SCREENVIDEOPACKET
        bit_sequence = data_stream.read(9).unpack('B72').to_s
      end