Class: Vidibus::Recording::Backend::Rtmpdump
- Inherits:
-
Object
- Object
- Vidibus::Recording::Backend::Rtmpdump
- Defined in:
- lib/vidibus/recording/backend/rtmpdump.rb
Constant Summary collapse
- PROTOCOLS =
%[rtmp rtmpt rtmpe rtmpte rtmps rtmpts]
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#live ⇒ Object
Returns the value of attribute live.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#stream ⇒ Object
Returns the value of attribute stream.
Class Method Summary collapse
Instance Method Summary collapse
-
#command ⇒ Object
Command for starting the recording.
-
#detect_error(string) ⇒ Object
Detect error from stdout or stderr.
-
#extract_metadata(string) ⇒ Object
Extract metadata from stdout or stderr.
-
#initialize(attributes) ⇒ Rtmpdump
constructor
Sets up a new dumper.
Constructor Details
#initialize(attributes) ⇒ Rtmpdump
Sets up a new dumper.
Required attributes:
:stream, :file
Optional:
:live
24 25 26 27 28 29 30 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 24 def initialize(attributes) self.stream = attributes[:stream] self.file = attributes[:file] self.live = attributes[:live] raise ConfigurationError.new('No output file defined') unless file raise ConfigurationError.new('No input stream given') unless stream end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 6 def file @file end |
#live ⇒ Object
Returns the value of attribute live.
6 7 8 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 6 def live @live end |
#metadata ⇒ Object
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 6 def @metadata end |
#stream ⇒ Object
Returns the value of attribute stream.
6 7 8 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 6 def stream @stream end |
Class Method Details
.executable ⇒ Object
12 13 14 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 12 def self.executable @executable || 'rtmpdump' end |
.executable=(path) ⇒ Object
8 9 10 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 8 def self.executable=(path) @executable = path end |
Instance Method Details
#command ⇒ Object
Command for starting the recording.
33 34 35 36 37 38 39 40 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 33 def command args = [].tap do |a| a << "-r #{stream}" a << "-o #{file}" a << "--live" if live end %(#{self.class.executable} #{args.join(" ")} 2>&1) end |
#detect_error(string) ⇒ Object
Detect error from stdout or stderr. Output delivered by rtmpdump looks like this:
RTMPDump v2.4 © 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team Connecting … ERROR: Problem accessing the DNS. (addr: whatever.domain)
90 91 92 93 94 95 96 97 98 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 90 def detect_error(string) if error = string[/(?:ERROR\:\ (.+))/,1] case error when 'rtmp server sent error' else raise RuntimeError.new($1) end end end |
#extract_metadata(string) ⇒ Object
Extract metadata from stdout or stderr. Output delivered by rtmpdump looks like this:
RTMPDump v2.2 © 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team Connecting … Starting Live Stream Metadata:
author
copyright
description
keywords
rating
title
presetname Custom
creationdate Mon Jan 17 15:22:50 2011
videodevice Osprey-210 Video Device 1
framerate 25.00
width 680.00
height 394.00
videocodecid avc1
videodatarate 650.00
avclevel 31.00
avcprofile 66.00
videokeyframe_frequency5.00
audiodevice Osprey-210 Audio Device 1
audiosamplerate 22050.00
audiochannels 1.00
audioinputvolume 75.00
audiocodecid .mp3
audiodatarate 48.00
74 75 76 77 78 79 80 |
# File 'lib/vidibus/recording/backend/rtmpdump.rb', line 74 def (string) prefix = /(?:INFO\:\ *)/ if string.match(/INFO\:/) # INFO: gets prepended since v2.3 if = string.match(/#{prefix}Metadata\:\n(.+)\Z/m) tuples = $1.scan(/#{prefix}([^\n\ \d]+)\ +([^\ \n][^\n]+)\n/) self. = Hash[tuples] end end |