Skip to content

Commit 5be6776

Browse files
committed
Merge pull request #168 from cchampet/dev_cleanSeek
Clean seek
2 parents 466d556 + ad248ae commit 5be6776

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

app/pyThumbnail/pythumbnail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
parser.add_argument('inputFileName', help='It could be any media file with at least one video stream (video, image...). Support file without extension.')
1313
# options
1414
parser.add_argument("-o", "--outputFile", dest="outputFileName", default="thumbnail.jpg", help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!")
15-
parser.add_argument("-t", "--time", dest="time", type=int, default=0, help="Set time (in seconds) of where to seek in the video stream to generate the thumbnail (0 by default).")
15+
parser.add_argument("-t", "--time", dest="time", type=float, default=0, help="Set time (in seconds) of where to seek in the video stream to generate the thumbnail (0 by default).")
1616
parser.add_argument("-f", "--frame", dest="frame", type=int, default=0, help="Set time (in frames) of where to seek in the video stream to generate the thumbnail (0 by default). Warning: priority to frame if user indicates both frame and time!")
1717
parser.add_argument("-w", "--width", dest="width", type=int, default=0, help="Override the width of the thumbnail (same as input by default).")
1818
parser.add_argument("-he", "--height", dest="height", type=int, default=0, help="Override the height of the thumbnail (same as input by default).")

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)