rmov 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ #include "rmov_ext.h"
2
+
3
+ VALUE mQuicktime;
4
+ VALUE eQuicktime;
5
+
6
+ void Init_rmov_ext()
7
+ {
8
+ EnterMovies(); // Enables the QuickTime framework
9
+ mQuicktime = rb_define_module("Quicktime");
10
+ eQuicktime = rb_define_class_under(mQuicktime, "Error", rb_eStandardError);
11
+ Init_quicktime_movie();
12
+ Init_quicktime_track();
13
+ Init_quicktime_exporter();
14
+ }
@@ -0,0 +1,41 @@
1
+ #include <ruby.h>
2
+ #include <QuickTime/QuickTime.h>
3
+
4
+ extern VALUE mQuicktime, eQuicktime, cMovie, cTrack, cExporter;
5
+
6
+ /*** MOVIE ***/
7
+
8
+ void Init_quicktime_movie();
9
+ OSErr movie_progress_proc(Movie movie, short message, short operation, Fixed percent, VALUE proc);
10
+
11
+ #define RMOVIE(obj) (Check_Type(obj, T_DATA), (struct RMovie*)DATA_PTR(obj))
12
+ #define MOVIE(obj) (RMOVIE(obj)->movie)
13
+ #define MOVIE_TIME(obj, seconds) (floor(NUM2DBL(seconds)*GetMovieTimeScale(MOVIE(obj))))
14
+
15
+ struct RMovie {
16
+ Movie movie;
17
+ };
18
+
19
+
20
+ /*** TRACK ***/
21
+
22
+ void Init_quicktime_track();
23
+
24
+ #define RTRACK(obj) (Check_Type(obj, T_DATA), (struct RTrack*)DATA_PTR(obj))
25
+ #define TRACK(obj) (RTRACK(obj)->track)
26
+ #define TRACK_MEDIA(obj) (GetTrackMedia(TRACK(obj)))
27
+
28
+ struct RTrack {
29
+ Track track;
30
+ };
31
+
32
+
33
+ /*** EXPORTER ***/
34
+
35
+ void Init_quicktime_exporter();
36
+
37
+ #define REXPORTER(obj) (Check_Type(obj, T_DATA), (struct RExporter*)DATA_PTR(obj))
38
+
39
+ struct RExporter {
40
+ QTAtomContainer settings;
41
+ };
@@ -0,0 +1,174 @@
1
+ #include "rmov_ext.h"
2
+
3
+ VALUE cTrack;
4
+
5
+ static void track_free(struct RTrack *rTrack)
6
+ {
7
+ }
8
+
9
+ static void track_mark(struct RTrack *rTrack)
10
+ {
11
+ }
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
+ */
20
+ static VALUE track_new(VALUE klass)
21
+ {
22
+ struct RTrack *rTrack;
23
+ return Data_Make_Struct(klass, struct RTrack, track_mark, track_free, rTrack);
24
+ }
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
+ */
33
+ static VALUE track_load(VALUE obj, VALUE movie_obj, VALUE index_obj)
34
+ {
35
+ RTRACK(obj)->track = GetMovieIndTrack(MOVIE(movie_obj), NUM2INT(index_obj));
36
+ if (!RTRACK(obj)->track)
37
+ rb_raise(eQuicktime, "Unable to fetch track for movie at index %d", NUM2INT(index_obj));
38
+
39
+ return obj;
40
+ }
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
+ */
49
+ static VALUE track_raw_duration(VALUE obj)
50
+ {
51
+ return INT2NUM(GetMediaDuration(TRACK_MEDIA(obj)));
52
+ }
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
+ */
61
+ static VALUE track_time_scale(VALUE obj)
62
+ {
63
+ return INT2NUM(GetMediaTimeScale(TRACK_MEDIA(obj)));
64
+ }
65
+
66
+ /*
67
+ Returns the number of frames in the track.
68
+
69
+ call-seq:
70
+ frame_count() -> count
71
+ */
72
+ static VALUE track_frame_count(VALUE obj)
73
+ {
74
+ return INT2NUM(GetMediaSampleCount(TRACK_MEDIA(obj)));
75
+ }
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
+ */
83
+ static VALUE track_media_type(VALUE obj)
84
+ {
85
+ OSType media_type;
86
+
87
+ GetMediaHandlerDescription(TRACK_MEDIA(obj), &media_type, 0, 0);
88
+ if (media_type == SoundMediaType) {
89
+ return ID2SYM(rb_intern("audio"));
90
+ } else if (media_type == VideoMediaType) {
91
+ return ID2SYM(rb_intern("video"));
92
+ } else {
93
+ return Qnil;
94
+ }
95
+ }
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
+ */
104
+ static VALUE track_id(VALUE obj)
105
+ {
106
+ return INT2NUM(GetTrackID(TRACK(obj)));
107
+ }
108
+
109
+ /*
110
+ Removes the track from its movie and deletes it from memory.
111
+
112
+ call-seq:
113
+ delete()
114
+ */
115
+ static VALUE track_delete(VALUE obj)
116
+ {
117
+ DisposeMovieTrack(TRACK(obj));
118
+ return Qnil;
119
+ }
120
+
121
+ /*
122
+ Disables the track. See enabled? to determine if it's disabled already.
123
+
124
+ call-seq:
125
+ disable()
126
+ */
127
+ static VALUE track_disable(VALUE obj, VALUE boolean)
128
+ {
129
+ SetTrackEnabled(TRACK(obj), FALSE);
130
+ return obj;
131
+ }
132
+
133
+ /*
134
+ Enables the track. See enabled? to determine if it's enabled already.
135
+
136
+ call-seq:
137
+ enable()
138
+ */
139
+ static VALUE track_enable(VALUE obj, VALUE boolean)
140
+ {
141
+ SetTrackEnabled(TRACK(obj), TRUE);
142
+ return obj;
143
+ }
144
+
145
+ /*
146
+ Returns true/false depending on if the track is enabled.
147
+
148
+ call-seq:
149
+ enabled?() -> bool
150
+ */
151
+ static VALUE track_enabled(VALUE obj, VALUE boolean)
152
+ {
153
+ if (GetTrackEnabled(TRACK(obj)) == TRUE) {
154
+ return Qtrue;
155
+ } else {
156
+ return Qfalse;
157
+ }
158
+ }
159
+
160
+ void Init_quicktime_track()
161
+ {
162
+ cTrack = rb_define_class_under(mQuicktime, "Track", rb_cObject);
163
+ rb_define_alloc_func(cTrack, track_new);
164
+ rb_define_method(cTrack, "load_from_movie", track_load, 2);
165
+ rb_define_method(cTrack, "raw_duration", track_raw_duration, 0);
166
+ rb_define_method(cTrack, "time_scale", track_time_scale, 0);
167
+ rb_define_method(cTrack, "frame_count", track_frame_count, 0);
168
+ rb_define_method(cTrack, "media_type", track_media_type, 0);
169
+ rb_define_method(cTrack, "id", track_id, 0);
170
+ rb_define_method(cTrack, "delete", track_delete, 0);
171
+ rb_define_method(cTrack, "enabled?", track_enabled, 0);
172
+ rb_define_method(cTrack, "enable", track_enable, 0);
173
+ rb_define_method(cTrack, "disable", track_disable, 0);
174
+ }
@@ -0,0 +1,10 @@
1
+ module Quicktime
2
+ # see ext/exporter.c for additional methods
3
+ class Exporter
4
+ attr_reader :movie
5
+
6
+ def initialize(movie)
7
+ @movie = movie
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,57 @@
1
+ module Quicktime
2
+ # see ext/movie.c for additional methods
3
+ class Movie
4
+ # Opens a movie at filepath.
5
+ def self.open(filepath)
6
+ new.load_from_file(filepath)
7
+ end
8
+
9
+ # Returns a new, empty movie.
10
+ def self.empty
11
+ new.load_empty
12
+ end
13
+
14
+ # Returns the length of this movie in seconds
15
+ # using raw_duration and time_scale.
16
+ def duration
17
+ raw_duration.to_f/time_scale
18
+ end
19
+
20
+ # Returns the bounding width of this movie in number of pixels.
21
+ def width
22
+ bounds[:right] - bounds[:left]
23
+ end
24
+
25
+ # Returns the bounding height of this movie in number of pixels.
26
+ def height
27
+ bounds[:bottom] - bounds[:top]
28
+ end
29
+
30
+ # Returns an array of tracks in this movie.
31
+ def tracks
32
+ (1..track_count).map do |i|
33
+ Track.new.load_from_movie(self, i)
34
+ end
35
+ end
36
+
37
+ # Returns an array of audio tracks in this movie.
38
+ def audio_tracks
39
+ tracks.select { |t| t.audio? }
40
+ end
41
+
42
+ # Returns an array of video tracks in this movie.
43
+ def video_tracks
44
+ tracks.select { |t| t.video? }
45
+ end
46
+
47
+ # Returns an Exporter instance for this movie.
48
+ def exporter
49
+ Exporter.new(self)
50
+ end
51
+
52
+ # Convenience method for exporting the movie. See Exporter::export.
53
+ def export(*args, &block)
54
+ exporter.export(*args, &block)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ module Quicktime
2
+ # see ext/track.c for additional methods
3
+ class Track
4
+ # Returns the length of this track in seconds
5
+ # using raw_duration and time_scale.
6
+ def duration
7
+ raw_duration.to_f/time_scale
8
+ end
9
+
10
+ # The average frame_rate for this track. May not be exact.
11
+ def frame_rate # what about odd frame rates such as 29.97?
12
+ frame_count/duration
13
+ end
14
+
15
+ # Returns true/false depending on if track is an audio track.
16
+ def audio?
17
+ media_type == :audio
18
+ end
19
+
20
+ # Returns true/false depending on if track is a video track.
21
+ def video?
22
+ media_type == :video
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require File.dirname(__FILE__) + '/../ext/rmov_ext'
4
+
5
+ require 'quicktime/movie'
6
+ require 'quicktime/track'
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,0 +1,101 @@
1
+
2
+ # Gem::Specification for Rmov-0.1.0
3
+ # Originally generated by Echoe
4
+
5
+ --- !ruby/object:Gem::Specification
6
+ name: rmov
7
+ version: !ruby/object:Gem::Version
8
+ version: 0.1.0
9
+ platform: ruby
10
+ authors:
11
+ - Ryan Bates
12
+ autorequire:
13
+ bindir: bin
14
+
15
+ date: 2008-10-02 00:00:00 -07:00
16
+ default_executable:
17
+ dependencies: []
18
+
19
+ description: Ruby wrapper for the QuickTime C API.
20
+ email: ryan (at) railscasts (dot) com
21
+ executables: []
22
+
23
+ extensions:
24
+ - ext/extconf.rb
25
+ extra_rdoc_files:
26
+ - CHANGELOG
27
+ - ext/exporter.c
28
+ - ext/extconf.rb
29
+ - ext/movie.c
30
+ - ext/rmov_ext.c
31
+ - ext/rmov_ext.h
32
+ - ext/track.c
33
+ - lib/quicktime/exporter.rb
34
+ - lib/quicktime/movie.rb
35
+ - lib/quicktime/track.rb
36
+ - lib/rmov.rb
37
+ - LICENSE
38
+ - README
39
+ - tasks/setup.rake
40
+ - tasks/spec.rake
41
+ - TODO
42
+ files:
43
+ - CHANGELOG
44
+ - ext/exporter.c
45
+ - ext/extconf.rb
46
+ - ext/movie.c
47
+ - ext/rmov_ext.c
48
+ - ext/rmov_ext.h
49
+ - ext/track.c
50
+ - lib/quicktime/exporter.rb
51
+ - lib/quicktime/movie.rb
52
+ - lib/quicktime/track.rb
53
+ - lib/rmov.rb
54
+ - LICENSE
55
+ - Rakefile
56
+ - README
57
+ - spec/fixtures/settings.st
58
+ - spec/output/example.pct
59
+ - spec/output/saved_settings.st
60
+ - spec/quicktime/exporter_spec.rb
61
+ - spec/quicktime/movie_spec.rb
62
+ - spec/quicktime/track_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ - tasks/setup.rake
66
+ - tasks/spec.rake
67
+ - TODO
68
+ - Manifest
69
+ - rmov.gemspec
70
+ has_rdoc: true
71
+ homepage: http://github.com/ryanb/rmov
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --line-numbers
75
+ - --inline-source
76
+ - --title
77
+ - Rmov
78
+ - --main
79
+ - README
80
+ require_paths:
81
+ - lib
82
+ - ext
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "="
92
+ - !ruby/object:Gem::Version
93
+ version: "1.2"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: rmov
98
+ rubygems_version: 1.2.0
99
+ specification_version: 2
100
+ summary: Ruby wrapper for the QuickTime C API.
101
+ test_files: []
Binary file
Binary file