lib/movie_normalizer.rb
#Searches for gaps between videoclips and fills them with black screen
Searches for gaps between videoclips and fills them with black screen
Searches for gaps between videoclips and fills them with black screen
def fill_gaps(movie)
    sorted_visuals = movie.visual_sequence.sort
    gaps = 0
    0.upto(sorted_visuals.length - 1) { |i|
      unless i == (sorted_visuals.length - 1)
        clip_a = sorted_visuals[i]
        clip_b = sorted_visuals[i + 1]
        delta_x = clip_b.place.milliseconds - (clip_a.place.milliseconds + clip_a.length)
        unless delta_x == 0 or delta_x < 0 
          gap_place = "00:00:00:" + (clip_a.place.milliseconds + clip_a.length).to_s
          gap_start = "00:00:00:00"
          gap_end = "00:00:00:" + delta_x.to_s
          gap = Visual.new("blackness", "nil", gap_start, gap_end, gap_place, true, [], [])
          sorted_visuals << gap
          gaps += 1
        end
      end
    }
    movie.visual_sequence.visuals = sorted_visuals
    return gaps
  end
def fill_gaps ( movie ) sorted_visuals = movie . visual_sequence . sort gaps = 0 0 . upto ( sorted_visuals . length - 1 ) { | i | unless i == ( sorted_visuals . length - 1 ) clip_a = sorted_visuals [ i ] clip_b = sorted_visuals [ i + 1 ] delta_x = clip_b . place . milliseconds - ( clip_a . place . milliseconds + clip_a . length ) unless delta_x == 0 or delta_x < 0 gap_place = "00:00:00:" + ( clip_a . place . milliseconds + clip_a . length ) . to_s gap_start = "00:00:00:00" gap_end = "00:00:00:" + delta_x . to_s gap = Visual . new ( "blackness" , "nil" , gap_start , gap_end , gap_place , true , [ ] , [ ] ) sorted_visuals << gap gaps += 1 end end } movie . visual_sequence . visuals = sorted_visuals return gaps end
Searches for gaps between videoclips and fills them with black screen
Searches for gaps between videoclips and fills them with black screen
#Iterate through visuals and determine gaps =>  #add generated blackness to fill in the gaps #ToDo!: Why there is even a possibility for negative values?
movie
<not_specific>