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.
- data/Rakefile +1 -1
- data/ext/avinput.cc +41 -52
- data/ext/avinput.hh +2 -1
- metadata +4 -4
data/Rakefile
CHANGED
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
|
35
|
+
m_swsContext(NULL), m_vFrame(NULL), m_aFrame(NULL)
|
36
36
|
{
|
37
37
|
try {
|
38
|
-
int err =
|
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 =
|
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 =
|
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
|
-
|
71
|
-
ERRORMACRO(
|
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 =
|
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 (
|
102
|
-
av_free(
|
103
|
-
|
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
|
-
|
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,
|
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
|
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,
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
int
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
packet
|
192
|
-
|
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
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 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-
|
18
|
+
date: 2013-04-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: malloc
|