Permalink
Browse files

Add bits/bytes_per_sample, expand sample_fmt to sample_format

  • Loading branch information...
drbrain committed Sep 5, 2009
1 parent b51b207 commit 8d537d2a6c414768b2903a2703b87f1f47951c25
Showing with 31 additions and 6 deletions.
  1. +1 −1 bin/ffmpeg_rb
  2. +20 −3 lib/ffmpeg/codec_context.rb
  3. +10 −2 test/test_ffmpeg_codec_context.rb
View
@@ -27,7 +27,7 @@ input.streams.each do |stream|
when :AUDIO then
dsp << " #{stream.time_base.den} Hz"
dsp << " #{codec_context.channels} channels"
- dsp << " #{FFMPEG::SampleFormat::FORMATS[codec_context.sample_fmt]}"
+ dsp << " #{FFMPEG::SampleFormat::FORMATS[codec_context.sample_format]}"
when :VIDEO then
dsp << " frame rate %s" % stream.r_frame_rate
dsp << " size: #{codec_context.dimensions}"
@@ -20,6 +20,19 @@ class FFMPEG::CodecContext
}
C
+ ##
+ # :method: bits_per_sample
+
+ builder.c <<-C
+ int bits_per_sample() {
+ AVCodecContext *codec_context;
+
+ Data_Get_Struct(self, AVCodecContext, codec_context);
+
+ return av_get_bits_per_sample_format(codec_context->sample_fmt);
+ }
+ C
+
##
# :method: encoder
@@ -300,9 +313,9 @@ class FFMPEG::CodecContext
builder.accessor :sample_rate, 'int'
builder.accessor :width, 'int'
- builder.reader :channels, 'int'
- builder.reader :_codec_type, 'int', :codec_type
- builder.reader :sample_fmt, 'int'
+ builder.reader :channels, 'int'
+ builder.reader :_codec_type, 'int', :codec_type
+ builder.reader :sample_format, 'int', :sample_fmt
builder.reader :codec_name, 'char *'
end
@@ -317,6 +330,10 @@ def initialize(stream=nil)
@stream = stream
end
+ def bytes_per_sample
+ bits_per_sample / 8
+ end
+
def codec_type
FFMPEG::Codec.type_name _codec_type
end
@@ -13,6 +13,14 @@ def test_bit_rate
assert_equal 0, @codec_context.bit_rate
end
+ def test_bits_per_sample
+ assert_equal 16, @codec_context.bits_per_sample
+ end
+
+ def test_bytes_per_sample
+ assert_equal 2, @codec_context.bytes_per_sample
+ end
+
def test_codec
assert_equal nil, @codec_context.codec
@@ -54,8 +62,8 @@ def test_pixel_format
assert_equal FFMPEG::PixelFormat::YUV420P, @codec_context.pixel_format
end
- def test_sample_fmt
- assert_equal 1, @codec_context.sample_fmt
+ def test_sample_format
+ assert_equal 1, @codec_context.sample_format
end
def test_time_base

0 comments on commit 8d537d2

Please sign in to comment.