Class: Hornetseye::AVOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/hornetseye-ffmpeg/avoutput.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(mrl, video_bit_rate, width, height, frame_rate, aspect_ratio = 1, video_codec = nil, have_audio = false, audio_bit_rate = 64000, sample_rate = 44100, channels = 2, audio_codec = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 26

def new( mrl, video_bit_rate, width, height, frame_rate, aspect_ratio = 1,
         video_codec = nil, have_audio = false, audio_bit_rate = 64000,
         sample_rate = 44100, channels = 2, audio_codec = nil )
  if frame_rate.is_a? Float
    frame_rate = 90000.quo( ( 90000 / frame_rate ).to_i )
  end
  retval = orig_new mrl, video_bit_rate, width, height,
                    frame_rate.denominator, frame_rate.numerator,
                    aspect_ratio.numerator, aspect_ratio.denominator,
                    video_codec || CODEC_ID_NONE,
                    have_audio ? audio_bit_rate : 0,
                    have_audio ? sample_rate : 0,
                    have_audio ? channels : 0,
                    audio_codec || CODEC_ID_NONE
  if have_audio
    retval.instance_eval do
      @audio_buffer = MultiArray.new SINT, channels, frame_size
      @audio_samples = 0
    end
  end
  retval
end

.orig_newObject



24
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 24

alias_method :orig_new, :new

Instance Method Details

#orig_write_audioObject



59
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 59

alias_method :orig_write_audio, :write_audio

#orig_write_videoObject



51
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 51

alias_method :orig_write_video, :write_video

#write_audio(frame) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 61

def write_audio( frame )
  unless frame.typecode == SINT
    raise "Audio frame must have elements of type SINT (but elements were of " +
          "type #{frame.typecode})"
  end
  unless frame.dimension == 2
    raise "Audio frame must have 2 dimensions (but had #{frame.dimensions})"
  end
  unless frame.shape.first == channels
    raise "Audio frame must have #{channels} channels " +
          "(but had #{frame.shape.first})"
  end
  size = frame_size * 2 * channels
  remaining = frame
  while @audio_samples + remaining.shape.last >= frame_size
    if @audio_samples > 0
      @audio_buffer[ @audio_samples ... frame_size ] =
        remaining[ 0 ... frame_size - @audio_samples ]
      orig_write_audio Sequence.import(UBYTE, @audio_buffer.memory, size)
      remaining = remaining[ 0 ... channels,
                             frame_size - @audio_samples ... remaining.shape.last ]
      @audio_samples = 0
    else
      orig_write_audio Sequence.import(UBYTE, remaining.memory, size)
      remaining = remaining[ 0 ... channels, frame_size ... remaining.shape.last ]
    end
  end
  if remaining.shape.last > 0
    @audio_buffer[ 0 ... channels, @audio_samples ... @audio_samples +
                   remaining.shape.last ] = remaining
    @audio_samples += remaining.shape.last
  end
  frame
end

#write_video(frame) ⇒ Object Also known as: write



53
54
55
# File 'lib/hornetseye-ffmpeg/avoutput.rb', line 53

def write_video( frame )
  orig_write_video frame.to_yv12
end