Skip to content

Commit 1443a1a

Browse files
author
Clement Champetier
committed
FormatContext: add flag parameter to the seek function
1 parent 32d99fd commit 1443a1a

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
133133
return *stream;
134134
}
135135

136-
void FormatContext::seek( uint64_t position )
136+
void FormatContext::seek( uint64_t position, const int flag )
137137
{
138138
if( (int)getStartTime() != AV_NOPTS_VALUE )
139139
position += getStartTime();
140140

141-
if( av_seek_frame( _avFormatContext, -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
141+
if( av_seek_frame( _avFormatContext, -1, position, flag ) < 0 )
142142
{
143143
LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" )
144144
}

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ class AvExport FormatContext
6262
AVStream& addAVStream( const AVCodec& avCodec );
6363

6464
/**
65-
* @brief Seek at a specific position (in AV_TIME_BASE units)
65+
* @brief Seek at a specific position
66+
* @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
67+
* @param flag: seeking mode (AVSEEK_FLAG_xxx)
6668
* @note before seek, add offset of start time
67-
* @note after seek, clear buffering of streams
6869
*/
69-
void seek( uint64_t position );
70+
void seek( uint64_t position, const int flag );
7071

7172
size_t getNbStreams() const { return _avFormatContext->nb_streams; }
7273
/// Get duration of the program, in seconds

src/AvTranscoder/file/InputFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
8686
void InputFile::seekAtFrame( const size_t frame )
8787
{
8888
uint64_t position = frame / getFps() * AV_TIME_BASE;
89-
_formatContext.seek( position );
89+
_formatContext.seek( position, AVSEEK_FLAG_BACKWARD );
9090
}
9191

9292
void InputFile::seekAtTime( const double time )
9393
{
9494
uint64_t position = time * AV_TIME_BASE;
95-
_formatContext.seek( position );
95+
_formatContext.seek( position, AVSEEK_FLAG_BACKWARD );
9696
}
9797

9898
void InputFile::activateStream( const size_t streamIndex, bool activate )

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys
3131

3232
// if the analysis level wiil decode some streams parts, seek at the beginning
3333
if( level > eAnalyseLevelHeader )
34-
const_cast<FormatContext*>( _formatContext )->seek( 0 );
34+
const_cast<FormatContext*>( _formatContext )->seek( 0, AVSEEK_FLAG_BACKWARD );
3535

3636
for( size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex )
3737
{
@@ -88,7 +88,7 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys
8888

8989
// if the analysis level has decoded some streams parts, return at the beginning
9090
if( level > eAnalyseLevelHeader )
91-
const_cast<FormatContext*>( _formatContext )->seek( 0 );
91+
const_cast<FormatContext*>( _formatContext )->seek( 0, AVSEEK_FLAG_BACKWARD );
9292
}
9393

9494
std::string FileProperties::getFilename() const

0 commit comments

Comments
 (0)