1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
23
This effect allows recording a video from the session.
27
- git clone git://gitorious.org/capseo/mainline.git capseo
28
- you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
30
- the usual configure && make && make install procedure
31
(you may want to pass --enable-theora --with-accel=x86 [or amd64])
33
- git clone git://gitorious.org/libcaptury/mainline.git libcaptury
34
- you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
36
- the usual configure && make && make install procedure
38
Video is saved to $HOME/kwin_video.cps, use
39
"cpsrecode -i kwin_video.cps -o - | mplayer -" to play,
40
to create a video use "cpsrecode -c theora -i kwin_video.cps -o screen.ogg"
41
or use mencoder in a similar way as mplayer.
45
#include "videorecord.h"
48
#include <kactioncollection.h>
53
#include <kio/netaccess.h>
54
#include <KConfigGroup>
55
#include <KGlobalSettings>
62
KWIN_EFFECT(videorecord, VideoRecordEffect)
64
VideoRecordEffect::VideoRecordEffect()
67
KActionCollection* actionCollection = new KActionCollection(this);
68
KAction* a = static_cast< KAction* >(actionCollection->addAction("VideoRecord"));
69
a->setText(i18n("Toggle Video Recording"));
70
a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::META + Qt::Key_V));
71
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleRecording()));
72
area = QRect(0, 0, displayWidth(), displayHeight());
75
VideoRecordEffect::~VideoRecordEffect()
80
void VideoRecordEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
82
effects->paintScreen(mask, region, data);
84
capture_region = (mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED))
85
? QRect(0, 0, displayWidth(), displayHeight()) : region;
88
void VideoRecordEffect::postPaintScreen()
90
effects->postPaintScreen();
93
if (CapturyProcessRegionStart(client) == CAPTURY_SUCCESS) {
94
capture_region &= QRect(0, 0, displayWidth(), displayHeight()); // limit to screen
95
foreach (const QRect & r, capture_region.rects()) {
96
int gly = displayHeight() - r.y() - r.height(); // opengl coords
97
CapturyProcessRegion(client, r.x(), gly, r.width(), r.height());
99
CapturyProcessRegionCommit(client);
102
CapturyProcessFrame(client);
107
void VideoRecordEffect::startRecording()
111
bzero(&config, sizeof(config));
114
config.width = area.width();
115
config.height = area.height();
117
config.fps = 30; // TODO
118
config.deviceType = CAPTURY_DEVICE_GLX; // TODO
119
config.deviceHandle = display();
120
config.windowHandle = rootWindow(); // TODO
121
config.cursor = true;
122
client = CapturyOpen(&config);
123
if (client == NULL) {
124
kDebug(1212) << "Video recording init failed";
127
KConfigGroup conf = EffectsHandler::effectConfig("VideoRecord");
128
QString videoPath = conf.readEntry("videopath", KGlobalSettings::documentPath());
129
QString videoName(videoPath + "/kwin_video1.cps");
130
while (QFile::exists(videoName)) {
131
autoincFilename(videoName);
133
if (CapturySetOutputFileName(client, QFile::encodeName(videoName).constData()) != CAPTURY_SUCCESS) {
134
kDebug(1212) << "Video recording file open failed";
137
effects->addRepaintFull(); // trigger reading initial screen contents into buffer
138
kDebug(1212) << "Video recording start";
141
void VideoRecordEffect::autoincFilename(QString & name)
143
// If the name contains a number then increment it
144
QRegExp numSearch("(^|[^\\d])(\\d+)"); // we want to match as far left as possible, and when the number is at the start of the name
145
// Does it have a number?
146
int start = numSearch.lastIndexIn(name);
148
// It has a number, increment it
149
start = numSearch.pos(2); // we are only interested in the second group
150
QString numAsStr = numSearch.capturedTexts()[ 2 ];
151
QString number = QString::number(numAsStr.toInt() + 1);
152
number = number.rightJustified(numAsStr.length(), '0');
153
name.replace(start, number.length(), number);
156
void VideoRecordEffect::stopRecording()
160
kDebug(1212) << "Video recording stop";
161
CapturyClose(client);
165
void VideoRecordEffect::toggleRecording()
175
#include "videorecord.moc"