Class: Hornetseye::AVInput

Inherits:
Object
  • Object
show all
Includes:
ReaderConversion
Defined in:
lib/hornetseye-ffmpeg/avinput.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(mrl, audio = true) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 26

def new( mrl, audio = true )
  retval = orig_new mrl, audio
  retval.instance_eval do
    @frame = nil
    @video = Queue.new
    @audio = Queue.new
    @video_pts = AV_NOPTS_VALUE
    @audio_pts = AV_NOPTS_VALUE
  end
  retval
end

.orig_newObject



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

alias_method :orig_new, :new

Instance Method Details

#aspect_ratioObject



114
115
116
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 114

def aspect_ratio
  orig_aspect_ratio == 0 ? 1 : orig_aspect_ratio
end

#audio_posObject



88
89
90
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 88

def audio_pos
  @audio_pts == AV_NOPTS_VALUE ? nil : @audio_pts * audio_time_base
end

#audio_start_timeObject



107
108
109
110
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 107

def audio_start_time
  retval = orig_audio_start_time
  retval == AV_NOPTS_VALUE ? nil : retval * audio_time_base
end

#durationObject



94
95
96
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 94

def duration
  orig_duration == AV_NOPTS_VALUE ? nil : orig_duration * video_time_base
end

#enqueue_frameObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 60

def enqueue_frame
  frame = read_av
  if frame.is_a? Frame_
    @video.enq [frame, video_pts]
    @frame = frame
  else
    n = channels
    samples = MultiArray.import(SINT, frame.memory, n, frame.size / (2 * n))
    @audio.enq [samples, audio_pts]
  end
end

#orig_aspect_ratioObject



112
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 112

alias_method :orig_aspect_ratio, :aspect_ratio

#orig_audio_start_timeObject



105
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 105

alias_method :orig_audio_start_time, :audio_start_time

#orig_durationObject



92
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 92

alias_method :orig_duration, :duration

#orig_video_start_timeObject



98
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 98

alias_method :orig_video_start_time, :video_start_time

#pos=(timestamp) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 72

def pos=( timestamp )
  unless @frame
    begin
      read_video
    rescue Exception
    end
  end
  seek timestamp * AV_TIME_BASE
end

#readObject



50
51
52
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 50

def read
  has_video? ? read_video : read_audio
end

#read_audioObject



54
55
56
57
58
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 54

def read_audio
  enqueue_frame while @audio.empty?
  frame, @audio_pts = @audio.deq
  frame
end

#read_videoObject



44
45
46
47
48
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 44

def read_video
  enqueue_frame while @video.empty?
  frame, @video_pts = @video.deq
  frame
end

#shapeObject



40
41
42
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 40

def shape
  [ width, height ]
end

#video_posObject Also known as: pos



82
83
84
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 82

def video_pos
  @video_pts == AV_NOPTS_VALUE ? nil : @video_pts * video_time_base
end

#video_start_timeObject



100
101
102
103
# File 'lib/hornetseye-ffmpeg/avinput.rb', line 100

def video_start_time
  retval = orig_video_start_time
  retval == AV_NOPTS_VALUE ? nil : retval * video_time_base
end