1 #include <QMediaPlayer>
3 #include <QApplication>
5 #include <QVideoWidget>
9 #include "mainwindow.h"
10 #include "ui_mainwindow.h"
12 std::string format_timestamp(uint64_t pos)
22 snprintf(buf, sizeof(buf), "%d:%02d:%02d.%03d", hour, min, sec, ms);
26 MainWindow::MainWindow()
28 player = new QMediaPlayer;
29 //player->setSource(QUrl::fromLocalFile("/home/sesse/dev/stats/ultimate.mkv"));
30 player->setSource(QUrl::fromLocalFile("/home/sesse/dev/stats/ultimate-prores.mkv"));
33 Ui::MainWindow *ui = new Ui::MainWindow;
36 connect(player, &QMediaPlayer::positionChanged, [ui, this](uint64_t pos) {
37 ui->timestamp->setText(QString::fromUtf8(format_timestamp(pos)));
39 player->setPosition(*buffered_seek);
40 buffered_seek.reset();
43 player->pause(); // We only played to get a picture.
47 player->setVideoOutput(ui->video);
49 QShortcut *key_k = new QShortcut(QKeySequence(Qt::Key_K), this);
50 connect(key_k, &QShortcut::activated, [this]() { seek(-10000); });
52 QShortcut *key_l = new QShortcut(QKeySequence(Qt::Key_L), this);
53 connect(key_l, &QShortcut::activated, [this]() { seek(10000); });
55 QShortcut *key_left = new QShortcut(QKeySequence(Qt::Key_Left), this);
56 connect(key_left, &QShortcut::activated, [this]() { seek(-1000); });
58 QShortcut *key_right = new QShortcut(QKeySequence(Qt::Key_Right), this);
59 connect(key_right, &QShortcut::activated, [this]() { seek(1000); });
61 // TODO: Would be nice to actually have a frame...
62 QShortcut *key_comma = new QShortcut(QKeySequence(Qt::Key_Comma), this);
63 connect(key_comma, &QShortcut::activated, [this]() { seek(-20); });
65 QShortcut *key_period = new QShortcut(QKeySequence(Qt::Key_Period), this);
66 connect(key_period, &QShortcut::activated, [this]() { seek(20); });
68 QShortcut *key_space = new QShortcut(QKeySequence(Qt::Key_Space), this);
69 connect(key_space, &QShortcut::activated, [this]() {
73 player->setPlaybackRate(1.0);
80 void MainWindow::seek(int64_t delta_ms)
82 int64_t current_pos = buffered_seek ? *buffered_seek : player->position();
83 uint64_t pos = std::max<int64_t>(current_pos + delta_ms, 0);
86 player->setPlaybackRate(0.01);
87 player->play(); // Or Qt won't show the seek.
91 int main(int argc, char *argv[])
93 QApplication app(argc, argv);
95 MainWindow mainWindow;
96 mainWindow.resize(QSize(1280, 720));