hornetseye-ffmpeg 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
7
7
  require 'rbconfig'
8
8
 
9
9
  PKG_NAME = 'hornetseye-ffmpeg'
10
- PKG_VERSION = '0.7.0'
10
+ PKG_VERSION = '0.8.0'
11
11
  CFG = RbConfig::CONFIG
12
12
  CXX = ENV[ 'CXX' ] || 'g++'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
data/ext/avoutput.cc CHANGED
@@ -31,7 +31,8 @@ using namespace std;
31
31
  VALUE AVOutput::cRubyClass = Qnil;
32
32
 
33
33
  AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
34
- int timeBaseNum, int timeBaseDen, enum CodecID videoCodec,
34
+ int timeBaseNum, int timeBaseDen, int aspectRatioNum,
35
+ int aspectRatioDen, enum CodecID videoCodec,
35
36
  int audioBitRate, int sampleRate, int channels,
36
37
  enum CodecID audioCodec ) throw (Error):
37
38
  m_mrl( mrl ), m_oc( NULL ), m_video_st( NULL ), m_audio_st( NULL),
@@ -57,6 +58,8 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
57
58
  "Output format does not support video" );
58
59
  m_video_st = av_new_stream( m_oc, 0 );
59
60
  ERRORMACRO( m_video_st != NULL, Error, , "Could not allocate video stream" );
61
+ m_video_st->sample_aspect_ratio.num = aspectRatioNum;
62
+ m_video_st->sample_aspect_ratio.den = aspectRatioDen;
60
63
  AVCodecContext *c = m_video_st->codec;
61
64
  c->codec_id = videoCodec != CODEC_ID_NONE ? videoCodec : format->video_codec;
62
65
  c->codec_type = CODEC_TYPE_VIDEO;
@@ -67,6 +70,8 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
67
70
  c->time_base.den = timeBaseDen;
68
71
  c->gop_size = 12;
69
72
  c->pix_fmt = PIX_FMT_YUV420P;
73
+ c->sample_aspect_ratio.num = aspectRatioNum;
74
+ c->sample_aspect_ratio.den = aspectRatioDen;
70
75
  if ( m_oc->oformat->flags & AVFMT_GLOBALHEADER )
71
76
  c->flags |= CODEC_FLAG_GLOBAL_HEADER;
72
77
  if ( channels > 0 ) {
@@ -78,6 +83,8 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
78
83
  c->bit_rate = audioBitRate;
79
84
  c->sample_rate = sampleRate;
80
85
  c->channels = channels;
86
+ if ( m_oc->oformat->flags & AVFMT_GLOBALHEADER )
87
+ c->flags |= CODEC_FLAG_GLOBAL_HEADER;
81
88
  };
82
89
  ERRORMACRO( av_set_parameters( m_oc, NULL ) >= 0, Error, ,
83
90
  "Invalid output format parameters: " << strerror( errno ) );
@@ -296,7 +303,7 @@ VALUE AVOutput::registerRubyClass( VALUE rbModule )
296
303
  {
297
304
  cRubyClass = rb_define_class_under( rbModule, "AVOutput", rb_cObject );
298
305
  rb_define_singleton_method( cRubyClass, "new",
299
- RUBY_METHOD_FUNC( wrapNew ), 11 );
306
+ RUBY_METHOD_FUNC( wrapNew ), 13 );
300
307
  rb_define_const( cRubyClass, "CODEC_ID_NONE",
301
308
  INT2FIX( CODEC_ID_NONE ) );
302
309
  rb_define_const( cRubyClass, "CODEC_ID_MPEG1VIDEO",
@@ -781,6 +788,7 @@ void AVOutput::deleteRubyObject( void *ptr )
781
788
 
782
789
  VALUE AVOutput::wrapNew( VALUE rbClass, VALUE rbMRL, VALUE rbBitRate, VALUE rbWidth,
783
790
  VALUE rbHeight, VALUE rbTimeBaseNum, VALUE rbTimeBaseDen,
791
+ VALUE rbAspectRatioNum, VALUE rbAspectRatioDen,
784
792
  VALUE rbVideoCodec, VALUE rbAudioBitRate, VALUE rbSampleRate,
785
793
  VALUE rbChannels, VALUE rbAudioCodec )
786
794
  {
@@ -790,6 +798,8 @@ VALUE AVOutput::wrapNew( VALUE rbClass, VALUE rbMRL, VALUE rbBitRate, VALUE rbWi
790
798
  AVOutputPtr ptr( new AVOutput( StringValuePtr( rbMRL ), NUM2INT( rbBitRate ),
791
799
  NUM2INT( rbWidth ), NUM2INT( rbHeight ),
792
800
  NUM2INT( rbTimeBaseNum ), NUM2INT( rbTimeBaseDen ),
801
+ NUM2INT( rbAspectRatioNum ),
802
+ NUM2INT( rbAspectRatioDen ),
793
803
  (enum CodecID)NUM2INT( rbVideoCodec ),
794
804
  NUM2INT( rbAudioBitRate ), NUM2INT( rbSampleRate ),
795
805
  NUM2INT( rbChannels ),
data/ext/avoutput.hh CHANGED
@@ -42,7 +42,8 @@ class AVOutput
42
42
  {
43
43
  public:
44
44
  AVOutput( const std::string &mrl, int videoBitRate, int width, int height,
45
- int timeBaseNum, int timeBaseDen, enum CodecID videoCodec,
45
+ int timeBaseNum, int timeBaseDen, int aspectRatioNum,
46
+ int aspectRatioDen, enum CodecID videoCodec,
46
47
  int audioBitRate, int sampleRate, int channels,
47
48
  enum CodecID audioCodec ) throw (Error);
48
49
  virtual ~AVOutput(void);
@@ -56,6 +57,7 @@ public:
56
57
  static void deleteRubyObject( void *ptr );
57
58
  static VALUE wrapNew( VALUE rbClass, VALUE rbMRL, VALUE rbBitRate, VALUE rbWidth,
58
59
  VALUE rbHeight, VALUE rbTimeBaseNum, VALUE rbTimeBaseDen,
60
+ VALUE rbAspectRatioNum, VALUE rbAspectRatioDen,
59
61
  VALUE rbVideoCodec, VALUE rbAudioBitRate, VALUE rbSampleRate,
60
62
  VALUE rbChannels, VALUE rbAudioCodec );
61
63
  static VALUE wrapClose( VALUE rbSelf );
@@ -23,19 +23,27 @@ module Hornetseye
23
23
 
24
24
  alias_method :orig_new, :new
25
25
 
26
- def new( mrl, video_bit_rate, width, height, frame_rate, video_codec = nil,
27
- have_audio = false, audio_bit_rate = 64000, sample_rate = 44100,
28
- channels = 2, audio_codec = nil )
26
+ def new( mrl, video_bit_rate, width, height, frame_rate, aspect_ratio = 1,
27
+ video_codec = nil, have_audio = false, audio_bit_rate = 64000,
28
+ sample_rate = 44100, channels = 2, audio_codec = nil )
29
29
  if frame_rate.is_a? Float
30
30
  frame_rate = Rational( 90000, ( 90000 / frame_rate ).to_i )
31
31
  end
32
- orig_new mrl, video_bit_rate, width, height,
33
- frame_rate.denominator, frame_rate.numerator,
34
- video_codec || CODEC_ID_NONE,
35
- have_audio ? audio_bit_rate : 0,
36
- have_audio ? sample_rate : 0,
37
- have_audio ? channels : 0,
38
- audio_codec || CODEC_ID_NONE
32
+ retval = orig_new mrl, video_bit_rate, width, height,
33
+ frame_rate.denominator, frame_rate.numerator,
34
+ aspect_ratio.numerator, aspect_ratio.denominator,
35
+ video_codec || CODEC_ID_NONE,
36
+ have_audio ? audio_bit_rate : 0,
37
+ have_audio ? sample_rate : 0,
38
+ have_audio ? channels : 0,
39
+ audio_codec || CODEC_ID_NONE
40
+ if have_audio
41
+ retval.instance_eval do
42
+ @audio_buffer = Hornetseye::MultiArray( SINT, channels, frame_size ).new
43
+ @audio_samples = 0
44
+ end
45
+ end
46
+ retval
39
47
  end
40
48
 
41
49
  end
@@ -51,12 +59,37 @@ module Hornetseye
51
59
  alias_method :orig_write_audio, :write_audio
52
60
 
53
61
  def write_audio( frame )
54
- if frame.shape != [ channels, frame_size ]
55
- raise "Audio frame must have #{channels} channels and #{frame_size} " +
56
- "samples (but had #{frame.shape[0]} channels and #{frame.shape[1]} " +
57
- "samples)"
62
+ unless frame.typecode == SINT
63
+ raise "Audio frame must have elements of type SINT (but elements were of " +
64
+ "type #{frame.typecode})"
65
+ end
66
+ unless frame.dimension == 2
67
+ raise "Audio frame must have 2 dimensions (but had #{frame.dimensions})"
68
+ end
69
+ unless frame.shape.first == channels
70
+ raise "Audio frame must have #{channels} channels " +
71
+ "(but had #{frame.shape.first})"
72
+ end
73
+ frame_type = Hornetseye::Sequence UBYTE, frame_size * 2 * channels
74
+ remaining = frame
75
+ while @audio_samples + remaining.shape.last >= frame_size
76
+ if @audio_samples > 0
77
+ @audio_buffer[ @audio_samples ... frame_size ] =
78
+ remaining[ 0 ... frame_size - @audio_samples ]
79
+ orig_write_audio frame_type.new( @audio_buffer.memory )
80
+ remaining = remaining[ 0 ... channels,
81
+ frame_size - @audio_samples ... remaining.shape.last ]
82
+ @audio_samples = 0
83
+ else
84
+ orig_write_audio frame_type.new( remaining.memory )
85
+ remaining = remaining[ 0 ... channels, frame_size ... remaining.shape.last ]
86
+ end
87
+ end
88
+ if remaining.shape.last > 0
89
+ @audio_buffer[ 0 ... channels, 0 ... remaining.shape.last ] = remaining
90
+ @audio_samples = remaining.shape.last
58
91
  end
59
- orig_write_audio Sequence( UBYTE, frame.storage_size ).new( frame.memory )
92
+ frame
60
93
  end
61
94
 
62
95
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 7
7
+ - 8
8
8
  - 0
9
- version: 0.7.0
9
+ version: 0.8.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-13 00:00:00 +00:00
17
+ date: 2010-11-14 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency