Skip to content
Snippets Groups Projects

Implements #196 stream capturing

Merged Nicolas Pope requested to merge bug/196/snapshotcapture into master
Files
24
+ 73
0
#include <loguru.hpp>
#include <ftl/configuration.hpp>
#include <ftl/codecs/reader.hpp>
#include <ftl/codecs/decoder.hpp>
#include <ftl/codecs/packet.hpp>
#include <fstream>
static ftl::codecs::Decoder *decoder;
static void createDecoder(const ftl::codecs::Packet &pkt) {
if (decoder) {
if (!decoder->accepts(pkt)) {
ftl::codecs::free(decoder);
} else {
return;
}
}
decoder = ftl::codecs::allocateDecoder(pkt);
}
int main(int argc, char **argv) {
std::string filename(argv[1]);
LOG(INFO) << "Playing: " << filename;
auto root = ftl::configure(argc, argv, "player_default");
std::ifstream f;
f.open(filename);
if (!f.is_open()) LOG(ERROR) << "Could not open file";
ftl::codecs::Reader r(f);
if (!r.begin()) LOG(ERROR) << "Bad ftl file";
LOG(INFO) << "Playing...";
int current_stream = 0;
bool res = r.read(90000000000000, [&current_stream,&r](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
if (spkt.channel & 0x1 > 0) return;
if (spkt.streamID == current_stream) {
LOG(INFO) << "Reading packet: (" << (int)spkt.streamID << "," << (int)spkt.channel << ") " << (int)pkt.codec << ", " << (int)pkt.definition;
cv::Mat frame(cv::Size(ftl::codecs::getWidth(pkt.definition),ftl::codecs::getHeight(pkt.definition)), CV_8UC3);
createDecoder(pkt);
try {
decoder->decode(pkt, frame);
} catch (std::exception &e) {
LOG(INFO) << "Decoder exception: " << e.what();
}
if (!frame.empty()) {
cv::imshow("Player", frame);
}
int key = cv::waitKey(20);
if (key >= 48 && key <= 57) {
current_stream = key - 48;
} else if (key == 27) {
r.end();
}
}
});
if (!res) LOG(ERROR) << "No frames left";
r.end();
ftl::running = false;
return 0;
}
Loading