ffruby 0.0.1 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2007 James Le Cuirot
2
+ * Copyright (c) 2007-2010 James Le Cuirot
3
3
  *
4
4
  * This file is part of FFruby.
5
5
  *
@@ -18,36 +18,38 @@
18
18
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  */
20
20
 
21
- #define _GNU_SOURCE
22
- #include <ruby.h>
23
- #include <ffmpeg/avformat.h>
24
- #include <ffmpeg/avcodec.h>
21
+ #include "ffruby.h"
25
22
 
26
- VALUE cFFrubyStream;
27
- VALUE cFFrubyVideoStream;
28
- VALUE cFFrubyAudioStream;
23
+ /* Satisfy stupid RDoc. This hopefully gets optimised away. */
24
+ static void rdoc() { mFFruby = rb_define_module("FFruby"); }
25
+
26
+ static VALUE ffrs_alloc(VALUE klass)
27
+ {
28
+ return Data_Wrap_Struct(klass, 0, 0, NULL);
29
+ }
30
+
31
+ static AVStream* ffrs_get_stream(VALUE self)
32
+ {
33
+ AVStream *stream;
34
+ Data_Get_Struct(self, AVStream, stream);
35
+ return stream;
36
+ }
29
37
 
30
38
  static void ffrs_open_codec(AVStream* stream)
31
39
  {
32
40
  AVCodec *codec;
33
-
41
+
34
42
  if (stream->codec->codec == NULL)
35
43
  {
36
44
  if ((codec = avcodec_find_decoder(stream->codec->codec_id)) == NULL)
37
45
  rb_raise(rb_eIOError, "Cannot find codec!");
38
-
46
+
39
47
  if (avcodec_open(stream->codec, codec) < 0)
40
48
  rb_raise(rb_eIOError, "Cannot open codec!");
41
49
  }
42
50
  }
43
51
 
44
- static AVStream* ffrs_get_stream(VALUE self)
45
- {
46
- AVStream *stream;
47
- Data_Get_Struct(self, AVStream, stream);
48
- return stream;
49
- }
50
-
52
+ /* Returns the codec name. */
51
53
  static VALUE ffrs_codec(VALUE self)
52
54
  {
53
55
  AVStream *stream = ffrs_get_stream(self);
@@ -55,142 +57,166 @@ static VALUE ffrs_codec(VALUE self)
55
57
  return rb_str_new2(stream->codec->codec->name);
56
58
  }
57
59
 
60
+ /* Returns the FourCC tag. */
58
61
  static VALUE ffrs_tag(VALUE self)
59
62
  {
60
63
  char tag[4];
61
64
  signed int i, j;
62
65
  AVStream *stream = ffrs_get_stream(self);
63
-
66
+
64
67
  i = stream->codec->codec_tag;
65
-
68
+
66
69
  for (j = 3; j >= 0; j -= 1)
67
70
  {
68
71
  tag[j] = i >> (j * 8);
69
72
  i -= tag[j] << (j * 8);
70
73
  }
71
-
74
+
72
75
  for (j = 3; j >= 0; j -= 1)
73
76
  {
74
77
  if (tag[j] != '\0')
75
78
  break;
76
79
  }
77
-
80
+
78
81
  return rb_str_new(tag, j + 1);
79
82
  }
80
83
 
84
+ /* Returns the bit rate. */
81
85
  static VALUE ffrs_bit_rate(VALUE self)
82
86
  {
83
87
  AVStream *stream = ffrs_get_stream(self);
84
88
  return INT2NUM(stream->codec->bit_rate);
85
89
  }
86
90
 
87
- static VALUE ffrs_alloc(VALUE klass)
88
- {
89
- return Data_Wrap_Struct(klass, 0, 0, NULL);
90
- }
91
-
92
- static VALUE ffrs_initialize(VALUE self, VALUE file, VALUE index)
93
- {
94
- AVFormatContext *fmt;
95
- AVStream *stream;
96
- unsigned int i = FIX2UINT(index);
97
-
98
- Data_Get_Struct(file, AVFormatContext, fmt);
99
-
100
- if (i < 0 || i >= fmt->nb_streams)
101
- rb_raise(rb_eIndexError, "Stream index out of range!");
102
-
103
- DATA_PTR(self) = fmt->streams[i];
104
- stream = ffrs_get_stream(self);
105
-
106
- return self;
107
- }
108
-
91
+ /* Returns the frame width. */
109
92
  static VALUE ffrvs_width(VALUE self)
110
93
  {
111
94
  AVStream *stream = ffrs_get_stream(self);
112
95
  return INT2NUM(stream->codec->width);
113
96
  }
114
97
 
98
+ /* Returns the frame height. */
115
99
  static VALUE ffrvs_height(VALUE self)
116
100
  {
117
101
  AVStream *stream = ffrs_get_stream(self);
118
102
  return INT2NUM(stream->codec->height);
119
103
  }
120
104
 
105
+ /* Returns the frame aspect ratio. */
121
106
  static VALUE ffrvs_frame_aspect_ratio(VALUE self)
122
107
  {
123
108
  AVStream *stream = ffrs_get_stream(self);
124
-
109
+
125
110
  if (stream->codec->width == 0 || stream->codec->height == 0)
126
111
  return Qnil;
127
112
  else
128
113
  return rb_funcall(rb_mKernel, rb_intern("Rational"), 2, INT2NUM(stream->codec->width), INT2NUM(stream->codec->height));
129
114
  }
130
115
 
116
+ /* Returns the sample aspect ratio. */
131
117
  static VALUE ffrvs_sample_aspect_ratio(VALUE self)
132
118
  {
133
119
  AVStream *stream = ffrs_get_stream(self);
134
-
120
+
135
121
  if (stream->codec->sample_aspect_ratio.den == 0 || stream->codec->sample_aspect_ratio.num == 0)
136
122
  return rb_funcall(rb_mKernel, rb_intern("Rational"), 2, INT2FIX(1), INT2FIX(1));
137
123
  else
138
124
  return rb_funcall(rb_mKernel, rb_intern("Rational"), 2, INT2NUM(stream->codec->sample_aspect_ratio.num), INT2NUM(stream->codec->sample_aspect_ratio.den));
139
125
  }
140
126
 
127
+ /* Returns the real aspect ratio. */
141
128
  static VALUE ffrvs_real_aspect_ratio(VALUE self)
142
129
  {
143
130
  VALUE x, y;
144
131
  x = ffrvs_frame_aspect_ratio(self);
145
132
  y = ffrvs_sample_aspect_ratio(self);
146
-
133
+
147
134
  if (x == Qnil || y == Qnil)
148
135
  return Qnil;
149
136
  else
150
137
  return rb_funcall(x, rb_intern("*"), 1, y);
151
138
  }
152
139
 
140
+ /* Returns the frame rate as a Rational. */
153
141
  static VALUE ffrvs_frame_rate(VALUE self)
154
142
  {
155
143
  AVStream *stream = ffrs_get_stream(self);
156
144
  ffrs_open_codec(stream);
157
-
145
+
158
146
  if (stream->r_frame_rate.den && stream->r_frame_rate.num)
159
147
  return rb_funcall(rb_mKernel, rb_intern("Rational"), 2, INT2NUM(stream->r_frame_rate.num), INT2NUM(stream->r_frame_rate.den));
160
148
  else
161
149
  return rb_funcall(rb_mKernel, rb_intern("Rational"), 2, INT2NUM(stream->codec->time_base.den), INT2NUM(stream->codec->time_base.num));
162
150
  }
163
151
 
152
+ /* Returns the number of audio channels. */
164
153
  static VALUE ffras_channels(VALUE self)
165
154
  {
166
155
  AVStream *stream = ffrs_get_stream(self);
167
156
  return INT2FIX(stream->codec->channels);
168
157
  }
169
158
 
159
+ /* Returns the sample rate. */
170
160
  static VALUE ffras_sample_rate(VALUE self)
171
161
  {
172
162
  AVStream *stream = ffrs_get_stream(self);
173
163
  return INT2NUM(stream->codec->sample_rate);
174
164
  }
175
165
 
166
+ /* call-seq:
167
+ * new(file, index) -> FFruby::Stream
168
+ *
169
+ * Creates an FFruby::Stream instance using the given FFruby::File and
170
+ * stream index. This should usually only be called by FFruby
171
+ * itself. Access stream instances using FFruby::File#streams
172
+ * instead. */
173
+ static VALUE ffrs_initialize(VALUE self, VALUE file, VALUE index)
174
+ {
175
+ AVFormatContext *fmt;
176
+ AVStream *stream;
177
+ unsigned int i = FIX2UINT(index);
178
+
179
+ Data_Get_Struct(file, AVFormatContext, fmt);
180
+
181
+ if (i < 0 || i >= fmt->nb_streams)
182
+ rb_raise(rb_eIndexError, "Stream index out of range!");
183
+
184
+ DATA_PTR(self) = fmt->streams[i];
185
+ stream = ffrs_get_stream(self);
186
+
187
+ return self;
188
+ }
189
+
176
190
  void Init_ffrs()
177
191
  {
178
- cFFrubyStream = rb_define_class("FFrubyStream", rb_cObject);
192
+ /* Document-class: FFruby::Stream
193
+ *
194
+ * An interface to FFmpeg on any type of stream. Provides access
195
+ * to generic metadata. */
196
+ cFFrubyStream = rb_define_class_under(mFFruby, "Stream", rb_cObject);
179
197
  rb_define_alloc_func(cFFrubyStream, ffrs_alloc);
180
198
  rb_define_method(cFFrubyStream, "initialize", ffrs_initialize, 2);
181
199
  rb_define_method(cFFrubyStream, "codec", ffrs_codec, 0);
182
200
  rb_define_method(cFFrubyStream, "tag", ffrs_tag, 0);
183
201
  rb_define_method(cFFrubyStream, "bit_rate", ffrs_bit_rate, 0);
184
-
185
- cFFrubyVideoStream = rb_define_class("FFrubyVideoStream", cFFrubyStream);
202
+
203
+ /* Document-class: FFruby::VideoStream
204
+ *
205
+ * An interface to FFmpeg on video streams. Provides access to
206
+ * video metadata. */
207
+ cFFrubyVideoStream = rb_define_class_under(mFFruby, "VideoStream", cFFrubyStream);
186
208
  rb_define_method(cFFrubyVideoStream, "width", ffrvs_width, 0);
187
209
  rb_define_method(cFFrubyVideoStream, "height", ffrvs_height, 0);
188
210
  rb_define_method(cFFrubyVideoStream, "frame_aspect_ratio", ffrvs_frame_aspect_ratio, 0);
189
211
  rb_define_method(cFFrubyVideoStream, "sample_aspect_ratio", ffrvs_sample_aspect_ratio, 0);
190
212
  rb_define_method(cFFrubyVideoStream, "real_aspect_ratio", ffrvs_real_aspect_ratio, 0);
191
213
  rb_define_method(cFFrubyVideoStream, "frame_rate", ffrvs_frame_rate, 0);
192
-
193
- cFFrubyAudioStream = rb_define_class("FFrubyAudioStream", cFFrubyStream);
214
+
215
+ /* Document-class: FFruby::AudioStream
216
+ *
217
+ * An interface to FFmpeg on audio streams. Provides access to
218
+ * audio metadata. */
219
+ cFFrubyAudioStream = rb_define_class_under(mFFruby, "AudioStream", cFFrubyStream);
194
220
  rb_define_method(cFFrubyAudioStream, "channels", ffras_channels, 0);
195
221
  rb_define_method(cFFrubyAudioStream, "sample_rate", ffras_sample_rate, 0);
196
222
  }
metadata CHANGED
@@ -1,65 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4.6
3
- specification_version: 2
4
2
  name: ffruby
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-11-06 00:00:00 -05:00
8
- summary: a library that does something with media files!
9
- require_paths:
10
- - lib
11
- email: wayneeseguin at gmail dot com
12
- homepage: ffruby.rubyforge.org
13
- rubyforge_project:
14
- description: a library that does something with media files!
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - James Le Cuirot
15
14
  autorequire:
16
- default_executable:
17
15
  bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-24 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A Ruby interface to FFmpeg's libavformat and libavcodec. It allows you to query metadata from a wide variety of media files through some simple classes.
23
+ email: chewi@aura-online.co.uk
24
+ executables: []
25
+
26
+ extensions:
27
+ - ext/ffruby/extconf.rb
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - ext/ffruby/ffruby.c
31
+ - ext/ffruby/ffrubyfile.c
32
+ - ext/ffruby/ffrubystream.c
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - ext/ffruby/extconf.rb
39
+ - ext/ffruby/ffruby.c
40
+ - ext/ffruby/ffruby.h
41
+ - ext/ffruby/ffrubyfile.c
42
+ - ext/ffruby/ffrubystream.c
18
43
  has_rdoc: true
44
+ homepage: http://rubyforge.org/projects/ffruby/
45
+ licenses:
46
+ - LGPL-2.1
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
19
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
20
54
  requirements:
21
55
  - - ">="
22
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
23
60
  version: "0"
24
- version:
25
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
26
63
  requirements:
27
64
  - - ">="
28
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
29
69
  version: "0"
30
- version:
31
- platform: ruby
70
+ requirements:
71
+ - FFmpeg libraries and also development headers if building.
72
+ rubyforge_project: ffruby
73
+ rubygems_version: 1.3.7
32
74
  signing_key:
33
- cert_chain: []
34
-
35
- post_install_message:
36
- authors:
37
- - "ffruby: James Le Cuirot, gem: Wayne E. Seguin"
38
- files:
39
- - README
40
- - Rakefile
41
- - lib/ffruby
42
- - lib/ffruby/version.rb
43
- - ext/ffruby/ffruby.c
44
- - ext/ffruby/ffrubyfile.c
45
- - ext/ffruby/ffrubystream.c
46
- - ext/ffruby/extconf.rb
75
+ specification_version: 3
76
+ summary: A Ruby interface to FFmpeg's libavformat and libavcodec.
47
77
  test_files: []
48
78
 
49
- rdoc_options:
50
- - --quiet
51
- - --title
52
- - FFruby Reference
53
- - --main
54
- - README
55
- - --inline-source
56
- extra_rdoc_files:
57
- - README
58
- executables: []
59
-
60
- extensions:
61
- - ext/ffruby/extconf.rb
62
- requirements: []
63
-
64
- dependencies: []
65
-
data/README DELETED
@@ -1 +0,0 @@
1
- README
@@ -1,9 +0,0 @@
1
- module FFruby #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 0
5
- TINY = 1
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end