MCPcopy Create free account
hub / github.com/Tencent/libpag / GetVideoFirstFrame

Method GetVideoFirstFrame

viewer/src/editing/PAGImageLayerModel.cpp:34–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace pag {
33
34QImage PAGImageLayerModel::GetVideoFirstFrame(const QString& filePath) {
35 QMediaPlayer player;
36 QVideoSink sink;
37 QEventLoop loop;
38 QImage result = {};
39
40 connect(&sink, &QVideoSink::videoFrameChanged, [&](const QVideoFrame& frame) {
41 QVideoFrame videoFrame(frame);
42 videoFrame.map(QVideoFrame::ReadOnly);
43 QImage image = videoFrame.toImage();
44 if (!image.isNull()) {
45 result = image.copy();
46 loop.quit();
47 }
48 videoFrame.unmap();
49 });
50
51 player.setVideoSink(&sink);
52 player.setSource(filePath);
53 player.setLoops(1);
54 player.play();
55
56 QTimer timer;
57 timer.setSingleShot(true);
58 connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
59 timer.start(1000);
60
61 loop.exec();
62 player.stop();
63
64 return result;
65}
66
67PAGImageLayerModel::PAGImageLayerModel(QObject* parent) : QAbstractListModel(parent) {
68}

Callers

nothing calls this directly

Calls 6

copyMethod · 0.80
setSourceMethod · 0.80
execMethod · 0.80
playMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected