qtrefmovie 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +76 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/qtrefmovie.rb +513 -0
- data/qtrefmovie.gemspec +55 -0
- data/test/helper.rb +10 -0
- data/test/sample.mov +0 -0
- data/test/test_qtrefmovie.rb +15 -0
- metadata +92 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jonathan Block
|
2
|
+
Based on PHPRefMovie Copyright (C) 2003 Juergen Enge (GPL V2 or later)
|
3
|
+
http://www.phpclasses.org/browse/file/7719.html
|
4
|
+
juergen@info-age.net
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU General Public License
|
8
|
+
as published by the Free Software Foundation; either version 2
|
9
|
+
of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU General Public License
|
17
|
+
along with this program; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19
|
+
|
20
|
+
The GPL V2 is available at http://www.gnu.org/licenses/gpl-2.0.html
|
data/README.rdoc
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
= QTRefMovie
|
2
|
+
|
3
|
+
QTRefMovie is based on PHPRefMovie Copyright (C) 2003 Juergen Enge (GPL V2 or later)
|
4
|
+
http://www.phpclasses.org/browse/file/7719.html
|
5
|
+
juergen@info-age.net
|
6
|
+
|
7
|
+
Most of the code design is Juergen's.
|
8
|
+
Most code comments are from Apple's QuickTime File Format specification.
|
9
|
+
I just translated the code to Ruby, simplified usage, and made it a Ruby Gem.
|
10
|
+
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
* Install the qtrefmovie gem
|
15
|
+
|
16
|
+
* Load the library (some or all may not be needed)
|
17
|
+
require 'rubygems'
|
18
|
+
gem 'qtrefmovie'
|
19
|
+
require 'lib/qtrefmovie'
|
20
|
+
|
21
|
+
* Make a reference movie
|
22
|
+
movie = QTRefMovie::QTMovie.new [{:reference => "rtsp://127.0.0.1:80/test.mov",
|
23
|
+
:data_rate => 'intranet',
|
24
|
+
:cpu_speed => 'fast'},
|
25
|
+
{:reference => "rtsp://127.0.0.1:80/test2.mov",
|
26
|
+
:data_rate => 't1',
|
27
|
+
:quality => 650}]
|
28
|
+
File.open("refmovie.mov", "w") { |f| f.write movie.to_s }
|
29
|
+
|
30
|
+
* Make the reference movie useful
|
31
|
+
This part's up to you
|
32
|
+
|
33
|
+
|
34
|
+
== Options
|
35
|
+
|
36
|
+
You can have as many movie references as you'd like within a reference movie. The QuickTime client will consider the parameters of each reference, as well as its own settings, to decide which reference to actually load.
|
37
|
+
|
38
|
+
Each reference may have the following parameters:
|
39
|
+
|
40
|
+
reference:: (required) A URL pointing to a distinct version of the movie available somewhere online
|
41
|
+
Any URL accessible to the client and playable by QuickTime
|
42
|
+
|
43
|
+
data_rate:: (optional) The minimum connection speed for displaying this version
|
44
|
+
A 32-bit number, or: '28.8 modem', '56k modem', 'isdn', 'dual isdn',
|
45
|
+
'256 kbps', '384 kbps', '512 kbps', '768 kbps', '1 mbps', 't1', 'intranet'
|
46
|
+
|
47
|
+
cpu_speed:: (optional) An indicator of processor capability needed to view this version
|
48
|
+
A 32-bit number divisible by 100, or: 'very slow', 'slow', 'medium', 'fast', 'very fast'
|
49
|
+
|
50
|
+
quality:: (optional) A relative measure of the quality of this version compared to others referenced
|
51
|
+
A 32-bit number
|
52
|
+
|
53
|
+
|
54
|
+
== More Information
|
55
|
+
|
56
|
+
Juergen provided detailed comments with the code, which I have maintained intact.
|
57
|
+
These are largely from Apple's QuickTime File Format specification.
|
58
|
+
|
59
|
+
Apple's QuickTime File Format Specification is currently available at this URL:
|
60
|
+
http://developer.apple.com/mac/library/documentation/QuickTime/QTFF/
|
61
|
+
|
62
|
+
|
63
|
+
== Note on Patches/Pull Requests
|
64
|
+
|
65
|
+
* Fork the project.
|
66
|
+
* Make your feature addition or bug fix.
|
67
|
+
* Add tests for it. This is important so I don't break it in a
|
68
|
+
future version unintentionally.
|
69
|
+
* Commit, do not mess with rakefile, version, or history.
|
70
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
71
|
+
* Send me a pull request. Bonus points for topic branches.
|
72
|
+
|
73
|
+
|
74
|
+
== Copyright
|
75
|
+
|
76
|
+
Copyright (c) 2010 Jonathan Block. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "qtrefmovie"
|
8
|
+
gem.summary = %Q{Simple code for generating QuickTime Reference Movies from Ruby}
|
9
|
+
gem.description = %Q{QTRefMovie is a simple tool for generating QuickTime Reference Movie files from a Ruby script.}
|
10
|
+
gem.email = "jonblock@jonblock.com"
|
11
|
+
gem.homepage = "http://github.com/jonblock/qtrefmovie"
|
12
|
+
gem.authors = ["Jonathan Block"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "qtrefmovie #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/qtrefmovie.rb
ADDED
@@ -0,0 +1,513 @@
|
|
1
|
+
# Copyright (c) 2010 Jonathan Block
|
2
|
+
# jonblock@jonblock.com
|
3
|
+
# Based on PHPRefMovie Copyright (C) 2003 Juergen Enge (GPL V2 or later)
|
4
|
+
# http://www.phpclasses.org/browse/file/7719.html
|
5
|
+
# juergen@info-age.net
|
6
|
+
#
|
7
|
+
# Translated to Ruby 2010 by Jonathan Block
|
8
|
+
# Most of the code design is Juergen's.
|
9
|
+
# Most code comments are from Apple's QuickTime File Format specification.
|
10
|
+
# I just translated it to Ruby, simplified usage, and made it a Ruby Gem.
|
11
|
+
# Please see the README.
|
12
|
+
|
13
|
+
|
14
|
+
module QTRefMovie
|
15
|
+
|
16
|
+
# USAGE
|
17
|
+
def qt_sample_code
|
18
|
+
ref_movie = QTRefMovie.new
|
19
|
+
|
20
|
+
data_reference = QTDataReference.new "rtsp://127.0.0.1:80/test.mov"
|
21
|
+
data_rate = QTDataRate.new("intranet")
|
22
|
+
cpu_speed = QTCPUSpeed.new("fast")
|
23
|
+
|
24
|
+
movie_descriptor = QTRefMovieDescriptor.new
|
25
|
+
movie_descriptor.add_chunk data_reference
|
26
|
+
movie_descriptor.add_chunk data_rate
|
27
|
+
movie_descriptor.add_chunk cpu_speed
|
28
|
+
|
29
|
+
ref_movie.add_chunk movie_descriptor
|
30
|
+
|
31
|
+
data_reference = QTDataReference.new "rtsp://127.0.0.1:80/test2.mov"
|
32
|
+
data_rate = QTDataRate.new("t1")
|
33
|
+
cpu_speed = QTQuality.new(650)
|
34
|
+
|
35
|
+
movie_descriptor = QTRefMovieDescriptor.new
|
36
|
+
movie_descriptor.add_chunk data_reference
|
37
|
+
movie_descriptor.add_chunk data_rate
|
38
|
+
movie_descriptor.add_chunk cpu_speed
|
39
|
+
|
40
|
+
ref_movie.add_chunk movie_descriptor
|
41
|
+
|
42
|
+
movie = QTMovie.new
|
43
|
+
movie.add_chunk ref_movie
|
44
|
+
movie.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def qt_easier_sample_code
|
48
|
+
movie = QTMovie.new [{:reference => "rtsp://127.0.0.1:80/test.mov",
|
49
|
+
:data_rate => 'intranet',
|
50
|
+
:cpu_speed => 'fast'},
|
51
|
+
{:reference => "rtsp://127.0.0.1:80/test2.mov",
|
52
|
+
:data_rate => 't1',
|
53
|
+
:quality => 650}]
|
54
|
+
movie.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
class QTBase
|
59
|
+
def initialize
|
60
|
+
@list = []
|
61
|
+
@type = ' '
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_chunk( chunk, pos = -1 )
|
65
|
+
if pos < 0
|
66
|
+
@list << chunk
|
67
|
+
else
|
68
|
+
@list[pos] = chunk
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def size
|
73
|
+
size = 0
|
74
|
+
(0..(@list.count-1)).each do |i|
|
75
|
+
size += @list[i].size
|
76
|
+
end
|
77
|
+
size += 2*4
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
str = [size].pack('N')
|
82
|
+
str += @type
|
83
|
+
if @list.count > 0
|
84
|
+
(0..(@list.count-1)).each do |i|
|
85
|
+
str += @list[i].to_s
|
86
|
+
end
|
87
|
+
end
|
88
|
+
str
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# The Movie Atom
|
94
|
+
# You use movie atoms to specify the information that defines a movie-that is, the
|
95
|
+
# information that allows your application to understand the data that is stored in the
|
96
|
+
# movie data atom. The movie atom normally contains a movie header atom, which defines
|
97
|
+
# the time scale and duration information for the entire movie, as well as its display
|
98
|
+
# characteristics. In addition, the movie atom contains a track atom for each track in
|
99
|
+
# the movie.
|
100
|
+
#
|
101
|
+
# The movie atom has an atom type of 'moov'. It contains other types of atoms, including
|
102
|
+
# at least one of three possible parent atoms-the movie header atom ('mvhd'), the
|
103
|
+
# compressed movie atom ('cmov'), or a reference movie atom ('rmra'). An uncompressed
|
104
|
+
# movie atom can contain both a movie header atom and a reference movie atom, but it
|
105
|
+
# must contain at least one of the two. It can also contain several other atoms, such
|
106
|
+
# as a clipping atom ( 'clip'), one or more track atoms ( 'trak'), a color table atom
|
107
|
+
# ( 'ctab'), and a user data atom 'udta').
|
108
|
+
#
|
109
|
+
# Compressed movie atoms and reference movie atoms are discussed separately. This
|
110
|
+
# section describes normal uncompressed movie atoms.
|
111
|
+
#
|
112
|
+
# A movie atom may contain the following information.
|
113
|
+
#
|
114
|
+
#
|
115
|
+
# Size
|
116
|
+
# The number of bytes in this movie atom.
|
117
|
+
#
|
118
|
+
# Type
|
119
|
+
# The type of this movie atom; this field must be set to 'moov'.
|
120
|
+
#
|
121
|
+
# Movie header atom
|
122
|
+
# See "Movie Header Atoms" for more information.
|
123
|
+
#
|
124
|
+
# Movie clipping atom
|
125
|
+
# See "Clipping Atoms" for more information.
|
126
|
+
#
|
127
|
+
# Track list atoms
|
128
|
+
# See "Track Atoms" for details on track atoms and their associated atoms.
|
129
|
+
#
|
130
|
+
# User data atom
|
131
|
+
# See "User Data Atoms" for more infomation about user data atoms.
|
132
|
+
#
|
133
|
+
# Color table atom
|
134
|
+
# See"Color Table Atoms" for a discussion of the color table atom.
|
135
|
+
#
|
136
|
+
# Compressed movie atom
|
137
|
+
# See "Compressed Movie Resources" for a discussion of compressed movie atoms.
|
138
|
+
#
|
139
|
+
# Reference movie atom
|
140
|
+
# See "Reference Movies" for a discussion of reference movie atoms.
|
141
|
+
|
142
|
+
class QTMovie < QTBase
|
143
|
+
def initialize( options = nil )
|
144
|
+
super()
|
145
|
+
@type = 'moov'
|
146
|
+
unless options.nil?
|
147
|
+
ref_movie = QTRefMovie.new
|
148
|
+
options.each do |opt|
|
149
|
+
movie_descriptor = QTRefMovieDescriptor.new
|
150
|
+
movie_descriptor.add_chunk QTDataReference.new opt[:reference] unless opt[:reference].nil?
|
151
|
+
movie_descriptor.add_chunk QTDataRate.new opt[:data_rate] unless opt[:data_rate].nil?
|
152
|
+
movie_descriptor.add_chunk QTCPUSpeed.new opt[:cpu_speed] unless opt[:cpu_speed].nil?
|
153
|
+
movie_descriptor.add_chunk QTQuality.new opt[:quality ] unless opt[:quality ].nil?
|
154
|
+
ref_movie.add_chunk movie_descriptor
|
155
|
+
end
|
156
|
+
add_chunk ref_movie
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
#def set_ref_movie( qt_ref_movie )
|
161
|
+
# add_chunk qt_ref_movie, 0
|
162
|
+
#end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
# Reference Movie Atom
|
167
|
+
# A reference movie atom contains references to one or more movies. It can optionally
|
168
|
+
# contain a list of system requirements in order for each movie to play, and a quality
|
169
|
+
# rating for each movie. It is typically used to specify a list of alternate movies to
|
170
|
+
# be played under different conditions.
|
171
|
+
#
|
172
|
+
# A reference movie atom's parent is always a movie atom ('moov'). Only one reference
|
173
|
+
# movie atom is allowed in a given movie atom.
|
174
|
+
#
|
175
|
+
#
|
176
|
+
# A reference movie atom may contain the following information.
|
177
|
+
#
|
178
|
+
# Size
|
179
|
+
# The number of bytes in this reference movie atom.
|
180
|
+
#
|
181
|
+
# Type
|
182
|
+
# The type of this atom; this field must be set to 'rmra'.
|
183
|
+
#
|
184
|
+
# Reference movie descriptor atom
|
185
|
+
# A reference movie atom must contain at least one reference movie descriptor atom, and
|
186
|
+
# typically contains more than one. See "Reference Movie Descriptor Atom" for more
|
187
|
+
# information.
|
188
|
+
|
189
|
+
class QTRefMovie < QTBase
|
190
|
+
def initialize
|
191
|
+
super
|
192
|
+
@type = 'rmra'
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# Reference Movie Descriptor Atom
|
198
|
+
# Each reference movie descriptor atom contains other atoms that describe where a
|
199
|
+
# particular movie can be found, and optionally what the system requirements are to
|
200
|
+
# play that movie, as well as an optional quality rating for that movie.
|
201
|
+
#
|
202
|
+
# A reference movie descriptor atom's parent is always a movie reference atom ('rmra').
|
203
|
+
# Multiple reference movie descriptor atoms are allowed in a given movie reference atom,
|
204
|
+
# and more than one is usually present.
|
205
|
+
#
|
206
|
+
# A reference movie descriptor atom may contain the following information.
|
207
|
+
#
|
208
|
+
#
|
209
|
+
#
|
210
|
+
# Size
|
211
|
+
# The number of bytes in this reference movie descriptor atom.
|
212
|
+
#
|
213
|
+
# Type
|
214
|
+
# The type of this atom; this field must be set to 'rmda'.
|
215
|
+
#
|
216
|
+
# Data reference atom
|
217
|
+
# Each reference movie atom must contain exactly one data reference atom. See "Data
|
218
|
+
# Reference Atoms" for more information.
|
219
|
+
#
|
220
|
+
# Data rate atom
|
221
|
+
# A reference movie atom may contain an optional data rate atom. Only one data rate
|
222
|
+
# atom can be present. See "Data Rate Atom" for more information.
|
223
|
+
#
|
224
|
+
# CPU speed atom
|
225
|
+
# A reference movie atom may contain an optional CPU speed atom. Only one CPU speed
|
226
|
+
# atom can be present. See "CPU Speed Atom" for more information.
|
227
|
+
#
|
228
|
+
# Version check atom
|
229
|
+
# A reference movie atom may contain an optional version check atom. Multiple version
|
230
|
+
# check atoms can be present. See "Version Check Atom" for more information.
|
231
|
+
#
|
232
|
+
# Component detect atom
|
233
|
+
# A reference movie atom may contain an optional component detect atom. Multiple
|
234
|
+
# component detect atoms can be present. See "Component Detect Atom" for more
|
235
|
+
# information.
|
236
|
+
#
|
237
|
+
# Quality atom
|
238
|
+
# A reference movie atom may contain an optional quality atom. Only one quality atom
|
239
|
+
# can be present. See "Quality Atom" for more information
|
240
|
+
|
241
|
+
class QTRefMovieDescriptor < QTBase
|
242
|
+
def initialize
|
243
|
+
super
|
244
|
+
@type = 'rmda'
|
245
|
+
end
|
246
|
+
|
247
|
+
#def set_data_reference( qt_data_reference )
|
248
|
+
# add_chunk qt_data_reference, 0
|
249
|
+
#end
|
250
|
+
|
251
|
+
#def set_data_rate( qt_data_rate )
|
252
|
+
# add_chunk qt_data_rate, 1
|
253
|
+
#end
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
# Data Reference Atom
|
258
|
+
# A data reference atom contains the information necessary to locate a movie, or a
|
259
|
+
# stream or file that QuickTime can play, typically in the form of a URL or a file
|
260
|
+
# alias.
|
261
|
+
#
|
262
|
+
# Only one data reference atom is allowed in a given movie reference descriptor atom.
|
263
|
+
#
|
264
|
+
#
|
265
|
+
#
|
266
|
+
# A data reference atom may contain the following information.
|
267
|
+
#
|
268
|
+
# Size
|
269
|
+
# The number of bytes in this data reference atom.
|
270
|
+
#
|
271
|
+
# Type
|
272
|
+
# The type of this atom; this field must be set to 'rdrf'.
|
273
|
+
#
|
274
|
+
# Flags
|
275
|
+
# A 32-bit integer containing flags. One flag is currently defined: movie is
|
276
|
+
# self-contained. If the least-significant bit is set to 1, the movie is self-contained.
|
277
|
+
# This requires that the parent movie contain a movie header atom as well as a reference
|
278
|
+
# movie atom. In other words, the current 'moov' atom must contain both a 'rmra' atom
|
279
|
+
# and a 'mvhd' atom. To resolve this data reference, an application uses the movie
|
280
|
+
# defined in the movie header atom, ignoring the remainder of the fields in this data
|
281
|
+
# reference atom, which are used only to specify external movies.
|
282
|
+
#
|
283
|
+
# Data reference type
|
284
|
+
# The data reference type. A value of 'alis' indicates a file system alias record. A
|
285
|
+
# value of 'url ' indicates a string containing a uniform resource locator. Note that
|
286
|
+
# the fourth character in 'url ' is an ASCII blank (hex 20).
|
287
|
+
#
|
288
|
+
# Data reference size
|
289
|
+
# The size of the data reference in bytes, expressed as a 32-bit integer.
|
290
|
+
#
|
291
|
+
# Data reference
|
292
|
+
# A data reference to a QuickTime movie, or to a stream or file that QuickTime can play.
|
293
|
+
# If the reference type is 'alis' this field contains the contents of an AliasHandle.
|
294
|
+
# If the reference type is 'url ' this field contains a null-terminated string that can
|
295
|
+
# be interpreted as a URL. The URL can be absolute or relative, and can specify any
|
296
|
+
# protocol that QuickTime supports, including http://, ftp://, rtsp://, file:///, and
|
297
|
+
# data:.
|
298
|
+
|
299
|
+
class QTDataReference < QTBase
|
300
|
+
def initialize( reference = nil )
|
301
|
+
super()
|
302
|
+
@type = 'rdrf'
|
303
|
+
@flag = 0
|
304
|
+
@ref_type = 'url '
|
305
|
+
@size = 0
|
306
|
+
@reference = ''
|
307
|
+
set_reference(reference) unless reference.nil?
|
308
|
+
end
|
309
|
+
|
310
|
+
def set_reference( reference )
|
311
|
+
@reference = reference
|
312
|
+
@size = reference.length
|
313
|
+
end
|
314
|
+
|
315
|
+
def size
|
316
|
+
@size + 5 * 4
|
317
|
+
end
|
318
|
+
|
319
|
+
def to_s
|
320
|
+
str = [size].pack('N')
|
321
|
+
str += @type
|
322
|
+
str += [@flag].pack('N')
|
323
|
+
str += @ref_type
|
324
|
+
str += [@size].pack('N')
|
325
|
+
str += @reference
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
# Data Rate Atom
|
331
|
+
# A data rate atom specifies the minimum data rate required to play a movie. This is
|
332
|
+
# normally compared to the connection speed setting in the user's QuickTime Settings
|
333
|
+
# control panel. Applications should play the movie with the highest data rate less
|
334
|
+
# than or equal to the user's connection speed. If the connection speed is slower than
|
335
|
+
# any movie's data rate, applications should play the movie with the lowest data rate.
|
336
|
+
# The movie with the highest data rate is assumed to have the highest quality.
|
337
|
+
#
|
338
|
+
# Only one data rate atom is allowed in a given reference movie descriptor atom.
|
339
|
+
#
|
340
|
+
# A data rate atom may contain the following information.
|
341
|
+
#
|
342
|
+
# Size
|
343
|
+
# The number of bytes in this data rate atom.
|
344
|
+
#
|
345
|
+
# Type
|
346
|
+
# The type of this atom; this field must be set to 'rmdr'.
|
347
|
+
#
|
348
|
+
# Flags
|
349
|
+
# A 32-bit integer that is currently always 0.
|
350
|
+
#
|
351
|
+
# Data rate
|
352
|
+
# The required data rate in bits per second, expressed as a 32-bit integer.
|
353
|
+
|
354
|
+
class QTDataRate < QTBase
|
355
|
+
def initialize( rate = nil )
|
356
|
+
super()
|
357
|
+
@type = 'rmdr'
|
358
|
+
@flag = 0
|
359
|
+
@rate = 256000
|
360
|
+
set_rate(rate) unless rate.nil?
|
361
|
+
end
|
362
|
+
|
363
|
+
def rates
|
364
|
+
{ '28.8 modem' => 28800,
|
365
|
+
'56k modem' => 56000,
|
366
|
+
'isdn' => 64000,
|
367
|
+
'dual isdn' => 128000,
|
368
|
+
'256 kbps' => 256000,
|
369
|
+
'384 kbps' => 384000,
|
370
|
+
'512 kbps' => 512000,
|
371
|
+
'768 kbps' => 768000,
|
372
|
+
'1 mbps' => 1000000,
|
373
|
+
't1' => 1500000,
|
374
|
+
'intranet' => 2147483647 }
|
375
|
+
end
|
376
|
+
|
377
|
+
def set_rate( rate )
|
378
|
+
@rate = rates[rate] || rate
|
379
|
+
end
|
380
|
+
|
381
|
+
def size
|
382
|
+
4 * 4
|
383
|
+
end
|
384
|
+
|
385
|
+
def to_s
|
386
|
+
str = [size].pack('N')
|
387
|
+
str += @type
|
388
|
+
str += [@flag].pack('N')
|
389
|
+
str += [@rate].pack('N')
|
390
|
+
end
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
|
395
|
+
# CPU Speed Atom
|
396
|
+
# A CPU speed atom specifies the minimum computing power needed to display a movie.
|
397
|
+
# QuickTime performs an internal test to determine the speed of the user's computer.
|
398
|
+
#
|
399
|
+
# This is not a simple measurement of clock speed-it is a measurement of performance
|
400
|
+
# for QuickTime-related operations. Speed is expressed as a relative value between 100
|
401
|
+
# and 2^31, in multiples of 100.
|
402
|
+
#
|
403
|
+
# Note: Typical scores might range from a minimum score of 100, which would describe a
|
404
|
+
# computer as slow as, or slower than, a 166 MHz Pentium or 120 MHz PowerPC, to a
|
405
|
+
# maximum score of 600 for a 500 MHz Pentium III or 400 MHz G4 PowerPC. A computer with
|
406
|
+
# a graphics accelerator and a Gigahertz clock speed might score as high as 1000.
|
407
|
+
# Future computers will score higher.
|
408
|
+
#
|
409
|
+
# Applications should play the movie with the highest specified CPU speed that is less
|
410
|
+
# than or equal to the user's speed. If the user's speed is lower than any movie's CPU
|
411
|
+
# speed, applications should play the movie with the lowest CPU speed requirement. The
|
412
|
+
# movie with the highest CPU speed is assumed to be the highest quality.
|
413
|
+
#
|
414
|
+
# Only one CPU speed atom is allowed in a given reference movie descriptor atom.
|
415
|
+
#
|
416
|
+
#
|
417
|
+
# A CPU speed atom may contain the following information.
|
418
|
+
#
|
419
|
+
# Size
|
420
|
+
# The number of bytes in this CPU speed atom.
|
421
|
+
#
|
422
|
+
# Type
|
423
|
+
# The type of this atom; this field must be set to 'rmcs'.
|
424
|
+
#
|
425
|
+
# Flags
|
426
|
+
# A 32-bit integer that is currently always 0.
|
427
|
+
#
|
428
|
+
# CPU speed
|
429
|
+
# A relative ranking of required computer speed, expressed as a 32-bit integer
|
430
|
+
# divisible by 100, with larger numbers indicating higher speed.
|
431
|
+
|
432
|
+
class QTCPUSpeed < QTBase
|
433
|
+
def initialize( speed = nil )
|
434
|
+
super()
|
435
|
+
@type = 'rmcs'
|
436
|
+
@flag = 0
|
437
|
+
@speed = 500
|
438
|
+
set_speed(speed) unless speed.nil?
|
439
|
+
end
|
440
|
+
|
441
|
+
def speeds
|
442
|
+
{ 'very slow' => 100,
|
443
|
+
'slow' => 300,
|
444
|
+
'medium' => 500,
|
445
|
+
'fast' => 700,
|
446
|
+
'very fast' => 1000 }
|
447
|
+
end
|
448
|
+
|
449
|
+
def set_speed( speed )
|
450
|
+
@speed = speeds[speed] || speed
|
451
|
+
end
|
452
|
+
|
453
|
+
def size
|
454
|
+
4 * 4
|
455
|
+
end
|
456
|
+
|
457
|
+
def to_s
|
458
|
+
str = [size].pack('N')
|
459
|
+
str += @type
|
460
|
+
str += [@flag].pack('N')
|
461
|
+
str += [@speed].pack('N')
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
# Quality Atom
|
467
|
+
# A quality atom describes the relative quality of a movie. This acts as a tie-breaker
|
468
|
+
# if more than one movie meets the specified requirements, and it is not otherwise
|
469
|
+
# obvious which movie should be played.
|
470
|
+
# This would be the case if two qualified movies have the same data rate and CPU speed
|
471
|
+
# requirements, for example, or if one movie requires a higher data rate and another
|
472
|
+
# requires a higher CPU speed, but both can be played on the current system. In these
|
473
|
+
# cases, applications should play the movie with the highest quality, as specified in
|
474
|
+
# the quality atom.
|
475
|
+
# Only one quality atom is allowed in a given reference movie descriptor atom.
|
476
|
+
#
|
477
|
+
# A quality atom may contain the following information.
|
478
|
+
#
|
479
|
+
# Size
|
480
|
+
# The number of bytes in this quality atom.
|
481
|
+
#
|
482
|
+
# Type
|
483
|
+
# The type of this atom; this field must be set to 'rmqu'.
|
484
|
+
#
|
485
|
+
# Quality
|
486
|
+
# The relative quality of the movie, expressed as a 32-bit integer. A larger number indicates higher quality. A unique value should be given to each movie.
|
487
|
+
|
488
|
+
class QTQuality < QTBase
|
489
|
+
def initialize( quality = nil )
|
490
|
+
super()
|
491
|
+
@type = 'rmqu'
|
492
|
+
@flag = 0
|
493
|
+
@quality = 500
|
494
|
+
set_quality(quality) if quality
|
495
|
+
end
|
496
|
+
|
497
|
+
def set_quality( quality )
|
498
|
+
@quality = quality
|
499
|
+
end
|
500
|
+
|
501
|
+
def size
|
502
|
+
4 * 4
|
503
|
+
end
|
504
|
+
|
505
|
+
def to_s
|
506
|
+
str = [size].pack('N')
|
507
|
+
str += @type
|
508
|
+
str += [@flag].pack('N')
|
509
|
+
str += [@quality].pack('N')
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
end
|
data/qtrefmovie.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{qtrefmovie}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jonathan Block"]
|
12
|
+
s.date = %q{2010-08-17}
|
13
|
+
s.description = %q{QTRefMovie is a simple tool for generating QuickTime Reference Movie files from a Ruby script.}
|
14
|
+
s.email = %q{jonblock@jonblock.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/qtrefmovie.rb",
|
27
|
+
"qtrefmovie.gemspec",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/sample.mov",
|
30
|
+
"test/test_qtrefmovie.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/jonblock/qtrefmovie}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Simple code for generating QuickTime Reference Movies from Ruby}
|
37
|
+
s.test_files = [
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_qtrefmovie.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/test/helper.rb
ADDED
data/test/sample.mov
ADDED
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestQtrefmovie < Test::Unit::TestCase
|
4
|
+
should "create a reference movie matching the stored sample" do
|
5
|
+
QTRefMovie
|
6
|
+
movie = QTRefMovie::QTMovie.new [{:reference => "rtsp://127.0.0.1:80/test.mov",
|
7
|
+
:data_rate => 'intranet',
|
8
|
+
:cpu_speed => 'fast'},
|
9
|
+
{:reference => "rtsp://127.0.0.1:80/test2.mov",
|
10
|
+
:data_rate => 't1',
|
11
|
+
:quality => 650}]
|
12
|
+
sample = File.read("test/sample.mov")
|
13
|
+
assert_equal movie.to_s, sample
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qtrefmovie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jonathan Block
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-17 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: QTRefMovie is a simple tool for generating QuickTime Reference Movie files from a Ruby script.
|
36
|
+
email: jonblock@jonblock.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/qtrefmovie.rb
|
52
|
+
- qtrefmovie.gemspec
|
53
|
+
- test/helper.rb
|
54
|
+
- test/sample.mov
|
55
|
+
- test/test_qtrefmovie.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/jonblock/qtrefmovie
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.7
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Simple code for generating QuickTime Reference Movies from Ruby
|
90
|
+
test_files:
|
91
|
+
- test/helper.rb
|
92
|
+
- test/test_qtrefmovie.rb
|