Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

releasing initial 0.1.0 with documentation

  • Loading branch information...
commit 5e04e88fc4daf75ba8c0ab6b1a21ca6a0cb9986f 1 parent 1b8ec79
Ryan Bates authored
3  .gitignore
@@ -3,4 +3,5 @@
3 3 Makefile
4 4 spec/output/*.mov
5 5 spec/output/*.st
6   -spec/output/*.pct
  6 +spec/output/*.pct
  7 +pkg
3  CHANGELOG
... ... @@ -0,0 +1,3 @@
  1 +0.1.0 (October 2nd, 2008)
  2 +
  3 +* initial release
20 LICENSE
... ... @@ -0,0 +1,20 @@
  1 +Copyright (c) 2008 Ryan Bates
  2 +
  3 +Permission is hereby granted, free of charge, to any person obtaining
  4 +a copy of this software and associated documentation files (the
  5 +"Software"), to deal in the Software without restriction, including
  6 +without limitation the rights to use, copy, modify, merge, publish,
  7 +distribute, sublicense, and/or sell copies of the Software, and to
  8 +permit persons to whom the Software is furnished to do so, subject to
  9 +the following conditions:
  10 +
  11 +The above copyright notice and this permission notice shall be
  12 +included in all copies or substantial portions of the Software.
  13 +
  14 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18 +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19 +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20 +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 Manifest
... ... @@ -0,0 +1,26 @@
  1 +CHANGELOG
  2 +ext/exporter.c
  3 +ext/extconf.rb
  4 +ext/movie.c
  5 +ext/rmov_ext.c
  6 +ext/rmov_ext.h
  7 +ext/track.c
  8 +lib/quicktime/exporter.rb
  9 +lib/quicktime/movie.rb
  10 +lib/quicktime/track.rb
  11 +lib/rmov.rb
  12 +LICENSE
  13 +Rakefile
  14 +README
  15 +spec/fixtures/settings.st
  16 +spec/output/example.pct
  17 +spec/output/saved_settings.st
  18 +spec/quicktime/exporter_spec.rb
  19 +spec/quicktime/movie_spec.rb
  20 +spec/quicktime/track_spec.rb
  21 +spec/spec.opts
  22 +spec/spec_helper.rb
  23 +tasks/setup.rake
  24 +tasks/spec.rake
  25 +TODO
  26 +Manifest
75 README
... ... @@ -1,16 +1,73 @@
1   -RMov
  1 += RMov
2 2
3   -Ruby wrapper for the QuickTime C API.
  3 +Open, edit, and export QuickTime movies all within Ruby! This is an
  4 +unofficial wrapper around Apple's QuickTime C API. Mac OS X required.
4 5
5   -This is still in very early development. To try it out, run the setup
6   -task to build the ruby c extensions.
7 6
8   - rake setup
  7 +== Install
9 8
10   -You can then require 'rmov' in the lib directory.
  9 +Install the gem:
  10 +
  11 + gem install rmov
  12 +
  13 +And then load it in your project:
11 14
12 15 require 'rmov'
13   - movie = Quicktime::Movie.open('foo.mov')
14   - movie.duration # returns number of seconds of movie
15 16
16   -More features coming soon.
  17 +
  18 +== Usage
  19 +
  20 +Use this gem to open QuickTime movies and edit them to your liking.
  21 +
  22 + movie1 = QuickTime::Movie.open("path/to/movie.mov")
  23 + movie2 = QuickTime::Movie.open("path/to/another_movie.mov")
  24 +
  25 + # add movie2 to the end of movie1
  26 + movie1.append_movie(movie2)
  27 +
  28 + # make a new movie out of a section of movie 1
  29 + # this will delete 5 seconds out of the movie at 2 seconds in
  30 + movie3 = movie1.clip_section(movie1, 2, 5)
  31 +
  32 + # You can insert that part back into the movie at 8 seconds in
  33 + movie1.insert_movie(movie3, 8)
  34 +
  35 +Now you can export the movie. Usually this is done through a user
  36 +interface the first time around. The settings can then be saved to
  37 +a file. After that you can load these settings without interfering
  38 +the user with the dialog again.
  39 +
  40 + exporter = movie1.exporter
  41 +
  42 + # if we already have saved the settings, load those
  43 + if File.exist? "settings.st"
  44 + exporter.load_settings("settings.st")
  45 + else
  46 + # otherwise open the QuickTime GUI settings dialog
  47 + exporter.open_settings_dialog
  48 +
  49 + # save settings to a file so we don't have to bother user next time
  50 + exporter.save_settings("settings.st")
  51 + end
  52 +
  53 + # export the movie to a file and report the progress along the way
  54 + exporter.export("movie.mov") do |progress|
  55 + percent = (progress*100).round
  56 + puts "#{percent}% complete"
  57 + end
  58 +
  59 +See Quicktime::Movie in the RDoc for more information.
  60 +
  61 +http://rmov.rubyforge.org
  62 +
  63 +
  64 +== Development
  65 +
  66 +This project can be found on github at the following URL.
  67 +
  68 +http://github.com/ryanb/rmov
  69 +
  70 +If you find a bug, please send me a message on GitHub.
  71 +
  72 +If you would like to contribute to this project, please fork the
  73 +repository and send me a pull request.
13 Rakefile
... ... @@ -1,5 +1,16 @@
1 1 require 'rubygems'
2 2 require 'rake'
3   -require 'rake/gempackagetask'
  3 +require 'echoe'
  4 +
  5 +Echoe.new('rmov', '0.1.0') do |p|
  6 + p.summary = "Ruby wrapper for the QuickTime C API."
  7 + p.description = "Ruby wrapper for the QuickTime C API."
  8 + p.url = "http://github.com/ryanb/rmov"
  9 + p.author = 'Ryan Bates'
  10 + p.email = "ryan (at) railscasts (dot) com"
  11 + p.ignore_pattern = ["script/*", "tmp/*", "output/*", "**/*.o", "**/*.bundle", "**/*.mov"]
  12 + p.extensions = ["ext/extconf.rb"]
  13 + p.development_dependencies = []
  14 +end
4 15
5 16 Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
40 ext/exporter.c
@@ -13,6 +13,12 @@ static void exporter_mark(struct RExporter *rExporter)
13 13 {
14 14 }
15 15
  16 +/*
  17 + Creates a new exporter instance. Usually this is done through movie.exporter.
  18 +
  19 +call-seq:
  20 + new(movie) -> exporter
  21 +*/
16 22 static VALUE exporter_new(VALUE klass)
17 23 {
18 24 struct RExporter *rExporter;
@@ -28,6 +34,17 @@ static ComponentInstance exporter_component(VALUE obj)
28 34 return component;
29 35 }
30 36
  37 +/*
  38 + Exports a movie to the given filepath. This will use either the
  39 + settings you set beforehand, or QuickTime's defaults.
  40 +
  41 + You can track the progress of this operation by passing a block to this
  42 + method. It will be called regularly during the process and pass the
  43 + percentage complete (0.0 to 1.0) as an argument to the block.
  44 +
  45 +call-seq:
  46 + export_to_file(filepath)
  47 +*/
31 48 static VALUE exporter_export_to_file(VALUE obj, VALUE filepath)
32 49 {
33 50 OSErr err;
@@ -58,6 +75,16 @@ static VALUE exporter_export_to_file(VALUE obj, VALUE filepath)
58 75 return Qnil;
59 76 }
60 77
  78 +/*
  79 + Opens the offical QuickTime GUI settings dialog. The process will be
  80 + suspended until the user closes the dialogue. If the user clicks Okay
  81 + the settings will be applied to this Exporter. You can then use
  82 + save_settings to save them to a file, and load_settings to load them
  83 + back again.
  84 +
  85 +call-seq:
  86 + open_settings_dialog()
  87 +*/
61 88 static VALUE exporter_open_settings_dialog(VALUE obj)
62 89 {
63 90 Boolean canceled;
@@ -98,6 +125,12 @@ static VALUE exporter_open_settings_dialog(VALUE obj)
98 125 }
99 126 }
100 127
  128 +/*
  129 + Loads the settings at the given filepath. See save_settings.
  130 +
  131 +call-seq:
  132 + load_settings(filepath)
  133 +*/
101 134 static VALUE exporter_load_settings(VALUE obj, VALUE filepath)
102 135 {
103 136 FILE *file;
@@ -130,6 +163,13 @@ static VALUE exporter_load_settings(VALUE obj, VALUE filepath)
130 163 return Qnil;
131 164 }
132 165
  166 +/*
  167 + Saves the settings to the given filepath (usually with .st extension).
  168 + See open_settings_dialog and load_settings.
  169 +
  170 +call-seq:
  171 + save_settings(filepath)
  172 +*/
133 173 static VALUE exporter_save_settings(VALUE obj, VALUE filepath)
134 174 {
135 175 FILE *file;
151 ext/movie.c
@@ -19,12 +19,30 @@ static void movie_mark(struct RMovie *rMovie)
19 19 {
20 20 }
21 21
  22 +/*
  23 + Creates a new movie instance. Generally you want to go through
  24 + Movie.open or Movie.empty to load or create a new movie respectively.
  25 + If you do no then you will need to load the movie with load_empty or
  26 + load_from_file before you can accomplish anything.
  27 +
  28 +call-seq:
  29 + new() -> movie
  30 +*/
22 31 static VALUE movie_new(VALUE klass)
23 32 {
24 33 struct RMovie *rMovie;
25 34 return Data_Make_Struct(klass, struct RMovie, movie_mark, movie_free, rMovie);
26 35 }
27 36
  37 +/*
  38 + Dispose of the loaded QuickTime movie. This will automatically be done
  39 + when this movie instance is garbage collected. However if you are
  40 + iterating through many movies it is often helpful to dispose of it
  41 + as soon as you're done with it.
  42 +
  43 +call-seq:
  44 + dispose()
  45 +*/
28 46 static VALUE movie_dispose(VALUE obj)
29 47 {
30 48 if (MOVIE(obj)) {
@@ -34,6 +52,14 @@ static VALUE movie_dispose(VALUE obj)
34 52 return obj;
35 53 }
36 54
  55 +/*
  56 + Loads a new, empty QuickTime movie at given filepath. Should only be
  57 + called if no movie has been loaded (or it has been disposed). Usually
  58 + you go through Movie.open.
  59 +
  60 +call-seq:
  61 + load_from_file(filepath)
  62 +*/
37 63 static VALUE movie_load_from_file(VALUE obj, VALUE filepath)
38 64 {
39 65 if (MOVIE(obj)) {
@@ -67,6 +93,14 @@ static VALUE movie_load_from_file(VALUE obj, VALUE filepath)
67 93 }
68 94 }
69 95
  96 +/*
  97 + Loads a new, empty QuickTime movie. Should only be called if no movie
  98 + has been loaded (or it has been disposed). Usually you go through
  99 + Movie.empty.
  100 +
  101 +call-seq:
  102 + load_empty()
  103 +*/
70 104 static VALUE movie_load_empty(VALUE obj)
71 105 {
72 106 if (MOVIE(obj)) {
@@ -77,16 +111,36 @@ static VALUE movie_load_empty(VALUE obj)
77 111 }
78 112 }
79 113
  114 +/*
  115 + Returns the raw duration of the movie. Combine this with time_scale to
  116 + reach the duration in seconds.
  117 +
  118 +call-seq:
  119 + raw_duration() -> duration_int
  120 +*/
80 121 static VALUE movie_raw_duration(VALUE obj)
81 122 {
82 123 return INT2NUM(GetMovieDuration(MOVIE(obj)));
83 124 }
84 125
  126 +/*
  127 + Returns the time scale of the movie. Usually only needed when working
  128 + with raw_duration.
  129 +
  130 +call-seq:
  131 + time_scale() -> scale_int
  132 +*/
85 133 static VALUE movie_time_scale(VALUE obj)
86 134 {
87 135 return INT2NUM(GetMovieTimeScale(MOVIE(obj)));
88 136 }
89 137
  138 +/*
  139 + Returns the number of tracks in the movie.
  140 +
  141 +call-seq:
  142 + track_count() -> count
  143 +*/
90 144 static VALUE movie_bounds(VALUE obj)
91 145 {
92 146 VALUE bounds_hash = rb_hash_new();
@@ -99,11 +153,27 @@ static VALUE movie_bounds(VALUE obj)
99 153 return bounds_hash;
100 154 }
101 155
  156 +/*
  157 + Returns the number of tracks in the movie.
  158 +
  159 +call-seq:
  160 + track_count -> count
  161 +*/
102 162 static VALUE movie_track_count(VALUE obj)
103 163 {
104 164 return INT2NUM(GetMovieTrackCount(MOVIE(obj)));
105 165 }
106 166
  167 +/*
  168 + Adds the tracks of given movie into called movie at given position (in seconds).
  169 +
  170 + You can track the progress of this operation by passing a block to this
  171 + method. It will be called regularly during the process and pass the
  172 + percentage complete (0.0 to 1.0) as an argument to the block.
  173 +
  174 +call-seq:
  175 + composite_movie(movie, position)
  176 +*/
107 177 static VALUE movie_composite_movie(VALUE obj, VALUE src, VALUE position)
108 178 {
109 179 if (rb_block_given_p())
@@ -118,6 +188,16 @@ static VALUE movie_composite_movie(VALUE obj, VALUE src, VALUE position)
118 188 return obj;
119 189 }
120 190
  191 +/*
  192 + Inserts given movie into called movie at given position (in seconds).
  193 +
  194 + You can track the progress of this operation by passing a block to this
  195 + method. It will be called regularly during the process and pass the
  196 + percentage complete (0.0 to 1.0) as an argument to the block.
  197 +
  198 +call-seq:
  199 + append_movie(movie, position)
  200 +*/
121 201 static VALUE movie_insert_movie(VALUE obj, VALUE src, VALUE position)
122 202 {
123 203 if (rb_block_given_p())
@@ -132,6 +212,16 @@ static VALUE movie_insert_movie(VALUE obj, VALUE src, VALUE position)
132 212 return obj;
133 213 }
134 214
  215 +/*
  216 + Adds given movie to the end of movie which this method is called on.
  217 +
  218 + You can track the progress of this operation by passing a block to this
  219 + method. It will be called regularly during the process and pass the
  220 + percentage complete (0.0 to 1.0) as an argument to the block.
  221 +
  222 +call-seq:
  223 + append_movie(movie)
  224 +*/
135 225 static VALUE movie_append_movie(VALUE obj, VALUE src)
136 226 {
137 227 if (rb_block_given_p())
@@ -146,6 +236,13 @@ static VALUE movie_append_movie(VALUE obj, VALUE src)
146 236 return obj;
147 237 }
148 238
  239 +/*
  240 + Deletes given section from movie. Both start_time and duration
  241 + should be floats representing seconds.
  242 +
  243 +call-seq:
  244 + delete_section(start_time, duration)
  245 +*/
149 246 static VALUE movie_delete_section(VALUE obj, VALUE start, VALUE duration)
150 247 {
151 248 SetMovieSelection(MOVIE(obj), MOVIE_TIME(obj, start), MOVIE_TIME(obj, duration));
@@ -153,6 +250,18 @@ static VALUE movie_delete_section(VALUE obj, VALUE start, VALUE duration)
153 250 return obj;
154 251 }
155 252
  253 +/*
  254 + Returns a new movie in the given section. Does not modify original
  255 + movie. Both start_time and duration should be floats representing
  256 + seconds.
  257 +
  258 + You can track the progress of this operation by passing a block to this
  259 + method. It will be called regularly during the process and pass the
  260 + percentage complete (0.0 to 1.0) as an argument to the block.
  261 +
  262 +call-seq:
  263 + clone_section(start_time, duration) -> movie
  264 +*/
156 265 static VALUE movie_clone_section(VALUE obj, VALUE start, VALUE duration)
157 266 {
158 267 VALUE new_movie_obj = rb_obj_alloc(cMovie);
@@ -169,6 +278,18 @@ static VALUE movie_clone_section(VALUE obj, VALUE start, VALUE duration)
169 278 return new_movie_obj;
170 279 }
171 280
  281 +/*
  282 + Deletes given section on movie and returns a new movie with that
  283 + section. Both start_time and duration should be floats representing
  284 + seconds.
  285 +
  286 + You can track the progress of this operation by passing a block to this
  287 + method. It will be called regularly during the process and pass the
  288 + percentage complete (0.0 to 1.0) as an argument to the block.
  289 +
  290 +call-seq:
  291 + clip_section(start_time, duration) -> movie
  292 +*/
172 293 static VALUE movie_clip_section(VALUE obj, VALUE start, VALUE duration)
173 294 {
174 295 VALUE new_movie_obj = rb_obj_alloc(cMovie);
@@ -185,6 +306,13 @@ static VALUE movie_clip_section(VALUE obj, VALUE start, VALUE duration)
185 306 return new_movie_obj;
186 307 }
187 308
  309 +/*
  310 + Determine if a movie has changed since opening. Returns true/false.
  311 + See reset_changed_status to reset this value.
  312 +
  313 +call-seq:
  314 + changed?() -> bool
  315 +*/
188 316 static VALUE movie_changed(VALUE obj)
189 317 {
190 318 if (HasMovieChanged(MOVIE(obj))) {
@@ -194,12 +322,26 @@ static VALUE movie_changed(VALUE obj)
194 322 }
195 323 }
196 324
  325 +/*
  326 + Resets the "changed?" status. Does not revert the movie itself.
  327 +
  328 +call-seq:
  329 + clear_changed_status()
  330 +*/
197 331 static VALUE movie_clear_changed_status(VALUE obj)
198 332 {
199 333 ClearMovieChanged(MOVIE(obj));
200 334 return Qnil;
201 335 }
202 336
  337 +
  338 +/*
  339 + Saves the movie to the given filepath by flattening it.
  340 +
  341 +call-seq:
  342 + flatten(filepath)
  343 +*/
  344 +
203 345 static VALUE movie_flatten(VALUE obj, VALUE filepath)
204 346 {
205 347 OSErr err;
@@ -220,6 +362,15 @@ static VALUE movie_flatten(VALUE obj, VALUE filepath)
220 362 return new_movie_obj;
221 363 }
222 364
  365 +/*
  366 + Exports a PICT file to given filepath (should end in .pct) at the given
  367 + time. Time should be a floating point in seconds.
  368 +
  369 +call-seq:
  370 + export_pict(filepath, time)
  371 +
  372 +*/
  373 +
223 374 static VALUE movie_export_pict(VALUE obj, VALUE filepath, VALUE frame_time)
224 375 {
225 376 GraphicsImportComponent component;
71 ext/track.c
@@ -10,12 +10,26 @@ static void track_mark(struct RTrack *rTrack)
10 10 {
11 11 }
12 12
  13 +/*
  14 + Creates a new track instance. Generally you will do this through
  15 + movie.tracks to fetch the Track instances for a given movie.
  16 +
  17 +call-seq:
  18 + new() -> track
  19 +*/
13 20 static VALUE track_new(VALUE klass)
14 21 {
15 22 struct RTrack *rTrack;
16 23 return Data_Make_Struct(klass, struct RTrack, track_mark, track_free, rTrack);
17 24 }
18 25
  26 +/*
  27 + Loads a QuickTime track from a given movie. This is done automatically
  28 + when calling movie.tracks.
  29 +
  30 +call-seq:
  31 + load(movie, index)
  32 +*/
19 33 static VALUE track_load(VALUE obj, VALUE movie_obj, VALUE index_obj)
20 34 {
21 35 RTRACK(obj)->track = GetMovieIndTrack(MOVIE(movie_obj), NUM2INT(index_obj));
@@ -25,21 +39,47 @@ static VALUE track_load(VALUE obj, VALUE movie_obj, VALUE index_obj)
25 39 return obj;
26 40 }
27 41
  42 +/*
  43 + Returns the raw duration of the track. Combine this with time_scale to
  44 + reach the duration in seconds.
  45 +
  46 +call-seq:
  47 + raw_duration() -> duration_int
  48 +*/
28 49 static VALUE track_raw_duration(VALUE obj)
29 50 {
30 51 return INT2NUM(GetMediaDuration(TRACK_MEDIA(obj)));
31 52 }
32 53
  54 +/*
  55 + Returns the time scale of the track. Usually only needed when working
  56 + with raw_duration.
  57 +
  58 +call-seq:
  59 + time_scale() -> scale_int
  60 +*/
33 61 static VALUE track_time_scale(VALUE obj)
34 62 {
35 63 return INT2NUM(GetMediaTimeScale(TRACK_MEDIA(obj)));
36 64 }
37 65
  66 +/*
  67 + Returns the number of frames in the track.
  68 +
  69 +call-seq:
  70 + frame_count() -> count
  71 +*/
38 72 static VALUE track_frame_count(VALUE obj)
39 73 {
40 74 return INT2NUM(GetMediaSampleCount(TRACK_MEDIA(obj)));
41 75 }
42 76
  77 +/*
  78 + Returns either :audio or :video depending on the type of track this is.
  79 +
  80 +call-seq:
  81 + media_type() -> media_type_sym
  82 +*/
43 83 static VALUE track_media_type(VALUE obj)
44 84 {
45 85 OSType media_type;
@@ -54,29 +94,60 @@ static VALUE track_media_type(VALUE obj)
54 94 }
55 95 }
56 96
  97 +/*
  98 + Returns either id number QuickTime uses to reference this track.
  99 + Usually only used internally.
  100 +
  101 +call-seq:
  102 + id() -> quicktime_track_id_int
  103 +*/
57 104 static VALUE track_id(VALUE obj)
58 105 {
59 106 return INT2NUM(GetTrackID(TRACK(obj)));
60 107 }
61 108
  109 +/*
  110 + Removes the track from its movie and deletes it from memory.
  111 +
  112 +call-seq:
  113 + delete()
  114 +*/
62 115 static VALUE track_delete(VALUE obj)
63 116 {
64 117 DisposeMovieTrack(TRACK(obj));
65 118 return Qnil;
66 119 }
67 120
  121 +/*
  122 + Disables the track. See enabled? to determine if it's disabled already.
  123 +
  124 +call-seq:
  125 + disable()
  126 +*/
68 127 static VALUE track_disable(VALUE obj, VALUE boolean)
69 128 {
70 129 SetTrackEnabled(TRACK(obj), FALSE);
71 130 return obj;
72 131 }
73 132
  133 +/*
  134 + Enables the track. See enabled? to determine if it's enabled already.
  135 +
  136 +call-seq:
  137 + enable()
  138 +*/
74 139 static VALUE track_enable(VALUE obj, VALUE boolean)
75 140 {
76 141 SetTrackEnabled(TRACK(obj), TRUE);
77 142 return obj;
78 143 }
79 144
  145 +/*
  146 + Returns true/false depending on if the track is enabled.
  147 +
  148 +call-seq:
  149 + enabled?() -> bool
  150 +*/
80 151 static VALUE track_enabled(VALUE obj, VALUE boolean)
81 152 {
82 153 if (GetTrackEnabled(TRACK(obj)) == TRUE) {
11 lib/quicktime/movie.rb
... ... @@ -1,44 +1,55 @@
1 1 module Quicktime
2 2 # see ext/movie.c for additional methods
3 3 class Movie
  4 + # Opens a movie at filepath.
4 5 def self.open(filepath)
5 6 new.load_from_file(filepath)
6 7 end
7 8
  9 + # Returns a new, empty movie.
8 10 def self.empty
9 11 new.load_empty
10 12 end
11 13
  14 + # Returns the length of this movie in seconds
  15 + # using raw_duration and time_scale.
12 16 def duration
13 17 raw_duration.to_f/time_scale
14 18 end
15 19
  20 + # Returns the bounding width of this movie in number of pixels.
16 21 def width
17 22 bounds[:right] - bounds[:left]
18 23 end
19 24
  25 + # Returns the bounding height of this movie in number of pixels.
20 26 def height
21 27 bounds[:bottom] - bounds[:top]
22 28 end
23 29
  30 + # Returns an array of tracks in this movie.
24 31 def tracks
25 32 (1..track_count).map do |i|
26 33 Track.new.load_from_movie(self, i)
27 34 end
28 35 end
29 36
  37 + # Returns an array of audio tracks in this movie.
30 38 def audio_tracks
31 39 tracks.select { |t| t.audio? }
32 40 end
33 41
  42 + # Returns an array of video tracks in this movie.
34 43 def video_tracks
35 44 tracks.select { |t| t.video? }
36 45 end
37 46
  47 + # Returns an Exporter instance for this movie.
38 48 def exporter
39 49 Exporter.new(self)
40 50 end
41 51
  52 + # Convenience method for exporting the movie. See Exporter::export.
42 53 def export(*args, &block)
43 54 exporter.export(*args, &block)
44 55 end
5 lib/quicktime/track.rb
... ... @@ -1,18 +1,23 @@
1 1 module Quicktime
2 2 # see ext/track.c for additional methods
3 3 class Track
  4 + # Returns the length of this track in seconds
  5 + # using raw_duration and time_scale.
4 6 def duration
5 7 raw_duration.to_f/time_scale
6 8 end
7 9
  10 + # The average frame_rate for this track. May not be exact.
8 11 def frame_rate # what about odd frame rates such as 29.97?
9 12 frame_count/duration
10 13 end
11 14
  15 + # Returns true/false depending on if track is an audio track.
12 16 def audio?
13 17 media_type == :audio
14 18 end
15 19
  20 + # Returns true/false depending on if track is a video track.
16 21 def video?
17 22 media_type == :video
18 23 end
5 lib/rmov.rb
@@ -5,3 +5,8 @@
5 5 require 'quicktime/movie'
6 6 require 'quicktime/track'
7 7 require 'quicktime/exporter'
  8 +
  9 +
  10 +# RMov is made up of several parts. To start, see Quicktime::Movie.
  11 +module Quicktime
  12 +end

0 comments on commit 5e04e88

Please sign in to comment.
Something went wrong with that request. Please try again.