Reputation: 61
I want to get the id of the window by name using c++ or qml and record the specific screen using this id in ffmpeg.
ffmpeg -f x11grab -wid 0x6200012 -s 1920x1052 -r 30 -i :0.0+0,0
How can I do this?
it's not necessary to be the id, can be the offset-x and offset-y, I just want to record the window in any position.
Upvotes: 3
Views: 1380
Reputation: 71
I found out the following:
ffmpeg -y -s 800x600 -f x11grab -window_id 0x3200008 -framerate 30 -i :11.0+0,0 -c:v libx264 -preset ultrafast -crf 40 output_select_window.mp4
Very important explanation:
-window_id = 'xwininfo' shows window_id if you select a window
-i :11.0+0,0 = 11 means and from in shell with `$echo $Display`.
Upvotes: 3
Reputation: 243965
I do not see that x11grab can record some screen by id as this answer indicates so as that answer points out one option is to use GStreamer:
gst-launch-1.0 ximagesrc xid=0x04000007 ! videoconvert ! autovideosink
How do I get the window id in Qt?
If QQmlApplicationEngine is used with Window or ApplicationWindow:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url, &engine](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
if(QWindow *w = qobject_cast<QWindow *>(engine.rootObjects().first())){
qDebug() << w->winId();
}
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
With QQuickView
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQuickView view;
const QUrl url(QStringLiteral("qrc:/main.qml"));
view.setSource(url);
view.show();
qDebug() << view.winId();
return app.exec();
}
Qt Widgets:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
qDebug() << w.winId();
return a.exec();
}
Or in general you should access the QWindow and get the window id:
for(QWindow *w : QGuiApplication::allWindows()){
qDebug() << w->winId();
}
Upvotes: 3