Permalink
Browse files

Audio transcoding checkpoint, audio decoding (appears to) work

  • Loading branch information...
1 parent 83ba2ea commit 0e03948e736307c0b7a6f0db48367aa4a09b996c @drbrain committed Sep 5, 2009
Showing with 128 additions and 203 deletions.
  1. +4 −3 lib/ffmpeg.rb
  2. +3 −0 lib/ffmpeg/codec.rb
  3. +34 −0 lib/ffmpeg/codec_context.rb
  4. +86 −196 lib/ffmpeg/format_context.rb
  5. +1 −4 sample/transcode.rb
View
@@ -131,9 +131,10 @@ def self.builder_defaults(builder)
rb_define_const(c, "TIME_BASE_Q", ffmpeg_rat2obj(time_base_q));
C
- builder.map_c_const 'AV_TIME_BASE' => ['int', :TIME_BASE]
- builder.map_c_const 'URL_WRONLY' => 'int'
- builder.map_c_const 'AV_NOPTS_VALUE' => ['int64_t', :NOPTS_VALUE]
+ builder.map_c_const 'AV_TIME_BASE' => ['int', :TIME_BASE]
+ builder.map_c_const 'URL_WRONLY' => 'int'
+ builder.map_c_const 'AV_NOPTS_VALUE' => ['int64_t', :NOPTS_VALUE]
+ builder.map_c_const 'FF_MIN_BUFFER_SIZE' => ['int', :MIN_BUFFER_SIZE]
end
end
View
@@ -3,6 +3,9 @@ class FFMPEG::Codec
inline :C do |builder|
FFMPEG.builder_defaults builder
+ builder.map_c_const :AVCODEC_MAX_AUDIO_FRAME_SIZE =>
+ ['int', :MAX_AUDIO_FRAME_SIZE]
+
TYPE_CONSTS = [
[:UNKNOWN, :CODEC_TYPE_UNKNOWN, :int],
[:VIDEO, :CODEC_TYPE_VIDEO, :int],
@@ -37,6 +37,40 @@ class FFMPEG::CodecContext
}
C
+ ##
+ # :method: decode_audio
+
+ builder.c <<-C
+ VALUE decode_audio(VALUE buffer, VALUE packet) {
+ AVCodecContext *codec_context;
+ AVPacket *pkt;
+ int16_t *samples;
+ int bytes_used, frame_size;
+
+ if (NIL_P(pkt))
+ return Qnil;
+
+ Data_Get_Struct(self, AVCodecContext, codec_context);
+ Data_Get_Struct(packet, AVPacket, pkt);
+
+ samples = (int16_t *)RSTRING_PTR(buffer);
+ frame_size = RSTRING_LEN(buffer);
+
+ bytes_used = avcodec_decode_audio3(codec_context, samples,
+ &frame_size, pkt);
+
+ ffmpeg_check_error(bytes_used);
+
+ #ifdef rb_str_set_len
+ rb_str_set_len(buffer, frame_size);
+ #else
+ RSTRING(buffer)->len = frame_size;
+ #endif
+
+ return INT2NUM(bytes_used);
+ }
+ C
+
##
# :method: decode_video
Oops, something went wrong.

0 comments on commit 0e03948

Please sign in to comment.