Repository navigation
Expand file tree
/
Copy pathdecoderservice.cpp
More file actions
79 lines (70 loc) · 2.18 KB
/
Copy pathdecoderservice.cpp
File metadata and controls
79 lines (70 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "decoderservice.h"
#include <vector>
DecoderService::DecoderService(QObject* parent) : QObject(parent) {}
DecoderService::~DecoderService() = default;
QVariantMap DecoderService::Open(const QString& path, int codec,
QVariantList raw_keyframes) {
QVariantMap result;
decoder_ = std::make_unique<FFmpegDecoder>();
if (!decoder_->OpenFile(path.toStdString(), (CodecType)codec)) {
result["ok"] = false;
result["error"] = QString::fromStdString(decoder_->LastError());
decoder_.reset();
return result;
}
if (raw_keyframes.size() >= 2) {
std::vector<FFmpegDecoder::RawKeyframe> keyframes;
for (int i = 0; i + 1 < raw_keyframes.size(); i += 2) {
FFmpegDecoder::RawKeyframe keyframe;
keyframe.frame_index = raw_keyframes[i].toInt();
keyframe.byte_offset = raw_keyframes[i + 1].toLongLong();
keyframes.push_back(keyframe);
}
decoder_->SetRawKeyframeIndex(std::move(keyframes));
}
result["ok"] = true;
result["has_timestamps"] = decoder_->HasTimestamps();
result["frame_rate"] = decoder_->FrameRate();
result["duration"] = decoder_->DurationSec();
return result;
}
QVariantMap DecoderService::Close() {
if (decoder_) {
decoder_->close();
decoder_.reset();
}
QVariantMap result;
result["ok"] = true;
return result;
}
QVariantMap DecoderService::Seek(int frame) {
QVariantMap result;
if (!decoder_) {
result["ok"] = false;
return result;
}
result["ok"] = decoder_->SeekToFrame(frame);
const FFmpegDecoder::SeekStats stats = decoder_->LastSeekStats();
result["used_container"] = stats.used_container;
result["used_raw_keyframe"] = stats.used_raw_keyframe;
result["frames_decoded"] = stats.frames_decoded;
result["seek_io_ms"] = (qint64)stats.seek_io_ms;
result["decode_ms"] = (qint64)stats.decode_ms;
return result;
}
QVariantMap DecoderService::DecodeNext() {
QVariantMap result;
if (!decoder_) {
result["ok"] = false;
return result;
}
DecodedFrame frame;
if (!decoder_->DecodeNextFrame(frame)) {
result["ok"] = false;
return result;
}
result["ok"] = true;
result["image"] = frame.image;
result["pts"] = frame.pts_sec;
return result;
}