@@ -143,20 +143,18 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
143
143
144
144
void InputFile::seekAtFrame ( const size_t frame )
145
145
{
146
- double fps = 1 ;
147
- // Get Fps from first video stream
148
- if ( _properties.getNbVideoStreams () )
149
- fps = _properties.getVideoProperties ().at ( 0 ).getFps ();
150
-
151
- uint64_t pos = frame / fps * AV_TIME_BASE;
146
+ uint64_t position = frame / getFps () * AV_TIME_BASE;
147
+ seek ( position );
148
+ }
152
149
153
- // Offset of start time
150
+ void InputFile::seek ( uint64_t position )
151
+ {
154
152
if ( (int )_formatContext.getStartTime () != AV_NOPTS_VALUE )
155
- pos += _formatContext.getStartTime ();
153
+ position += _formatContext.getStartTime ();
156
154
157
- if ( av_seek_frame ( &_formatContext.getAVFormatContext (), -1 , pos , AVSEEK_FLAG_BACKWARD ) < 0 )
155
+ if ( av_seek_frame ( &_formatContext.getAVFormatContext (), -1 , position , AVSEEK_FLAG_BACKWARD ) < 0 )
158
156
{
159
- std::cerr << " Error during seek at " << frame << " ( " << pos << " ) in file" << std::endl;
157
+ std::cerr << " Error during seek at " << position << " seconds in file" << std::endl;
160
158
}
161
159
162
160
for ( std::vector<InputStream*>::iterator it = _inputStreams.begin (); it != _inputStreams.end (); ++it )
@@ -186,6 +184,14 @@ InputStream& InputFile::getStream( size_t index )
186
184
}
187
185
}
188
186
187
+ double InputFile::getFps ()
188
+ {
189
+ double fps = 1 ;
190
+ if ( _properties.getNbVideoStreams () )
191
+ fps = _properties.getVideoProperties ().at ( 0 ).getFps ();
192
+ return fps;
193
+ }
194
+
189
195
void InputFile::setProfile ( const ProfileLoader::Profile& profile )
190
196
{
191
197
for ( ProfileLoader::Profile::const_iterator it = profile.begin (); it != profile.end (); ++it )
0 commit comments