Skip to content

Commit 35e8681

Browse files
author
Clement Champetier
committed
InputFile: add parameter to seek with a specific flag
Fix #211
1 parent eaf480e commit 35e8681

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

app/pyThumbnail/pythumbnail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464

6565
# seek in file
6666
if args.frame:
67-
inputFile.seekAtFrame(args.frame)
67+
inputFile.seekAtFrame(args.frame, av.AVSEEK_FLAG_BACKWARD)
6868
elif args.time:
69-
inputFile.seekAtTime(args.time)
69+
inputFile.seekAtTime(args.time, av.AVSEEK_FLAG_BACKWARD)
7070

7171
# create output file (need to set format profile of encoding to force output format to mjpeg)
7272
formatProfile = av.ProfileMap()

src/AvTranscoder/avTranscoder.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
%include "AvTranscoder/swig/avMediaType.i"
1414
%include "AvTranscoder/swig/avRational.i"
1515
%include "AvTranscoder/swig/avLogLevel.i"
16+
%include "AvTranscoder/swig/avSeek.i"
1617
%include "AvTranscoder/swig/avOperator.i"
1718

1819
%{

src/AvTranscoder/file/InputFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
8383
return true;
8484
}
8585

86-
void InputFile::seekAtFrame( const size_t frame )
86+
void InputFile::seekAtFrame( const size_t frame, const int flag )
8787
{
8888
uint64_t position = frame / getFps() * AV_TIME_BASE;
89-
_formatContext.seek( position, AVSEEK_FLAG_ANY );
89+
_formatContext.seek( position, flag );
9090
}
9191

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

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

src/AvTranscoder/file/InputFile.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ class AvExport InputFile
5050
/**
5151
* @brief Seek at a specific frame / time (in seconds)
5252
* @note Seek in file by using the default stream (according to ffmpeg)
53+
* @param flag: ffmpeg seek flag (by default seek to any frame, even non-keyframes)
5354
* @warning If the seek is done to a non key-frame, the decoding will start from the next key-frame
5455
**/
55-
void seekAtFrame( const size_t frame );
56-
void seekAtTime( const double time );
56+
void seekAtFrame( const size_t frame, const int flag = AVSEEK_FLAG_ANY );
57+
void seekAtTime( const double time, const int flag = AVSEEK_FLAG_ANY );
5758

5859
/**
5960
* @brief Activate the indicated stream

src/AvTranscoder/swig/avSeek.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
2+
#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
3+
#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
4+
#define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number

0 commit comments

Comments
 (0)