summaryrefslogtreecommitdiff
path: root/rotord/src/libavwrapper.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-09-03 17:04:32 +0100
committerTim Redfern <tim@eclectronics.org>2013-09-03 17:04:32 +0100
commitf316c9f73a63df12def9a640038bd526c470f5fd (patch)
tree2f91117b623fc7d3dd0db3be3ce25462242559f6 /rotord/src/libavwrapper.cpp
parent2469ddabe2b6e7746984339db84dbe0e7b069255 (diff)
stop blocking on audio analysis
Diffstat (limited to 'rotord/src/libavwrapper.cpp')
-rwxr-xr-xrotord/src/libavwrapper.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp
index 6081ed6..180032d 100755
--- a/rotord/src/libavwrapper.cpp
+++ b/rotord/src/libavwrapper.cpp
@@ -361,12 +361,13 @@ int libav::decoder::seekToFrame(int targetFrameIndex)
return -1;
}
int result = avformat_seek_file( container, //format context
- videoStream,//stream id
- 0, //min timestamp 0?
+ videoStream,//stream id
+ 0, //min timestamp 0?
ts, //target timestamp
ts, //max timestamp
- 0);//flags AVSEEK_FLAG_ANY //doesn't seem to work great
- if (result < 0)
+ 0);//flags AVSEEK_FLAG_ANY //
+
+ if (result< 0)
return -1;
avcodec_flush_buffers(pCtx);
@@ -376,6 +377,31 @@ int libav::decoder::seekToFrame(int targetFrameIndex)
return targetFrameIndex;
}
+// \returns current frame on success, otherwise -1
+int libav::decoder::seekToFrameNew(int targetFrameIndex)
+{
+ int64_t duration = container->streams[videoStream]->duration;
+ int64_t ts = av_rescale(duration,targetFrameIndex,numFrames);
+ int64_t tol = av_rescale(duration,1,2*numFrames);
+ if ( (targetFrameIndex < 0) || (targetFrameIndex >= numFrames) ) {
+ return -1;
+ }
+
+ int flags = AVSEEK_FLAG_BACKWARD;
+ if (ts > 0 && ts < duration)
+ flags |= AVSEEK_FLAG_ANY; // H.264 I frames don't always register as "key frames" in FFmpeg
+
+ int ret = av_seek_frame(container, videoStream, ts, flags);
+ if (ret < 0)
+ ret = av_seek_frame(container, videoStream, ts, AVSEEK_FLAG_ANY);
+
+
+ if (ret< 0)
+ return -1;
+
+ return targetFrameIndex;
+}
+
bool libav::decoder::readNextFrame(int targetFrameIndex)
{
AVPacket packet = {0};