hornetseye-ffmpeg 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/ext/avinput.cc +41 -52
  3. data/ext/avinput.hh +2 -1
  4. metadata +4 -4
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 = '1.1.1'
10
+ PKG_VERSION = '1.1.2'
11
11
  CFG = RbConfig::CONFIG
12
12
  CXX = ENV[ 'CXX' ] || 'g++'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
data/ext/avinput.cc CHANGED
@@ -32,13 +32,13 @@ AVInput::AVInput( const string &mrl, bool audio ) throw (Error):
32
32
  m_mrl( mrl ), m_ic( NULL ), m_videoDec( NULL ), m_audioDec( NULL ),
33
33
  m_videoCodec( NULL ), m_audioCodec( NULL ),
34
34
  m_videoStream( -1 ), m_audioStream( -1 ), m_videoPts( 0 ), m_audioPts( 0 ),
35
- m_swsContext( NULL ), m_avFrame( NULL )
35
+ m_swsContext(NULL), m_vFrame(NULL), m_aFrame(NULL)
36
36
  {
37
37
  try {
38
- int err = av_open_input_file( &m_ic, mrl.c_str(), NULL, 0, NULL );
38
+ int err = avformat_open_input(&m_ic, mrl.c_str(), NULL, NULL);
39
39
  ERRORMACRO( err >= 0, Error, , "Error opening file \"" << mrl << "\": "
40
40
  << strerror( errno ) );
41
- err = av_find_stream_info( m_ic );
41
+ err = avformat_find_stream_info(m_ic, NULL);
42
42
  ERRORMACRO( err >= 0, Error, , "Error finding stream info for file \""
43
43
  << mrl << "\": " << strerror( errno ) );
44
44
  for ( unsigned int i=0; i<m_ic->nb_streams; i++ ) {
@@ -57,7 +57,7 @@ AVInput::AVInput( const string &mrl, bool audio ) throw (Error):
57
57
  m_videoCodec = avcodec_find_decoder( m_videoDec->codec_id );
58
58
  ERRORMACRO( m_videoCodec != NULL, Error, , "Could not find video decoder for "
59
59
  "file \"" << mrl << "\"" );
60
- err = avcodec_open( m_videoDec, m_videoCodec );
60
+ err = avcodec_open2(m_videoDec, m_videoCodec, NULL);
61
61
  if ( err < 0 ) {
62
62
  m_videoCodec = NULL;
63
63
  ERRORMACRO( false, Error, , "Error opening video codec for file \""
@@ -67,8 +67,10 @@ AVInput::AVInput( const string &mrl, bool audio ) throw (Error):
67
67
  m_videoDec->pix_fmt,
68
68
  m_videoDec->width, m_videoDec->height,
69
69
  PIX_FMT_YUV420P, SWS_FAST_BILINEAR, 0, 0, 0 );
70
- m_avFrame = avcodec_alloc_frame();
71
- ERRORMACRO( m_avFrame, Error, , "Error allocating frame" );
70
+ m_vFrame = avcodec_alloc_frame();
71
+ ERRORMACRO(m_vFrame, Error, , "Error allocating frame");
72
+ m_aFrame = avcodec_alloc_frame();
73
+ ERRORMACRO(m_aFrame, Error, , "Error allocating frame");
72
74
  };
73
75
  if ( m_audioStream >= 0 )
74
76
  m_audioDec = m_ic->streams[ m_audioStream ]->codec;
@@ -76,7 +78,7 @@ AVInput::AVInput( const string &mrl, bool audio ) throw (Error):
76
78
  m_audioCodec = avcodec_find_decoder( m_audioDec->codec_id );
77
79
  ERRORMACRO( m_audioCodec != NULL, Error, , "Could not find audio decoder for "
78
80
  "file \"" << mrl << "\"" );
79
- err = avcodec_open( m_audioDec, m_audioCodec );
81
+ err = avcodec_open2( m_audioDec, m_audioCodec, NULL);
80
82
  if ( err < 0 ) {
81
83
  m_audioCodec = NULL;
82
84
  ERRORMACRO( false, Error, , "Error opening audio codec for file \""
@@ -98,9 +100,13 @@ void AVInput::close(void)
98
100
  {
99
101
  m_audioFrame.reset();
100
102
  m_videoFrame.reset();
101
- if ( m_avFrame ) {
102
- av_free( m_avFrame );
103
- m_avFrame = NULL;
103
+ if (m_vFrame) {
104
+ av_free(m_vFrame);
105
+ m_vFrame = NULL;
106
+ };
107
+ if (m_aFrame) {
108
+ av_free(m_aFrame);
109
+ m_aFrame = NULL;
104
110
  };
105
111
  if ( m_swsContext ) {
106
112
  sws_freeContext( m_swsContext );
@@ -120,7 +126,7 @@ void AVInput::close(void)
120
126
  m_audioStream = -1;
121
127
  m_videoStream = -1;
122
128
  if ( m_ic ) {
123
- av_close_input_file( m_ic );
129
+ avformat_close_input(&m_ic);
124
130
  m_ic = NULL;
125
131
  };
126
132
  }
@@ -136,10 +142,10 @@ void AVInput::readAV(void) throw (Error)
136
142
  while ( av_read_frame( m_ic, &packet ) >= 0 ) {
137
143
  if ( packet.stream_index == m_videoStream ) {
138
144
  int frameFinished;
139
- int err = avcodec_decode_video2( m_videoDec, m_avFrame, &frameFinished,
145
+ int err = avcodec_decode_video2( m_videoDec, m_vFrame, &frameFinished,
140
146
  &packet );
141
147
  ERRORMACRO( err >= 0, Error, ,
142
- "Error decoding video frame of video \"" << m_mrl << "\"" );
148
+ "Error decoding video frame of file \"" << m_mrl << "\"" );
143
149
  if ( firstPacketPts == AV_NOPTS_VALUE ) firstPacketPts = packet.pts;
144
150
  if ( frameFinished ) {
145
151
  if ( packet.dts != AV_NOPTS_VALUE )
@@ -163,51 +169,33 @@ void AVInput::readAV(void) throw (Error)
163
169
  picture.linesize[0] = widtha;
164
170
  picture.linesize[1] = width2a;
165
171
  picture.linesize[2] = width2a;
166
- sws_scale( m_swsContext, m_avFrame->data, m_avFrame->linesize, 0,
172
+ sws_scale( m_swsContext, m_vFrame->data, m_vFrame->linesize, 0,
167
173
  m_videoDec->height, picture.data, picture.linesize );
168
174
  break;
169
175
  } else
170
176
  av_free_packet( &packet );
171
177
  } else if ( packet.stream_index == m_audioStream ) {
172
178
  if ( packet.pts != AV_NOPTS_VALUE ) m_audioPts = packet.pts;
173
- m_audioFrame.reset();
174
- unsigned char *data = packet.data;
175
- int size = packet.size;
176
- while ( packet.size > 0 ) {
177
- short int *buffer;
178
- ERRORMACRO(posix_memalign((void **)&buffer, 16,
179
- AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 2) == 0, Error, ,
180
- "Error allocating aligned memory");
181
- buffer[ AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 4 - 1 ] = '\000';
182
- int bufSize = AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 2;
183
- int len = avcodec_decode_audio3( m_audioDec, buffer, &bufSize, &packet );
184
- if ( len < 0 ) {
185
- free( buffer );
186
- m_audioFrame.reset();
187
- ERRORMACRO( false, Error, , "Error decoding audio frame of video \""
188
- << m_mrl << "\"" );
189
- };
190
- packet.data += len;
191
- packet.size -= len;
192
- if ( bufSize > 0 ) {
193
- if ( m_audioFrame.get() ) {
194
- SequencePtr extended( new Sequence( m_audioFrame->size() + bufSize ) );
195
- memcpy( extended->data(), m_audioFrame->data(), m_audioFrame->size() );
196
- memcpy( extended->data() + m_audioFrame->size(), buffer, bufSize );
197
- m_audioFrame = extended;
198
- } else {
199
- m_audioFrame = SequencePtr( new Sequence( bufSize ) );
200
- memcpy( m_audioFrame->data(), buffer, bufSize );
201
- };
202
- };
203
- free( buffer );
204
- };
205
- packet.data = data;
206
- packet.size = size;
207
- av_free_packet( &packet );
208
- if ( m_audioFrame.get() ) break;
209
- } else
210
- av_free_packet( &packet );
179
+ int frameFinished;
180
+ int len = avcodec_decode_audio4(m_audioDec, m_aFrame, &frameFinished, &packet);
181
+ ERRORMACRO(len >= 0, Error, ,
182
+ "Error decoding audio frame of file \"" << m_mrl << "\"" );
183
+ if (firstPacketPts == AV_NOPTS_VALUE) firstPacketPts = packet.pts;
184
+ if (frameFinished) {
185
+ if (packet.dts != AV_NOPTS_VALUE)
186
+ m_audioPts = packet.dts;
187
+ else
188
+ m_audioPts = firstPacketPts;
189
+ int bufSize = av_samples_get_buffer_size(NULL, m_audioDec->channels,
190
+ m_aFrame->nb_samples,
191
+ m_audioDec->sample_fmt, 1);
192
+ m_audioFrame = SequencePtr(new Sequence(bufSize));
193
+ memcpy( m_audioFrame->data(), m_aFrame->data[0], bufSize);
194
+ av_free_packet( &packet );
195
+ break;
196
+ } else
197
+ av_free_packet( &packet );
198
+ };
211
199
  };
212
200
  ERRORMACRO( m_videoFrame.get() || m_audioFrame.get(), Error, ,
213
201
  "No more frames available" );
@@ -359,6 +347,7 @@ VALUE AVInput::registerRubyClass( VALUE rbModule )
359
347
  rb_define_method( cRubyClass, "seek", RUBY_METHOD_FUNC( wrapSeek ), 1 );
360
348
  rb_define_method( cRubyClass, "video_pts", RUBY_METHOD_FUNC( wrapVideoPTS ), 0 );
361
349
  rb_define_method( cRubyClass, "audio_pts", RUBY_METHOD_FUNC( wrapAudioPTS ), 0 );
350
+ return cRubyClass;
362
351
  }
363
352
 
364
353
  void AVInput::deleteRubyObject( void *ptr )
data/ext/avinput.hh CHANGED
@@ -98,7 +98,8 @@ protected:
98
98
  long long m_videoPts;
99
99
  long long m_audioPts;
100
100
  struct SwsContext *m_swsContext;
101
- AVFrame *m_avFrame;
101
+ AVFrame *m_vFrame;
102
+ AVFrame *m_aFrame;
102
103
  FramePtr m_videoFrame;
103
104
  SequencePtr m_audioFrame;
104
105
  };
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hornetseye-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan Wedekind
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-19 00:00:00 Z
18
+ date: 2013-04-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: malloc