Skip to content

Commit

Permalink
preview: fix error decoding key frame after seek
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Oct 27, 2014
1 parent 6394ce3 commit 6ae6f51
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/AVDemuxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 128,7 @@ void AVDemuxThread::seek(qint64 pos)
}
if (video_thread) {
video_thread->packetQueue()->clear();
// TODO: the first frame (key frame) will not be decoded correctly if flush() is called.
video_thread->packetQueue()->put(Packet());
}
//if (subtitle_thread) {
Expand Down
1 change: 0 additions & 1 deletion src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 424,6 @@ bool AVDemuxer::seek(qint64 pos)
return false;
}
//replay
qDebug("startTime: %lld", startTime());
if (upos <= startTime()) {
qDebug("************seek to beginning. started = false");
started_ = false;
Expand Down
12 changes: 8 additions & 4 deletions src/QtAV/VideoFrameExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 41,18 @@ class Q_AV_EXPORT VideoFrameExtractor : public QObject
explicit VideoFrameExtractor(QObject *parent = 0);
void setSource(const QString value);
QString source() const;
/*!
* \brief setAsync
* Extract video frames in another thread. Default is true.
*/
void setAsync(bool value);
bool async() const;
void setAutoExtract(bool value);
bool autoExtract() const;
/*!
* \brief setPrecision
* if the difference of the next requested position is less than the value, the
* last one is used and not positionChanged() signal to emit.
* if the difference between the next requested position is less than the value, previous
* one is used and no positionChanged() and frameExtracted() signals to emit.
* Default is 500ms.
*/
void setPrecision(int value);
Expand Down Expand Up @@ -76,8 80,8 @@ public slots:
/*!
* \brief extract
* If last extracted frame can be use, use it.
* If there is a key frame in [position-precision, position precision], then the nearest key frame will be extracted.
* Otherwise, the given position frame will be extracted.
* If there is a key frame in [position-precision, position precision], the nearest key frame
* before position precision will be extracted. Otherwise, the given position frame will be extracted.
*/
void extract();
private slots:
Expand Down
6 changes: 3 additions & 3 deletions src/VideoFrameExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 133,7 @@ class VideoFrameExtractorPrivate : public DPtrPrivate<VideoFrameExtractor>
continue;
}
QVariantHash opt, va;
va["Display"] = "X11"; // to support swscale
va["display"] = "X11"; // to support swscale
opt["vaapi"] = va;
decoder->setOptions(opt);
break;
Expand All @@ -158,7 158,7 @@ class VideoFrameExtractorPrivate : public DPtrPrivate<VideoFrameExtractor>
if (demuxer.packet()->hasKeyFrame)
break;
}
decoder->flush();
// decoder->flush(); // TODO: why key frame can't be decoded? also in VideoThread
const qint64 t_key = qint64(demuxer.packet()->pts * 1000.0);
//qDebug("delta t = %d, data size: %d", int(value - t_key), demuxer.packet()->data.size());
// must decode key frame
Expand All @@ -183,7 183,7 @@ class VideoFrameExtractorPrivate : public DPtrPrivate<VideoFrameExtractor>
qreal t0 = qreal(value/1000LL);
while (!demuxer.atEnd()) {
if (!demuxer.readFrame()) {
qDebug("!!!!!!----read frame error!!!!!!");
//qDebug("!!!!!!----read frame error!!!!!!");
continue;
}
if (demuxer.stream() != vstream) {
Expand Down

0 comments on commit 6ae6f51

Please sign in to comment.