Sha256: 7731e56f5e6f9ebac68d6b0dfebc010acf0a3b216d4eb3413c287fe545c419fc

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

module FLV
  module Edit  
    module Processor

      class Join < Base
        desc "Join the FLV files"
    
        def process_next_file
          dispatch_chunks(@source) while @source.has_next_file?
        end

        def on_tag(tag)
          if @wait_for_keyframe
            absorb
          else
            tag.timestamp += @delta
          end
          @last_timestamp = tag.timestamp
        end
        
        def on_video(tag)
          @next_to_last_video_timestamp, @last_video_timestamp = @last_video_timestamp, tag.timestamp
        end
        
        def on_keyframe(tag)
          if @wait_for_keyframe
            @wait_for_keyframe = false
            @delta -= tag.timestamp
          end
        end

        def on_header(h)
          if is_first_header = !@delta
            @delta = 0
            @wait_for_keyframe = false
            @last_video_timestamp = 0
          else
            if @last_video_timestamp
              last_interval = @last_video_timestamp - @next_to_last_video_timestamp
              @delta += [@last_video_timestamp + last_interval, @last_timestamp].max
              @wait_for_keyframe = true
            else
              @delta = @last_timestamp
            end
            dispatch_instead(Tag.new(@last_timestamp, evt = Event.new(:onNextSegment, :file => ::File.basename(h.path))))
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
marcandre-flvedit-0.6.1 lib/flv/edit/processor/join.rb
flvedit-0.6.1 lib/flv/edit/processor/join.rb