Commit 22584594 authored by Fabian Riethmayer's avatar Fabian Riethmayer

Cleaned up makemedia. Small bugfix in Actionbutton3.qml

parent 46b56eea
...@@ -34,7 +34,8 @@ Rectangle { ...@@ -34,7 +34,8 @@ Rectangle {
id: addrbook id: addrbook
index: 3 index: 3
Component.onCompleted: { Component.onCompleted: {
addrbook.pageStack.push(addrbook.detailPage) //addrbook.pageStack.push(addrbook.detailPage)
//addrbook.setIndex(1)
qmlControler.start(); qmlControler.start();
} }
} }
......
...@@ -36,14 +36,16 @@ CentOS/RHEL ``sudo yum install ffmpeg`` ...@@ -36,14 +36,16 @@ CentOS/RHEL ``sudo yum install ffmpeg``
git clone https://anongit.kde.org/scratch/mart/qmlgrabber.git git clone https://anongit.kde.org/scratch/mart/qmlgrabber.git
cd qmlgrabber cd qmlgrabber
... TODO ... qmake PREFIX=~/.local/bin
make
make install
If you install it in you home directory, make sure you have the If you install it in you home directory, make sure you have the
installed packages in your path by adding it to your .profile: installed packages in your path by adding it to your .profile:
.. code-block:: sh .. code-block:: sh
echo "PATH=~/.local/lib:\$PATH" >> ~/.profile echo "PATH=~/.local/bin:\$PATH" >> ~/.profile
source ~/.profile source ~/.profile
......
...@@ -2,35 +2,42 @@ ...@@ -2,35 +2,42 @@
<?php <?php
if ($argc > 1) { if ($argc > 1) {
if (is_dir($argv[1])) { // very basic cmd line option parsing
$options = (getopt("d", [], $n));
$entry = $argv[$n];
global $debug;
$debug = array_key_exists("d", $options);
if (is_dir($entry)) {
// Create media files for a directory, including subdirectories // Create media files for a directory, including subdirectories
$imagedir = findRootDir($argv[1]) . "/source/img/"; $imagedir = findRootDir($entry) . "/source/img/";
parseDir(dir($argv[1])); parseDir(dir(realpath(__DIR__ . "/" . $entry)));
exit(0);
} }
if (is_file($argv[1])) { if (is_file($entry)) {
// Create media for a single file // Create media for a single file
$dir = dirname($argv[1]); $dir = dirname($entry);
$imagedir = findRootDir($dir) . "/source/img/"; $imagedir = findRootDir($dir) . "/source/img/";
$config = getConfig(dir($dir)); $config = getConfig(dir($dir));
$filename = basename($argv[1]); $filename = basename($entry);
if (key_exists($filename, $config)) { if (key_exists($filename, $config)) {
createMedia(dirname($argv[1]), $filename, $config[$filename]); createMedia(dirname($entry), $filename, $config[$filename]);
exit(0);
} }
else { else {
echo "No config entry for " . $argv[1]; el("No config entry for " . $entry);
exit(1); exit(1);
} }
} }
} else { } else {
// Create all media files // Create all media files
chdir(findRootDir(realpath("."))); chdir(findRootDir(realpath(".")));
$dir = dir("./source/qml"); $dir = dir("./source/qml");
$imagedir = realpath("./source/img/"); $imagedir = realpath("./source/img/");
parseDir($dir); parseDir($dir);
exit(0);
} }
exit(0);
/** /**
* Find the root directory of the checked out HIG project * Find the root directory of the checked out HIG project
...@@ -53,14 +60,15 @@ function findRootDir($dir) { ...@@ -53,14 +60,15 @@ function findRootDir($dir) {
*/ */
function parseDir(\Directory $dir) { function parseDir(\Directory $dir) {
$config = getConfig($dir); $config = getConfig($dir);
el("Parsing " . $dir->path);
while (false !== ($entry = $dir->read())) { while (false !== ($entry = $dir->read())) {
if (is_dir($dir->path . "/" . $entry)) { if (is_dir($dir->path . "/" . $entry)) {
if ($entry[0] != ".") { if ($entry[0] != ".") {
parseDir(dir($dir->path . "/" . $entry)); parseDir(dir($dir->path . "/" . $entry));
} }
} }
if (key_exists($entry, $config)) { if (key_exists($entry, $config)) {
createMedia($dir->path, $entry, $config[$entry]); createMedia($dir->path, $entry, $config[$entry]);
} }
...@@ -84,78 +92,111 @@ function getConfig(\Directory $dir) { ...@@ -84,78 +92,111 @@ function getConfig(\Directory $dir) {
function createMedia($path, $filename, $config) { function createMedia($path, $filename, $config) {
global $imagedir; global $imagedir;
$pathinfo = pathinfo($path. "/" . $filename); $pathinfo = pathinfo($path. "/" . $filename);
//echo "Changing to " . $path;
chdir($path);
echo "Creating media for " . $filename . " ";
$options = "";
if (isset($config["controls"]) && $config["controls"] == "mobile") { el("Changing to " . $path . "\n");
putenv("QT_QUICK_CONTROLS_MOBILE=1"); if (chdir($path)) {
putenv("QT_QUICK_CONTROLS_STYLE=Plasma"); echo "Created media for " . $filename . " ... ";
}
else { // Setting env variables
$options = "";
if (isset($config["controls"]) && $config["controls"] == "mobile") {
putenv("QT_QUICK_CONTROLS_MOBILE=1");
putenv("QT_QUICK_CONTROLS_STYLE=Plasma");
}
else {
putenv("QT_QUICK_CONTROLS_MOBILE=0");
putenv("QT_QUICK_CONTROLS_STYLE=org.kde.desktop");
}
if (isset($config["autostart"])) {
$options .= " -a " . $config["autostart"];
}
if (isset($config["scale"]) && is_numeric($config["scale"])) {
putenv("QT_SCALE_FACTOR=" . $config["scale"]);
}
else {
putenv("QT_SCALE_FACTOR=1");
}
if (isset($config["fps"])) {
$options .= " -f " . $config["fps"];
}
if (isset($config["duration"])) {
$options .= " -s " . $config["duration"];
}
switch ($config["type"]) {
case "png":
el("qmlgrabber " . $filename . $options );
cmdExec("qmlgrabber " . $filename . $options );
$output = $imagedir . $pathinfo["filename"] . ".png";
el("moving file to " . $output);
if (is_file($output)) {
unlink($output);
}
rename($path . "/Screenshot.png", $output);
break;
case "webm":
el("qmlgrabber " . $options . " " . $filename);
cmdExec("qmlgrabber " . $options . " " . $filename);
cmdExec("ffmpeg -r 60 -f image2 -i Frames/Frame-%d.png -vcodec libvpx -b:v 1M video.webm");
$output = $imagedir . $pathinfo["filename"] . ".webm";
el("moving file to " . $output);
if (is_file($output)) {
unlink($output);
}
rename($path . "/video.webm", $output);
cmdExec("rm -r Frames");
break;
case "gif":
cmdExec("qmlgrabber " . $filename . $options);
cmdExec("ffmpeg -f image2 -i Frames/Frame-%d.png -vf fps=10,scale=240:-1:flags=lanczos,palettegen palette.png");
cmdExec('ffmpeg -f image2 -i Frames/Frame-%d.png -i palette.png -filter_complex "fps=20,scale=240:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif');
$output = $imagedir . $pathinfo["filename"] . ".gif";
el("moving file to " . $output);
if (is_file($output)) {
unlink($output);
}
rename($path. "/output.gif", $output);
cmdExec("rm -r Frames");
cmdExec("rm palette.png");
break;
}
// Reset env variables back to default
putenv("QT_QUICK_CONTROLS_MOBILE=0"); putenv("QT_QUICK_CONTROLS_MOBILE=0");
putenv("QT_QUICK_CONTROLS_STYLE=org.kde.desktop"); putenv("QT_QUICK_CONTROLS_STYLE=org.kde.desktop");
}
if (isset($config["autostart"])) {
$options .= " -a " . $config["autostart"];
}
if (isset($config["scale"]) && is_numeric($config["scale"])) {
putenv("QT_SCALE_FACTOR=" . $config["scale"]);
}
else {
putenv("QT_SCALE_FACTOR=1"); putenv("QT_SCALE_FACTOR=1");
echo " done \n";
} }
else {
if (isset($config["fps"])) { echo "Could not change to $path \n";
$options .= " -f " . $config["fps"]; exit(1);
} }
}
if (isset($config["duration"])) {
$options .= " -s " . $config["duration"]; /**
* Executing a bash cmd
* printing out the result, if an error occured
* exit(1) on error
*/
function cmdExec($cmd) {
exec($cmd . " 2>&1", $result, $return);
if ($return !== 0) {
print_r($result);
exit(1);
} }
}
switch ($config["type"]) {
case "png": /**
error_log("qmlgrabber " . $filename . $options ); * Output if -d is set
exec("qmlgrabber " . $filename . $options ); */
$output = $imagedir . $pathinfo["filename"] . ".png"; function el($str) {
echo "moving file to " . $output; global $debug;
if (is_file($output)) { if ($debug) {
unlink($output); echo $str . "\n";
}
rename(realpath($path) . "/Screenshot.png", $output);
break;
case "webm":
echo "qmlgrabber " . $options . " " . $filename . "\n\n";
exec("qmlgrabber " . $options . " " . $filename);
exec("ffmpeg -r 60 -f image2 -i Frames/Frame-%d.png -vcodec libvpx -b:v 1M video.webm;");
$output = $imagedir . $pathinfo["filename"] . ".webm";
echo "moving file to " . $output;
if (is_file($output)) {
unlink($output);
}
rename(realpath($path) . "/video.webm", $output);
exec("rm -r Frames");
break;
case "gif":
exec("qmlgrabber " . $filename . $options);
exec("ffmpeg -f image2 -i Frames/Frame-%d.png -vf fps=10,scale=240:-1:flags=lanczos,palettegen palette.png");
exec('ffmpeg -f image2 -i Frames/Frame-%d.png -i palette.png -filter_complex "fps=20,scale=240:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif');
$output = $imagedir . $pathinfo["filename"] . ".gif";
echo "moving file to " . $output;
if (is_file($output)) {
unlink($output);
}
rename(realpath($path) . "/output.gif", $output);
exec("rm -r Frames");
exec("rm palette.png");
break;
} }
echo "\n";
putenv("QT_QUICK_CONTROLS_MOBILE=0");
putenv("QT_QUICK_CONTROLS_STYLE=org.kde.desktop");
putenv("QT_SCALE_FACTOR=1");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment