vcs_ruby 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/lib/libAV/libav.rb CHANGED
@@ -1,151 +1,151 @@
1
- #
2
- # libAV Abstraction
3
- #
4
-
5
- require 'capturer'
6
- require 'command'
7
-
8
- module VCSRuby
9
- class LibAV < Capturer
10
-
11
- HEADER = 10
12
-
13
- ENCODING_SUPPORT = 2
14
- VIDEO_CODEC = 3
15
- NAME = 8
16
-
17
- attr_reader :info, :video_streams, :audio_streams
18
-
19
- def initialize video
20
- @video = video
21
- @avconv = Command.new :libav, 'avconv'
22
- @avprobe = Command.new :libav, 'avprobe'
23
-
24
- detect_version if available?
25
- end
26
-
27
- def file_valid?
28
- return probe_meta_information
29
- end
30
-
31
- def name
32
- :libav
33
- end
34
-
35
- def available?
36
- @avconv.available? && @avprobe.available?
37
- end
38
-
39
-
40
- def detect_version
41
- info = @avconv.execute('-version')
42
- match = /avconv ([\d|.|-|:]*)/.match(info)
43
- if match
44
- @version = match[1]
45
- end
46
- end
47
-
48
-
49
-
50
- def grab time, image_path
51
- @avconv.execute "-y -ss #{time.total_seconds} -i \"#{@video.full_path}\" -an -dframes 1 -vframes 1 -vcodec #{format} -f rawvideo \"#{image_path}\""
52
- end
53
-
54
- def available_formats
55
- # Ordered by priority
56
- image_formats = ['png', 'tiff', 'bmp', 'mjpeg']
57
- formats = []
58
-
59
- list = @avprobe.execute "-codecs"
60
- list.lines.drop(HEADER).each do |codec|
61
- name, e, v = format_split(codec)
62
- formats << name if image_formats.include?(name) && e && v
63
- end
64
-
65
- image_formats.select{ |format| formats.include?(format) }.map(&:to_sym)
66
- end
67
-
68
- def to_s
69
- "LibAV #{@version}"
70
- end
71
-
72
- private
73
- def format_split line
74
- correction = 0
75
- unless line[0] == ' '
76
- correction = 1
77
- end
78
- e = line[ENCODING_SUPPORT - correction] == 'E'
79
- v = line[VIDEO_CODEC - correction] == 'V'
80
-
81
- name = line[NAME-correction..-1].split(' ', 2).first
82
- return name, e, v
83
- rescue
84
- return nil, false, false
85
- end
86
-
87
- def check_cache
88
- unless @cache
89
- @cache = @avprobe.execute("\"#{@video.full_path}\" -show_format -show_streams", "2>&1")
90
- end
91
- end
92
-
93
- def extract_format regexp
94
- @cache.scan(regexp) do |format|
95
- @info = LibAVMetaInfo.new(get_hash(format[0]))
96
- return true
97
- end
98
- false
99
- end
100
-
101
- def parse_format
102
- parsed = extract_format(/\[FORMAT\](.*?)\[\/FORMAT\]/m)
103
- unless parsed
104
- parsed = extract_format(/\[format\](.*?)\n\n/m)
105
- end
106
- return parsed
107
- end
108
-
109
- def extract_audio_streams regexp
110
- parsed = false
111
- @cache.scan(regexp) do |stream|
112
- info = get_hash(stream[0])
113
- if info['codec_type'] == 'audio'
114
- @audio_streams << LibAVAudioStream.new(info)
115
- parsed = true
116
- end
117
- end
118
- parsed
119
- end
120
-
121
- def parse_audio_streams
122
- @audio_streams = []
123
- parsed = extract_audio_streams(/\[STREAM\](.*?)\[\/STREAM\]/m)
124
- unless parsed
125
- extract_audio_streams(/\[streams.stream.\d\](.*?)\n\n/m)
126
- end
127
- true
128
- end
129
-
130
- def extract_video_streams regexp
131
- parsed = false
132
- @cache.scan(regexp) do |stream|
133
- info = get_hash(stream[0])
134
- if info['codec_type'] == 'video'
135
- @video_streams << LibAVVideoStream.new(info)
136
- parsed = true
137
- end
138
- end
139
- parsed
140
- end
141
-
142
- def parse_video_streams
143
- @video_streams = []
144
- parsed = extract_video_streams(/\[STREAM\](.*?)\[\/STREAM\]/m)
145
- unless parsed
146
- parsed = extract_video_streams(/\[streams.stream.\d\](.*?)\n\n/m)
147
- end
148
- true
149
- end
150
- end
151
- end
1
+ #
2
+ # libAV Abstraction
3
+ #
4
+
5
+ require 'capturer'
6
+ require 'command'
7
+
8
+ module VCSRuby
9
+ class LibAV < Capturer
10
+
11
+ HEADER = 10
12
+
13
+ ENCODING_SUPPORT = 2
14
+ VIDEO_CODEC = 3
15
+ NAME = 8
16
+
17
+ attr_reader :info, :video_streams, :audio_streams
18
+
19
+ def initialize video
20
+ @video = video
21
+ @avconv = Command.new :libav, 'avconv'
22
+ @avprobe = Command.new :libav, 'avprobe'
23
+
24
+ detect_version if available?
25
+ end
26
+
27
+ def file_valid?
28
+ return probe_meta_information
29
+ end
30
+
31
+ def name
32
+ :libav
33
+ end
34
+
35
+ def available?
36
+ @avconv.available? && @avprobe.available?
37
+ end
38
+
39
+
40
+ def detect_version
41
+ info = @avconv.execute('-version')
42
+ match = /avconv ([\d|.|-|:]*)/.match(info)
43
+ if match
44
+ @version = match[1]
45
+ end
46
+ end
47
+
48
+
49
+
50
+ def grab time, image_path
51
+ @avconv.execute "-y -ss #{time.total_seconds} -i \"#{@video.full_path}\" -an -dframes 1 -vframes 1 -vcodec #{format} -f rawvideo \"#{image_path}\""
52
+ end
53
+
54
+ def available_formats
55
+ # Ordered by priority
56
+ image_formats = ['png', 'tiff', 'bmp', 'mjpeg']
57
+ formats = []
58
+
59
+ list = @avprobe.execute "-codecs"
60
+ list.lines.drop(HEADER).each do |codec|
61
+ name, e, v = format_split(codec)
62
+ formats << name if image_formats.include?(name) && e && v
63
+ end
64
+
65
+ image_formats.select{ |format| formats.include?(format) }.map(&:to_sym)
66
+ end
67
+
68
+ def to_s
69
+ "LibAV #{@version}"
70
+ end
71
+
72
+ private
73
+ def format_split line
74
+ correction = 0
75
+ unless line[0] == ' '
76
+ correction = 1
77
+ end
78
+ e = line[ENCODING_SUPPORT - correction] == 'E'
79
+ v = line[VIDEO_CODEC - correction] == 'V'
80
+
81
+ name = line[NAME-correction..-1].split(' ', 2).first
82
+ return name, e, v
83
+ rescue
84
+ return nil, false, false
85
+ end
86
+
87
+ def check_cache
88
+ unless @cache
89
+ @cache = @avprobe.execute("\"#{@video.full_path}\" -show_format -show_streams", "2>&1")
90
+ end
91
+ end
92
+
93
+ def extract_format regexp
94
+ @cache.scan(regexp) do |format|
95
+ @info = LibAVMetaInfo.new(get_hash(format[0]))
96
+ return true
97
+ end
98
+ false
99
+ end
100
+
101
+ def parse_format
102
+ parsed = extract_format(/\[FORMAT\](.*?)\[\/FORMAT\]/m)
103
+ unless parsed
104
+ parsed = extract_format(/\[format\](.*?)\n\n/m)
105
+ end
106
+ return parsed
107
+ end
108
+
109
+ def extract_audio_streams regexp
110
+ parsed = false
111
+ @cache.scan(regexp) do |stream|
112
+ info = get_hash(stream[0])
113
+ if info['codec_type'] == 'audio'
114
+ @audio_streams << LibAVAudioStream.new(info)
115
+ parsed = true
116
+ end
117
+ end
118
+ parsed
119
+ end
120
+
121
+ def parse_audio_streams
122
+ @audio_streams = []
123
+ parsed = extract_audio_streams(/\[STREAM\](.*?)\[\/STREAM\]/m)
124
+ unless parsed
125
+ extract_audio_streams(/\[streams.stream.\d\](.*?)\n\n/m)
126
+ end
127
+ true
128
+ end
129
+
130
+ def extract_video_streams regexp
131
+ parsed = false
132
+ @cache.scan(regexp) do |stream|
133
+ info = get_hash(stream[0])
134
+ if info['codec_type'] == 'video'
135
+ @video_streams << LibAVVideoStream.new(info)
136
+ parsed = true
137
+ end
138
+ end
139
+ parsed
140
+ end
141
+
142
+ def parse_video_streams
143
+ @video_streams = []
144
+ parsed = extract_video_streams(/\[STREAM\](.*?)\[\/STREAM\]/m)
145
+ unless parsed
146
+ parsed = extract_video_streams(/\[streams.stream.\d\](.*?)\n\n/m)
147
+ end
148
+ true
149
+ end
150
+ end
151
+ end
@@ -1,38 +1,38 @@
1
- #
2
- # Implementes AudioStream Interface for libAV
3
- #
4
-
5
- # AudioStream = Struct.new(:codec, :channels, :channel_layout, :sample_rate, :bit_rate, :raw)
6
- module VCSRuby
7
- class LibAVAudioStream
8
- attr_reader :raw
9
-
10
- def initialize audio_stream
11
- @raw = audio_stream
12
- end
13
-
14
- def codec short = false
15
- if short
16
- @raw['codec_name']
17
- else
18
- @raw['codec_long_name']
19
- end
20
- end
21
-
22
- def channels
23
- @raw['channels'].to_i
24
- end
25
-
26
- def channel_layout
27
- @raw['channel_layout']
28
- end
29
-
30
- def sample_rate
31
- @raw['sample_rate'].to_i
32
- end
33
-
34
- def bit_rate
35
- @raw['bit_rate'].to_i
36
- end
37
- end
1
+ #
2
+ # Implementes AudioStream Interface for libAV
3
+ #
4
+
5
+ # AudioStream = Struct.new(:codec, :channels, :channel_layout, :sample_rate, :bit_rate, :raw)
6
+ module VCSRuby
7
+ class LibAVAudioStream
8
+ attr_reader :raw
9
+
10
+ def initialize audio_stream
11
+ @raw = audio_stream
12
+ end
13
+
14
+ def codec short = false
15
+ if short
16
+ @raw['codec_name']
17
+ else
18
+ @raw['codec_long_name']
19
+ end
20
+ end
21
+
22
+ def channels
23
+ @raw['channels'].to_i
24
+ end
25
+
26
+ def channel_layout
27
+ @raw['channel_layout']
28
+ end
29
+
30
+ def sample_rate
31
+ @raw['sample_rate'].to_i
32
+ end
33
+
34
+ def bit_rate
35
+ @raw['bit_rate'].to_i
36
+ end
37
+ end
38
38
  end
@@ -1,37 +1,37 @@
1
- #
2
- # Implementes MetaInfo Interface for libAV
3
- #
4
-
5
- # MetaInformation = Struct.new(:duration, :bit_rate, :size, :format, :extension, :raw)
6
-
7
- require_relative '../time_index'
8
-
9
- module VCSRuby
10
- class LibAVMetaInfo
11
- attr_reader :raw
12
-
13
- def initialize meta_info
14
- @raw = meta_info
15
- end
16
-
17
- def duration
18
- TimeIndex.new(@raw['duration'].to_f)
19
- end
20
-
21
- def bit_rate
22
- @raw['bit_rate'].to_i
23
- end
24
-
25
- def size
26
- @raw['size'].to_i
27
- end
28
-
29
- def format
30
- @raw['format_long_name']
31
- end
32
-
33
- def extension
34
- @raw['format_name']
35
- end
36
- end
1
+ #
2
+ # Implementes MetaInfo Interface for libAV
3
+ #
4
+
5
+ # MetaInformation = Struct.new(:duration, :bit_rate, :size, :format, :extension, :raw)
6
+
7
+ require_relative '../time_index'
8
+
9
+ module VCSRuby
10
+ class LibAVMetaInfo
11
+ attr_reader :raw
12
+
13
+ def initialize meta_info
14
+ @raw = meta_info
15
+ end
16
+
17
+ def duration
18
+ TimeIndex.new(@raw['duration'].to_f)
19
+ end
20
+
21
+ def bit_rate
22
+ @raw['bit_rate'].to_i
23
+ end
24
+
25
+ def size
26
+ @raw['size'].to_i
27
+ end
28
+
29
+ def format
30
+ @raw['format_long_name']
31
+ end
32
+
33
+ def extension
34
+ @raw['format_name']
35
+ end
36
+ end
37
37
  end
@@ -1,62 +1,64 @@
1
- #
2
- # Implementes VideoStream Interface for libAV
3
- #
4
-
5
- # VideoStream = Struct.new(:width, :height, :codec, :color_space, :bit_rate, :frame_rate, :aspect_ratio, :raw)
6
-
7
- module VCSRuby
8
- class LibAVVideoStream
9
- attr_reader :raw
10
-
11
- def initialize video_stream
12
- @raw = video_stream
13
- end
14
-
15
- def width
16
- @raw['width'].to_i
17
- end
18
-
19
- def height
20
- @raw['height'].to_i
21
- end
22
-
23
- def codec short = false
24
- if short
25
- @raw['codec_name']
26
- else
27
- @raw['codec_long_name']
28
- end
29
- end
30
-
31
- def color_space
32
- if ["unknown", "", nil].include? @raw['color_space']
33
- @raw['pix_fmt']
34
- else
35
- @raw['color_space']
36
- end
37
- end
38
-
39
- def bit_rate
40
- @raw['bit_rate'].to_i
41
- end
42
-
43
-
44
- def frame_rate
45
- if @raw['r_frame_rate']
46
- @raw['r_frame_rate'].to_r
47
- elsif @raw['avg_frame_rate']
48
- @raw['avg_frame_rate'].to_r
49
- end
50
- end
51
-
52
- def aspect_ratio
53
- colon = ":"
54
- if @raw['display_aspect_ratio'].include? colon
55
- w,h = @raw['display_aspect_ratio'].split(colon)
56
- Rational(w,h)
57
- else
58
- @raw['display_aspect_ratio'].to_f
59
- end
60
- end
61
- end
62
- end
1
+ #
2
+ # Implementes VideoStream Interface for libAV
3
+ #
4
+
5
+ # VideoStream = Struct.new(:width, :height, :codec, :color_space, :bit_rate, :frame_rate, :aspect_ratio, :raw)
6
+
7
+ module VCSRuby
8
+ class LibAVVideoStream
9
+ attr_reader :raw
10
+
11
+ def initialize video_stream
12
+ @raw = video_stream
13
+ end
14
+
15
+ def width
16
+ @raw['width'].to_i
17
+ end
18
+
19
+ def height
20
+ @raw['height'].to_i
21
+ end
22
+
23
+ def codec short = false
24
+ if short
25
+ @raw['codec_name']
26
+ else
27
+ @raw['codec_long_name']
28
+ end
29
+ end
30
+
31
+ def color_space
32
+ if ["unknown", "", nil].include? @raw['color_space']
33
+ @raw['pix_fmt']
34
+ else
35
+ @raw['color_space']
36
+ end
37
+ end
38
+
39
+ def bit_rate
40
+ @raw['bit_rate'].to_i
41
+ end
42
+
43
+
44
+ def frame_rate
45
+ if @raw['r_frame_rate']
46
+ @raw['r_frame_rate'].to_r
47
+ elsif @raw['avg_frame_rate']
48
+ @raw['avg_frame_rate'].to_r
49
+ end
50
+ end
51
+
52
+ def aspect_ratio
53
+ return nil if @raw['display_aspect_ratio'] == nil
54
+
55
+ colon = ":"
56
+ if @raw['display_aspect_ratio'].include? colon
57
+ w,h = @raw['display_aspect_ratio'].split(colon)
58
+ Rational(w,h)
59
+ else
60
+ @raw['display_aspect_ratio'].to_f
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/oldstyle.yml CHANGED
@@ -1,22 +1,22 @@
1
- style:
2
- header:
3
- font: Nimbus-Mono-L-Bold
4
- size: 18
5
- color: Green
6
- background: Black
7
- title:
8
- font: Nimbus-Mono-L-Bold
9
- size: 40
10
- color: Green
11
- background: Black
12
- color: White
13
- background: Black
14
- contact:
15
- background: Black
16
- signature:
17
- font: Nimbus-Mono-L-Bold
18
- size: 18
19
- color: Green
20
- background: Black
21
- filter:
22
- softshadow: false
1
+ style:
2
+ header:
3
+ font: Nimbus-Mono-L-Bold
4
+ size: 18
5
+ color: Green
6
+ background: Black
7
+ title:
8
+ font: Nimbus-Mono-L-Bold
9
+ size: 40
10
+ color: Green
11
+ background: Black
12
+ color: White
13
+ background: Black
14
+ contact:
15
+ background: Black
16
+ signature:
17
+ font: Nimbus-Mono-L-Bold
18
+ size: 18
19
+ color: Green
20
+ background: Black
21
+ filter:
22
+ softshadow: false
data/lib/stream.rb CHANGED
@@ -1,24 +1,24 @@
1
- #
2
- # Represents a stream in a video
3
- #
4
-
5
- require 'vcs'
6
-
7
- module VCSRuby
8
- class Stream
9
- def initialize stream
10
- @stream = stream
11
- create_accessors
12
- end
13
-
14
- def create_accessors
15
- @stream.each do |key, value|
16
- self.class.send :define_method, key.to_sym do
17
- return @stream[key]
18
- end
19
- end
20
- end
21
-
22
- private
23
- end
24
- end
1
+ #
2
+ # Represents a stream in a video
3
+ #
4
+
5
+ require 'vcs'
6
+
7
+ module VCSRuby
8
+ class Stream
9
+ def initialize stream
10
+ @stream = stream
11
+ create_accessors
12
+ end
13
+
14
+ def create_accessors
15
+ @stream.each do |key, value|
16
+ self.class.send :define_method, key.to_sym do
17
+ return @stream[key]
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+ end
24
+ end