rmovie 0.5.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,349 @@
1
+ #include <ruby.h>
2
+
3
+ #include "qp_movie.h"
4
+ #include "rmovie_movie.h"
5
+
6
+ extern VALUE rb_cFrame;
7
+
8
+ extern VALUE wrap_frame_ctx(VALUE klass, qp_frame_context *frame);
9
+
10
+ static void rm_mark_movie_ctx(qp_movie_context *movie) {}
11
+
12
+ static void rm_free_movie_ctx(qp_movie_context *movie) {
13
+ qp_free_movie_ctx(movie, NULL);
14
+ }
15
+
16
+ VALUE movie_allocate(VALUE klass)
17
+ {
18
+ qp_movie_context* movie = qp_alloc_movie_ctx(NULL);
19
+ return Data_Wrap_Struct (klass, rm_mark_movie_ctx,
20
+ rm_free_movie_ctx, movie);
21
+ }
22
+
23
+
24
+ VALUE movie_initialize(VALUE self, VALUE filename)
25
+ {
26
+ qp_movie_context *movie_ctx;
27
+
28
+ SafeStringValue(filename);
29
+
30
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
31
+
32
+ if (qp_open_movie_file(movie_ctx, StringValueCStr(filename))) {
33
+ rb_sys_fail((StringValueCStr(filename)));
34
+ }
35
+
36
+ return self;
37
+ }
38
+
39
+
40
+ VALUE Movie_get_duration(VALUE self)
41
+ {
42
+ qp_movie_context *movie_ctx;
43
+
44
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
45
+
46
+ return rb_float_new(qp_get_duration(movie_ctx));
47
+ }
48
+
49
+
50
+ VALUE Movie_get_frame_count(VALUE self)
51
+ {
52
+ qp_movie_context *movie_ctx;
53
+
54
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
55
+
56
+ return rb_int_new(qp_get_frame_count(movie_ctx));
57
+ }
58
+
59
+
60
+ VALUE Movie_get_frame_rate(VALUE self)
61
+ {
62
+ qp_movie_context *movie_ctx;
63
+
64
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
65
+
66
+ return rb_float_new(qp_get_frame_rate(movie_ctx));
67
+ }
68
+
69
+
70
+ VALUE Movie_get_file_name(VALUE self)
71
+ {
72
+ qp_movie_context *movie_ctx;
73
+
74
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
75
+
76
+ return rb_tainted_str_new2(qp_get_file_name(movie_ctx));
77
+ }
78
+
79
+
80
+ VALUE Movie_get_frame_width(VALUE self)
81
+ {
82
+ qp_movie_context *movie_ctx;
83
+
84
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
85
+
86
+ return rb_int_new(qp_get_movie_width(movie_ctx));
87
+ }
88
+
89
+
90
+ VALUE Movie_get_frame_height(VALUE self)
91
+ {
92
+ qp_movie_context *movie_ctx;
93
+
94
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
95
+
96
+ return rb_int_new(qp_get_movie_height(movie_ctx));
97
+ }
98
+
99
+
100
+ VALUE Movie_get_comment(VALUE self)
101
+ {
102
+ qp_movie_context *movie_ctx;
103
+
104
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
105
+
106
+ return rb_tainted_str_new2(qp_get_comment(movie_ctx));
107
+ }
108
+
109
+
110
+ VALUE Movie_get_title(VALUE self)
111
+ {
112
+ qp_movie_context *movie_ctx;
113
+
114
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
115
+
116
+ return rb_tainted_str_new2(qp_get_title(movie_ctx));
117
+ }
118
+
119
+
120
+ // getartist is an alias of this
121
+ VALUE Movie_get_author(VALUE self)
122
+ {
123
+ qp_movie_context *movie_ctx;
124
+
125
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
126
+
127
+ return rb_tainted_str_new2(qp_get_author(movie_ctx));
128
+ }
129
+
130
+
131
+ VALUE Movie_get_copyright(VALUE self)
132
+ {
133
+ qp_movie_context *movie_ctx;
134
+
135
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
136
+
137
+ return rb_tainted_str_new2(qp_get_copyright(movie_ctx));
138
+ }
139
+
140
+
141
+ VALUE Movie_get_album(VALUE self)
142
+ {
143
+ qp_movie_context *movie_ctx;
144
+
145
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
146
+
147
+ return rb_tainted_str_new2(qp_get_album(movie_ctx));
148
+ }
149
+
150
+
151
+ VALUE Movie_get_genre(VALUE self)
152
+ {
153
+ qp_movie_context *movie_ctx;
154
+
155
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
156
+
157
+ return rb_tainted_str_new2(qp_get_genre(movie_ctx));
158
+ }
159
+
160
+
161
+ VALUE Movie_get_year(VALUE self)
162
+ {
163
+ qp_movie_context *movie_ctx;
164
+
165
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
166
+
167
+ return rb_int_new(qp_get_year(movie_ctx));
168
+ }
169
+
170
+
171
+ VALUE Movie_get_track(VALUE self)
172
+ {
173
+ qp_movie_context *movie_ctx;
174
+
175
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
176
+
177
+ return rb_int_new(qp_get_track(movie_ctx));
178
+ }
179
+
180
+
181
+ VALUE Movie_get_frame_number(VALUE self)
182
+ {
183
+ qp_movie_context *movie_ctx;
184
+
185
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
186
+
187
+ return rb_int_new(qp_get_current_frame_number(movie_ctx));
188
+ }
189
+
190
+
191
+ VALUE Movie_get_pixel_format(VALUE self)
192
+ {
193
+ const char *fmt;
194
+ qp_movie_context *movie_ctx;
195
+
196
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
197
+
198
+ fmt = qp_get_movie_pixel_format_name(movie_ctx);
199
+
200
+ if (fmt) {
201
+ return rb_tainted_str_new2((char *)fmt);
202
+ } else {
203
+ return Qfalse; // TODO: Should this be Qnil or Qundef instead?
204
+ }
205
+ }
206
+
207
+
208
+ VALUE Movie_get_bit_rate(VALUE self)
209
+ {
210
+ qp_movie_context *movie_ctx;
211
+
212
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
213
+
214
+ return rb_int_new(qp_get_bit_rate(movie_ctx));
215
+ }
216
+
217
+
218
+ VALUE Movie_has_audio(VALUE self)
219
+ {
220
+ qp_movie_context *movie_ctx;
221
+
222
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
223
+
224
+ return qp_has_audio(movie_ctx) ? Qtrue : Qfalse;
225
+ }
226
+
227
+
228
+ VALUE Movie_get_video_codec(VALUE self)
229
+ {
230
+ char *codec_name;
231
+ qp_movie_context *movie_ctx;
232
+
233
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
234
+
235
+ codec_name = (char*)qp_get_codec_name(movie_ctx, CODEC_TYPE_VIDEO);
236
+
237
+ if (codec_name) {
238
+ return rb_tainted_str_new2((char *)codec_name);
239
+ } else {
240
+ return Qfalse; // TODO: Should this be Qnil or Qundef instead?
241
+ }
242
+ }
243
+
244
+
245
+ VALUE Movie_get_audio_codec(VALUE self)
246
+ {
247
+ char *codec_name;
248
+ qp_movie_context *movie_ctx;
249
+
250
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
251
+
252
+ codec_name = (char*)qp_get_codec_name(movie_ctx, CODEC_TYPE_AUDIO);
253
+
254
+ if (codec_name) {
255
+ return rb_tainted_str_new2((char *)codec_name);
256
+ } else {
257
+ return Qfalse; // TODO: Should this be Qnil or Qundef instead?
258
+ }
259
+ }
260
+
261
+
262
+ VALUE Movie_get_num_audio_channels(VALUE self)
263
+ {
264
+ qp_movie_context *movie_ctx;
265
+
266
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
267
+
268
+ return rb_int_new(qp_get_num_audio_channels(movie_ctx));
269
+ }
270
+
271
+
272
+ VALUE Movie_get_pixel_aspect_ratio(VALUE self)
273
+ {
274
+ qp_movie_context *movie_ctx;
275
+
276
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
277
+
278
+ return rb_float_new(qp_get_pixel_aspect_ratio(movie_ctx));
279
+ }
280
+
281
+
282
+ VALUE Movie_get_frame(int argc, VALUE *argv, VALUE self)
283
+ {
284
+ unsigned int wanted_frame = 0;
285
+ qp_movie_context *movie_ctx;
286
+ qp_frame_context *frame_ctx = NULL;
287
+ int err;
288
+
289
+ switch (argc) {
290
+ case 1:
291
+ wanted_frame = NUM2UINT(argv[0]);
292
+ if (wanted_frame < 1) {
293
+ rb_raise(rb_eArgError,
294
+ "frame number must be greater than zero");
295
+ }
296
+ break;
297
+ case 0:
298
+ wanted_frame = 0;
299
+ break;
300
+ default:
301
+ rb_raise(rb_eArgError,
302
+ "wrong number of arguments (%d for 0 or 1)", argc);
303
+ break;
304
+ }
305
+
306
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
307
+
308
+ if (qp_get_frame(movie_ctx, wanted_frame, &frame_ctx)) {
309
+ rb_warn("couldn't get frame %d", wanted_frame);
310
+ } else {
311
+ return wrap_frame_ctx(rb_cFrame, frame_ctx);
312
+ }
313
+ return Qnil;
314
+ }
315
+
316
+
317
+ VALUE Movie_get_next_key_frame(VALUE self)
318
+ {
319
+ qp_movie_context *movie_ctx;
320
+ qp_frame_context *frame_ctx = NULL;
321
+
322
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
323
+
324
+ qp_get_frame(movie_ctx, QP_GETFRAME_KEYFRAME, &frame_ctx);
325
+
326
+ if (frame_ctx == NULL) {
327
+ // TODO: Exception or false?
328
+ rb_warn("couldn't get key frame");
329
+ } else {
330
+ return wrap_frame_ctx(rb_cFrame, frame_ctx);
331
+ }
332
+ return Qnil;
333
+ }
334
+
335
+ VALUE Movie_export(VALUE self, VALUE filename)
336
+ {
337
+ qp_movie_context *movie_ctx;
338
+
339
+ SafeStringValue(filename);
340
+
341
+ Data_Get_Struct(self, qp_movie_context, movie_ctx);
342
+
343
+ if (qp_export_movie(movie_ctx, StringValueCStr(filename)) != 0) {
344
+ rb_warn("couldn't export movie to %s", filename);
345
+ return Qfalse;
346
+ }
347
+
348
+ return Qtrue;
349
+ }
@@ -0,0 +1,28 @@
1
+ VALUE movie_allocate(VALUE klass);
2
+ VALUE movie_initialize(VALUE self, VALUE filename);
3
+ VALUE Movie_get_duration(VALUE);
4
+ VALUE Movie_get_frame_count(VALUE);
5
+ VALUE Movie_get_frame_rate(VALUE);
6
+ VALUE Movie_get_file_name(VALUE);
7
+ VALUE Movie_get_comment(VALUE);
8
+ VALUE Movie_get_title(VALUE);
9
+ VALUE Movie_get_author(VALUE); // get_artist is alias of this
10
+ VALUE Movie_get_artist(VALUE);
11
+ VALUE Movie_get_copyright(VALUE);
12
+ VALUE Movie_get_album(VALUE);
13
+ VALUE Movie_get_genre(VALUE);
14
+ VALUE Movie_get_year(VALUE);
15
+ VALUE Movie_get_track(VALUE);
16
+ VALUE Movie_get_frame_width(VALUE);
17
+ VALUE Movie_get_frame_height(VALUE);
18
+ VALUE Movie_get_frame_number(VALUE);
19
+ VALUE Movie_get_pixel_format(VALUE);
20
+ VALUE Movie_get_bit_rate(VALUE);
21
+ VALUE Movie_has_audio(VALUE);
22
+ VALUE Movie_get_next_key_frame(VALUE);
23
+ VALUE Movie_get_video_codec(VALUE);
24
+ VALUE Movie_get_audio_codec(VALUE);
25
+ VALUE Movie_get_num_audio_channels(VALUE);
26
+ VALUE Movie_get_pixel_aspect_ratio(VALUE);
27
+ VALUE Movie_get_frame(int argc, VALUE *argv, VALUE self);
28
+ VALUE Movie_export(VALUE self, VALUE filename);
@@ -0,0 +1,45 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
24
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # =============================================================================
31
+ #++
32
+
33
+ module RMovie
34
+
35
+ module Version
36
+
37
+ MAJOR = 0
38
+ MINOR = 5
39
+ TINY = 0
40
+
41
+ STRING = [ MAJOR, MINOR, TINY ].join( "." )
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rmovie'
4
+
5
+ mov = RMovie::Movie.new("/home/tkirby/test/video/vimeo.todd.289.mov")
6
+
7
+ mov.export('out.mpg')
data/test/get_frame.rb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rmovie'
4
+
5
+ $script_dir = File.dirname(File.expand_path($0))
6
+ $media_dir = "#{$script_dir}/media"
7
+
8
+ mov = RMovie::Movie.new("#{$media_dir}/1701-D.mov")
9
+
10
+ print mov.frame(1).inspect, "\n"
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rmovie'
4
+
5
+ $script_dir = File.dirname(File.expand_path($0))
6
+ $media_dir = "#{$script_dir}/media"
7
+
8
+ mov = RMovie::Movie.new("#{$media_dir}/1701-D.mov")
9
+
10
+ mov.frame(6).inspect
11
+ mov.frame(5).inspect