ffmpeg-ruby 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -8,6 +8,8 @@ ext/ffmpeg_ruby/ffmpeg_avcodec.c
8
8
  ext/ffmpeg_ruby/ffmpeg_avcodec.h
9
9
  ext/ffmpeg_ruby/ffmpeg_avformat.c
10
10
  ext/ffmpeg_ruby/ffmpeg_avformat.h
11
+ ext/ffmpeg_ruby/ffmpeg_avstream.c
12
+ ext/ffmpeg_ruby/ffmpeg_avstream.h
11
13
  ext/ffmpeg_ruby/ffmpeg_ruby.c
12
14
  ext/ffmpeg_ruby/ffmpeg_ruby.h
13
15
  ffmpeg-ruby.gemspec
data/README.rdoc CHANGED
@@ -21,12 +21,15 @@ If you run into trouble, it could be the C bundle not building. This is known to
21
21
 
22
22
  You may need to add +--with+ on mac, to point it to macports' /opt/local for the libraries.
23
23
 
24
- This has worked on my snow leopard machine:
24
+ == Mac Notes
25
+
26
+ Because of the way the library gets built, it needs to match the architecture type of your ruby. You can force it to do this by specifying the ++-arch++ flag. For a 64-bit ruby on Snow Leopard:
25
27
 
26
28
  $ sudo port install ffmpeg
27
29
  (go have coffee)
28
- $ env ARCHFLAGS="-arch x86_64" ruby extconf.rb --with-avformat-dir=/opt/local
29
- make
30
+ $ sudo env ARCHFLAGS="-arch x86_64" gem install ffmpeg-ruby
31
+
32
+ If your machine is 32 bit, the +ARCHFLAGS+ above should be ++ARCHFLAGS="-arch i386"+
30
33
 
31
34
  This will provide you with a bundle you can require.
32
35
 
data/Rakefile CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new("ffmpeg-ruby", "0.1.0") do |p|
5
+ Echoe.new("ffmpeg-ruby", "0.1.2") do |p|
6
6
  p.description = "FFMpeg Ruby Bridge. Call FFMpeg/LibAVCodec/LibAVFormat directly"
7
7
  p.url = "http://github.com/hackerdude/ffmpeg-ruby"
8
8
  p.author = "David Martinez"
9
- p.ignore_pattern = ["tmp/*", "script/*"]
9
+ p.ignore_pattern = ["tmp/*", "script/*", "pkg/*"]
10
10
  p.development_dependencies = [] # TODO How to do native dependencies?
11
11
  end
12
12
 
@@ -82,11 +82,9 @@ VALUE AVCodec_long_name(VALUE self)
82
82
 
83
83
  VALUE AVCodec_name(VALUE self)
84
84
  {
85
- char* tm;
86
85
  AVCodec *ptr;
87
86
  Data_Get_Struct(self, AVCodec, ptr);
88
- tm = ptr->name;
89
- return rb_str_new2(tm);
87
+ return rb_str_new2(ptr->name);
90
88
  }
91
89
 
92
90
  VALUE AVCodec_codec_type(VALUE self)
@@ -167,6 +165,44 @@ VALUE supported_audio_codecs()
167
165
  }
168
166
  return result;
169
167
  }
168
+ /*
169
+ * Similar to avcodec_string but only
170
+ * gets the name using thse same logic
171
+ */
172
+ VALUE avcodec_canonical_name(AVCodecContext *enc)
173
+ {
174
+ const char *codec_name;
175
+ AVCodec *p;
176
+ char buf1[128];
177
+
178
+ p = avcodec_find_decoder(enc->codec_id);
179
+ if (p) {
180
+ codec_name = p->name;
181
+ } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
182
+ /* fake mpeg2 transport stream codec (currently not
183
+ * registered) */
184
+ codec_name = "mpeg2ts";
185
+ } else if (enc->codec_name[0] != '\0') {
186
+ codec_name = enc->codec_name;
187
+ } else {
188
+ /* output avi tags */
189
+ if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
190
+ && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
191
+ snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
192
+ enc->codec_tag & 0xff,
193
+ (enc->codec_tag >> 8) & 0xff,
194
+ (enc->codec_tag >> 16) & 0xff,
195
+ (enc->codec_tag >> 24) & 0xff,
196
+ enc->codec_tag);
197
+ } else {
198
+ snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
199
+ }
200
+ codec_name = buf1;
201
+ }
202
+
203
+ return rb_str_new2(codec_name); // TODO on the ruby side, check enc->mb_decision to add the (hq) if we want to.
204
+ }
205
+
170
206
 
171
207
  void Init_ffmpeg_ruby_avcodec(VALUE module)
172
208
  {
@@ -1,4 +1,5 @@
1
1
  VALUE cFFMpegAVCodecContext;
2
+ VALUE cFFMpegAVCodec;
2
3
 
3
4
  void Init_ffmpeg_ruby_avcodec(VALUE module)
4
5
 
@@ -24,4 +25,5 @@ VALUE AVCodecContext_codec_name(VALUE self);
24
25
  VALUE supported_avcodecs();
25
26
  VALUE supported_video_codecs();
26
27
  VALUE supported_audio_codecs();
28
+ VALUE avcodec_canonical_name(AVCodecContext *enc);
27
29
 
@@ -72,6 +72,21 @@ VALUE AVFormatContext_new(VALUE klaas, VALUE ruby_filename) {
72
72
  return result;
73
73
  }
74
74
 
75
+ VALUE AVFormatContext_streams(VALUE self) {
76
+ AVFormatContext *ptr;
77
+ Data_Get_Struct(self, AVFormatContext, ptr);
78
+ VALUE result = rb_ary_new();
79
+ int i;
80
+ for(i=0; i<ptr->nb_streams; i++) {
81
+ // Get a pointer to the codec context for the video stream
82
+ AVStream *pStream = ptr->streams[i];
83
+ VALUE rStream = Data_Wrap_Struct(cFFMpegAVStream, AVStream_mark, AVStream_free, pStream);
84
+ rb_obj_call_init(rStream,0,0);
85
+ rb_ary_push(result, rStream);
86
+ }
87
+ return result;
88
+ }
89
+
75
90
  /* Return all the AVCodecContext entries for all streams in the file */
76
91
  VALUE AVFormatContext_codec_contexts(VALUE self) {
77
92
  AVFormatContext *ptr;
@@ -135,6 +150,7 @@ void Init_ffmpeg_ruby_avformat(VALUE module)
135
150
  cFFMpegAVFormatContext = rb_define_class_under(module, "AVFormatContext", rb_cObject);
136
151
  rb_define_singleton_method(cFFMpegAVFormatContext, "new", AVFormatContext_new, 1);
137
152
  rb_define_method(cFFMpegAVFormatContext, "close_file", AVFormatContext_close_file, 0);
153
+ rb_define_method(cFFMpegAVFormatContext, "streams", AVFormatContext_streams, 0);
138
154
  rb_define_method(cFFMpegAVFormatContext, "duration", AVFormatContext_duration, 0);
139
155
  rb_define_method(cFFMpegAVFormatContext, "title", AVFormatContext_title, 0);
140
156
  rb_define_method(cFFMpegAVFormatContext, "copyright", AVFormatContext_copyright, 0);
@@ -15,6 +15,7 @@ VALUE AVFormatContext_duration(VALUE);
15
15
  VALUE AVFormatContext_close_file(VALUE);
16
16
  VALUE AVFormatContext_new(VALUE, VALUE);
17
17
  VALUE AVFormatContext_codec_contexts(VALUE);
18
+ VALUE AVFormatContext_streams(VALUE);
18
19
  VALUE AVFormatContext_title(VALUE);
19
20
  VALUE AVFormatContext_author(VALUE);
20
21
  VALUE AVFormatContext_copyright(VALUE);
@@ -22,7 +23,11 @@ VALUE AVFormatContext_bit_rate(VALUE);
22
23
  VALUE AVFormatContext_album(VALUE);
23
24
  void Init_ffmpeg_ruby_avformat(VALUE module);
24
25
 
25
- // Forward declaring some necessary avcodec stuff
26
+ // Forward declaring some necessary stuff from other modules
26
27
  void AVCodecContext_mark(void *v);
27
28
  void AVCodecContext_free(void *v);
28
29
  extern VALUE cFFMpegAVCodecContext;
30
+
31
+ void AVStream_mark(void *v);
32
+ void AVStream_free(void *v);
33
+ extern VALUE cFFMpegAVStream;
@@ -0,0 +1,50 @@
1
+ #include "ruby.h"
2
+ #include <libavformat/avformat.h>
3
+ #include "ffmpeg_avstream.h"
4
+
5
+ void Init_ffmpeg_ruby_avstream(VALUE module)
6
+ {
7
+ cFFMpegAVStream = rb_define_class_under(module, "AVStream", rb_cObject);
8
+ rb_define_method(cFFMpegAVStream, "canonical_codec_name", AVStream_canonical_codec_name, 0);
9
+ rb_define_method(cFFMpegAVStream, "codec", AVStream_codec, 0);
10
+ rb_define_method(cFFMpegAVStream, "codec_context", AVStream_codec_context, 0);
11
+ }
12
+
13
+ void AVStream_free(void *v) {}
14
+ void AVStream_mark(void *v) {}
15
+
16
+ VALUE AVStream_canonical_codec_name(VALUE self)
17
+ {
18
+ AVStream *ptr;
19
+ AVCodec *c;
20
+
21
+ Data_Get_Struct(self, AVStream, ptr);
22
+ //char buf[256];
23
+ c =avcodec_canonical_name(ptr->codec);
24
+ return c;
25
+ }
26
+
27
+ VALUE AVStream_codec(VALUE self)
28
+ {
29
+ AVStream *pStream;
30
+ AVCodec *c;
31
+ Data_Get_Struct(self, AVStream, pStream);
32
+ c = avcodec_find_decoder(pStream->codec->codec_id);
33
+ if (!c) {
34
+ return Qnil;
35
+ }
36
+ VALUE rCodec = Data_Wrap_Struct(cFFMpegAVCodec, AVCodec_mark, AVCodec_free, c);
37
+ rb_obj_call_init(rCodec,0,0);
38
+ return rCodec;
39
+ }
40
+
41
+ VALUE AVStream_codec_context(VALUE self)
42
+ {
43
+ AVStream *pStream;
44
+ AVCodecContext *c;
45
+ Data_Get_Struct(self, AVStream, pStream);
46
+ c = pStream->codec;
47
+ VALUE rCodec = Data_Wrap_Struct(cFFMpegAVCodecContext, AVCodecContext_mark, AVCodecContext_free, c);
48
+ rb_obj_call_init(rCodec,0,0);
49
+ return rCodec;
50
+ }
@@ -0,0 +1,20 @@
1
+ #include <libavformat/avformat.h>
2
+ #include <ruby.h>
3
+
4
+ VALUE cFFMpegAVStream;
5
+
6
+ void AVStream_mark(void *v);
7
+ void AVStream_free(void *v);
8
+ VALUE AVStream_canonical_codec_name(VALUE);
9
+ VALUE AVStream_codec(VALUE);
10
+ VALUE AVStream_codec_context(VALUE);
11
+
12
+
13
+ // forward declaring some stuff from codec module
14
+ void AVCodec_mark(void *v);
15
+ void AVCodec_free(void *v);
16
+ void AVCodecContext_mark(void *v);
17
+ void AVCodecContext_free(void *v);
18
+ extern VALUE cFFMpegAVCodec;
19
+ extern VALUE cFFMpegAVCodecContext;
20
+ VALUE avcodec_canonical_name(AVCodecContext *enc);
@@ -12,5 +12,6 @@ void Init_ffmpeg_ruby()
12
12
  mFFMpeg = rb_define_module("FFMpeg");
13
13
  Init_ffmpeg_ruby_avcodec(mFFMpeg);
14
14
  Init_ffmpeg_ruby_avformat(mFFMpeg);
15
+ Init_ffmpeg_ruby_avstream(mFFMpeg);
15
16
  }
16
17
 
data/ffmpeg-ruby.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ffmpeg-ruby}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["David Martinez"]
9
- s.date = %q{2010-02-10}
9
+ s.date = %q{2010-02-16}
10
10
  s.description = %q{FFMpeg Ruby Bridge. Call FFMpeg/LibAVCodec/LibAVFormat directly}
11
11
  s.email = %q{}
12
12
  s.extensions = ["ext/ffmpeg_ruby/extconf.rb"]
13
- s.extra_rdoc_files = ["README.rdoc", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Info.plist", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Resources/DWARF/conftest", "ext/ffmpeg_ruby/extconf.rb", "ext/ffmpeg_ruby/ffmpeg_avcodec.c", "ext/ffmpeg_ruby/ffmpeg_avcodec.h", "ext/ffmpeg_ruby/ffmpeg_avformat.c", "ext/ffmpeg_ruby/ffmpeg_avformat.h", "ext/ffmpeg_ruby/ffmpeg_ruby.c", "ext/ffmpeg_ruby/ffmpeg_ruby.h", "lib/ffmpeg-ruby.rb", "tasks/mac_specific.rake"]
14
- s.files = ["Manifest", "README.rdoc", "Rakefile", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Info.plist", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Resources/DWARF/conftest", "ext/ffmpeg_ruby/extconf.rb", "ext/ffmpeg_ruby/ffmpeg_avcodec.c", "ext/ffmpeg_ruby/ffmpeg_avcodec.h", "ext/ffmpeg_ruby/ffmpeg_avformat.c", "ext/ffmpeg_ruby/ffmpeg_avformat.h", "ext/ffmpeg_ruby/ffmpeg_ruby.c", "ext/ffmpeg_ruby/ffmpeg_ruby.h", "ffmpeg-ruby.gemspec", "lib/ffmpeg-ruby.rb", "tasks/mac_specific.rake", "test/test.rb"]
13
+ s.extra_rdoc_files = ["README.rdoc", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Info.plist", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Resources/DWARF/conftest", "ext/ffmpeg_ruby/extconf.rb", "ext/ffmpeg_ruby/ffmpeg_avcodec.c", "ext/ffmpeg_ruby/ffmpeg_avcodec.h", "ext/ffmpeg_ruby/ffmpeg_avformat.c", "ext/ffmpeg_ruby/ffmpeg_avformat.h", "ext/ffmpeg_ruby/ffmpeg_avstream.c", "ext/ffmpeg_ruby/ffmpeg_avstream.h", "ext/ffmpeg_ruby/ffmpeg_ruby.c", "ext/ffmpeg_ruby/ffmpeg_ruby.h", "lib/ffmpeg-ruby.rb", "tasks/mac_specific.rake"]
14
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Info.plist", "ext/ffmpeg_ruby/conftest.dSYM/Contents/Resources/DWARF/conftest", "ext/ffmpeg_ruby/extconf.rb", "ext/ffmpeg_ruby/ffmpeg_avcodec.c", "ext/ffmpeg_ruby/ffmpeg_avcodec.h", "ext/ffmpeg_ruby/ffmpeg_avformat.c", "ext/ffmpeg_ruby/ffmpeg_avformat.h", "ext/ffmpeg_ruby/ffmpeg_avstream.c", "ext/ffmpeg_ruby/ffmpeg_avstream.h", "ext/ffmpeg_ruby/ffmpeg_ruby.c", "ext/ffmpeg_ruby/ffmpeg_ruby.h", "ffmpeg-ruby.gemspec", "lib/ffmpeg-ruby.rb", "tasks/mac_specific.rake", "test/test.rb"]
15
15
  s.homepage = %q{http://github.com/hackerdude/ffmpeg-ruby}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ffmpeg-ruby", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib", "ext"]
data/test/test.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "#{File.dirname(__FILE__)}/../lib/ffmpeg-ruby"
2
+ require 'rubygems'
3
+ require 'ruby-debug'
2
4
 
3
5
  puts "Here are the video codecs I support, of the #{FFMpeg::AVCodec.supported_avcodecs.length} codecs:"
4
6
  FFMpeg::AVCodec.supported_video_codecs.each{|k,v|
@@ -22,7 +24,13 @@ puts " Author: #{f.author}"
22
24
  puts " Album: #{f.album}"
23
25
  puts " Bit Rate: #{f.bit_rate}"
24
26
 
25
- puts "\nCodec Information for #{filename}"
27
+ puts "\nStream information:"
28
+ f.streams.each{|s|
29
+ puts " Canonical Codec: #{s.canonical_codec_name}"
30
+ puts " Codec Long Name: #{s.codec_context.long_name}"
31
+ }
32
+
33
+ puts "\nCodec Context Information for #{filename}"
26
34
  f.codec_contexts.each_with_index{|ctx,i|
27
35
  puts "Codec info for stream ##{i}"
28
36
  puts " Type: #{ctx.codec_type} (#{FFMpeg::MAP_CODEC_TYPES[ctx.codec_type]})"
@@ -34,6 +42,8 @@ f.codec_contexts.each_with_index{|ctx,i|
34
42
  puts " Audio Sample Rate: #{ctx.sample_rate}"
35
43
  }
36
44
 
45
+
46
+
37
47
  puts "-- Now dumping the format:"
38
48
  f.dump_format
39
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffmpeg-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Martinez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-10 00:00:00 -08:00
12
+ date: 2010-02-16 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,6 +28,8 @@ extra_rdoc_files:
28
28
  - ext/ffmpeg_ruby/ffmpeg_avcodec.h
29
29
  - ext/ffmpeg_ruby/ffmpeg_avformat.c
30
30
  - ext/ffmpeg_ruby/ffmpeg_avformat.h
31
+ - ext/ffmpeg_ruby/ffmpeg_avstream.c
32
+ - ext/ffmpeg_ruby/ffmpeg_avstream.h
31
33
  - ext/ffmpeg_ruby/ffmpeg_ruby.c
32
34
  - ext/ffmpeg_ruby/ffmpeg_ruby.h
33
35
  - lib/ffmpeg-ruby.rb
@@ -43,6 +45,8 @@ files:
43
45
  - ext/ffmpeg_ruby/ffmpeg_avcodec.h
44
46
  - ext/ffmpeg_ruby/ffmpeg_avformat.c
45
47
  - ext/ffmpeg_ruby/ffmpeg_avformat.h
48
+ - ext/ffmpeg_ruby/ffmpeg_avstream.c
49
+ - ext/ffmpeg_ruby/ffmpeg_avstream.h
46
50
  - ext/ffmpeg_ruby/ffmpeg_ruby.c
47
51
  - ext/ffmpeg_ruby/ffmpeg_ruby.h
48
52
  - ffmpeg-ruby.gemspec