]> git.sesse.net Git - kdenlive/blob - renderer/kdenlive_render.cpp
593d002c367df9ce5968b01754ff0bdb0676a9ba
[kdenlive] / renderer / kdenlive_render.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include <stdio.h>
21 #include <QCoreApplication>
22 #include <QStringList>
23 #include <QString>
24 #include <QUrl>
25 #include <QtDebug>
26
27 #include "renderjob.h"
28
29 int main(int argc, char **argv)
30 {
31     QCoreApplication app(argc, argv);
32     QStringList args = app.arguments();
33     QStringList preargs;
34     QString locale;
35     int pid = 0;
36     int in = -1;
37     int out = -1;
38     if (args.count() >= 7) {
39         // Remove program name
40         args.removeFirst();
41
42         bool erase = false;
43         if (args.at(0) == "-erase") {
44             erase = true;
45             args.removeFirst();
46         }
47         bool usekuiserver = false;
48         if (args.at(0) == "-kuiserver") {
49             usekuiserver = true;
50             args.removeFirst();
51         }
52         if (QString(args.at(0)).startsWith("-pid:")) {
53             pid = QString(args.at(0)).section(':', 1).toInt();
54             args.removeFirst();
55         }
56
57         if (QString(args.at(0)).startsWith("-locale:")) {
58             locale = QString(args.at(0)).section(':', 1);
59             args.removeFirst();
60         }
61         if (args.at(0).startsWith("in="))
62             in = args.takeFirst().section('=', -1).toInt();
63         if (args.at(0).startsWith("out="))
64             out = args.takeFirst().section('=', -1).toInt();
65         if (args.at(0).startsWith("preargs="))
66             preargs = args.takeFirst().section('=', 1).split(' ', QString::SkipEmptyParts);
67
68         QString render = args.takeFirst();
69         QString profile = args.takeFirst();
70         QString rendermodule = args.takeFirst();
71         QString player = args.takeFirst();
72         QByteArray srcString = args.takeFirst().toUtf8();
73         QUrl srcurl = QUrl::fromEncoded(srcString);
74         QString src = srcurl.path();
75         // The QUrl path() strips the consumer: protocol, so re-add it if necessary
76         if (srcString.startsWith("consumer:"))
77             src.prepend("consumer:");
78         QUrl desturl = QUrl::fromEncoded(args.takeFirst().toUtf8());
79         QString dest = desturl.path();
80         bool dualpass = false;
81         bool doerase;
82         QString vpre;
83
84         int vprepos = args.indexOf(QRegExp("vpre=.*"));
85         if (vprepos >= 0) {
86             vpre=args.at(vprepos);
87         }
88         QStringList vprelist = vpre.replace("vpre=", "").split(',');
89         if (vprelist.size() > 0) {
90             args.replaceInStrings(QRegExp("^vpre=.*"), QString("vpre=").append(vprelist.at(0)));
91         }
92
93         if (args.contains("pass=2")) {
94             // dual pass encoding
95             dualpass = true;
96             doerase = false;
97             args.replace(args.indexOf("pass=2"), "pass=1");
98             if (args.contains("vcodec=libx264")) args << QString("passlogfile=%1").arg(dest + ".log");
99         } else {
100             args.removeAll("pass=1");
101             doerase = erase;
102         }
103         
104         // Decode metadata
105         for (int i = 0; i < args.count(); ++i) {
106             if (args.at(i).startsWith("meta.attr")) {
107                 QString data = args.at(i);
108                 args.replace(i, data.section('=', 0, 0) + "=\"" + QUrl::fromPercentEncoding(data.section('=', 1).toUtf8()) + "\"");
109             }
110         }
111
112         qDebug() << "//STARTING RENDERING: " << erase << "," << usekuiserver << "," << render << "," << profile << "," << rendermodule << "," << player << "," << src << "," << dest << "," << preargs << "," << args << "," << in << "," << out ;
113         RenderJob *job = new RenderJob(doerase, usekuiserver, pid, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
114         if (!locale.isEmpty()) job->setLocale(locale);
115         job->start();
116         if (dualpass) {
117             if (vprelist.size()>1)
118                 args.replaceInStrings(QRegExp("^vpre=.*"),QString("vpre=").append(vprelist.at(1)));
119             args.replace(args.indexOf("pass=1"), "pass=2");
120             RenderJob *dualjob = new RenderJob(erase, usekuiserver, pid, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
121             QObject::connect(job, SIGNAL(renderingFinished()), dualjob, SLOT(start()));
122         }
123         app.exec();
124     } else {
125         fprintf(stderr, "Kdenlive video renderer for MLT.\nUsage: "
126                 "kdenlive_render [-erase] [-kuiserver] [-locale:LOCALE] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] [arg2] ...]\n"
127                 "  -erase: if that parameter is present, src file will be erased at the end\n"
128                 "  -kuiserver: if that parameter is present, use KDE job tracker\n"
129                 "  -locale:LOCALE : set a locale for rendering. For example, -locale:fr_FR.UTF-8 will use a french locale (comma as numeric separator)\n"
130                 "  in=pos: start rendering at frame pos\n"
131                 "  out=pos: end rendering at frame pos\n"
132                 "  render: path to MLT melt renderer\n"
133                 "  profile: the MLT video profile\n"
134                 "  rendermodule: the MLT consumer used for rendering, usually it is avformat\n"
135                 "  player: path to video player to play when rendering is over, use '-' to disable playing\n"
136                 "  src: source file (usually MLT XML)\n"
137                 "  dest: destination file\n"
138                 "  args: space separated libavformat arguments\n");
139     }
140 }
141