ffi-ffmpeg 0.6.d2b7675f3785 → 0.7.0beae74ee3d7

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.
data/ffi-ffmpeg.gemspec CHANGED
@@ -10,11 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["dmlary@gmail.com"]
11
11
  s.homepage = "http://bitbucket.org/dmlary/ffi-ffmpeg"
12
12
  s.summary = %q{Ruby FFI bindings for FFmpeg libraries}
13
- s.description = %q{Ruby FFI bindings for FFmpeg libraries:
14
- * libavformat
15
- * libavcodec
16
- * libavutil
17
- * libswscale}
13
+ s.description = %q{Ruby FFI bindings for libavformat, libavcodec, libavutil, and libswscale}
18
14
 
19
15
  s.rubyforge_project = "ffi-ffmpeg"
20
16
 
data/lib/ffi/ffmpeg.rb CHANGED
@@ -143,6 +143,7 @@ module FFI
143
143
  end
144
144
 
145
145
  ffi_lib "libavcodec.so.52"
146
+ AV_TIME_BASE = 1000000
146
147
  AV_PARSER_PTS_NB = 4
147
148
 
148
149
  AVDiscard = enum :none, -16,
data/lib/ffmpeg/reader.rb CHANGED
@@ -25,6 +25,11 @@ class FFmpeg::Reader
25
25
  FFI::FFmpeg.dump_format(@av_format_ctx, 0, @filename, 0)
26
26
  end
27
27
 
28
+ # Video duration in (fractional) seconds
29
+ def duration
30
+ @av_format_ctx[:duration].to_f / AV_TIME_BASE
31
+ end
32
+
28
33
  def each_frame(&block)
29
34
  raise ArgumentError, "No block provided" unless block_given?
30
35
 
data/lib/ffmpeg/stream.rb CHANGED
@@ -127,11 +127,30 @@ class FFmpeg::Stream::Video
127
127
  # allocation to later be used as pts.
128
128
  @av_codec_ctx[:get_buffer] = @get_buffer_callback = \
129
129
  FFI::Function.new(:void, [:pointer, :pointer]) do |ctx, frame|
130
+
131
+ # alloc space for our pts value
132
+ # I really want to use FFI::MemoryPointer to alloc here, but
133
+ # due to a ffi bug (https://github.com/ffi/ffi/issues/174), I
134
+ # cannot recover the memory in the release buffer callback.
135
+ # For the time being we'll use av_malloc()/ac_free().
136
+ ptr = FFI::Pointer.new av_malloc(8)
137
+ raise MemoryError, "av_malloc() failed" if ptr.null?
138
+ ptr.write_uint64 @last_pts
139
+
140
+ # Grab our buffer
130
141
  ret = avcodec_default_get_buffer(ctx, frame)
131
- AVFrame.new(frame)[:opaque] = FFI::Pointer.new(@last_pts)
132
- # pp :alloc => @last_pts
142
+
143
+ # shove the pts into it
144
+ AVFrame.new(frame)[:opaque] = ptr
145
+
133
146
  ret
134
147
  end
148
+
149
+ @av_codec_ctx[:release_buffer] = @release_buffer_callback = \
150
+ FFI::Function.new(:void, [:pointer, :pointer]) do |ctx, frame|
151
+ av_free(AVFrame.new(frame)[:opaque])
152
+ avcodec_default_release_buffer(ctx, frame)
153
+ end
135
154
  end
136
155
 
137
156
  def fps
@@ -181,7 +200,8 @@ class FFmpeg::Stream::Video
181
200
  # the AVFrame.
182
201
  @raw_frame.pts = nil
183
202
  @raw_frame.pts = packet[:dts] unless packet[:dts] == AV_NOPTS_VALUE
184
- @raw_frame.pts ||= @raw_frame.av_frame[:opaque].address
203
+ @raw_frame.pts ||=
204
+ FFI::Pointer.new(@raw_frame.av_frame[:opaque]).read_uint64
185
205
 
186
206
  @raw_frame.number = @av_codec_ctx[:frame_number].to_i
187
207
 
@@ -1,3 +1,3 @@
1
1
  module FFmpeg
2
- VERSION = "0.6"
2
+ VERSION = "0.7"
3
3
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.d2b7675f3785
5
- prerelease: 4
4
+ version: 0.7.0beae74ee3d7
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - David M. Lary
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-01 00:00:00.000000000Z
12
+ date: 2011-11-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &7888320 !ruby/object:Gem::Requirement
16
+ requirement: &14840620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,8 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7888320
25
- description: ! "Ruby FFI bindings for FFmpeg libraries:\n * libavformat\n
26
- \ * libavcodec\n * libavutil\n *
27
- libswscale"
24
+ version_requirements: *14840620
25
+ description: Ruby FFI bindings for libavformat, libavcodec, libavutil, and libswscale
28
26
  email:
29
27
  - dmlary@gmail.com
30
28
  executables: []
@@ -70,3 +68,4 @@ signing_key:
70
68
  specification_version: 3
71
69
  summary: Ruby FFI bindings for FFmpeg libraries
72
70
  test_files: []
71
+ has_rdoc: