]> git.sesse.net Git - kdenlive/blob - renderer/kdenlive_render.cpp
Fix icludes
[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 <QDebug>
26 #include "renderjob.h"
27
28 int main(int argc, char **argv)
29 {
30     QCoreApplication app(argc, argv);
31     QStringList args = app.arguments();
32     QStringList preargs;
33     QString locale;
34     int pid = 0;
35     int in = -1;
36     int out = -1;
37     if (args.count() >= 7) {
38         // Remove program name
39         args.removeFirst();
40
41         bool erase = false;
42         if (args.at(0) == "-erase") {
43             erase = true;
44             args.removeFirst();
45         }
46         bool usekuiserver = false;
47         if (args.at(0) == "-kuiserver") {
48             usekuiserver = true;
49             args.removeFirst();
50         }
51         if (QString(args.at(0)).startsWith("-pid:")) {
52             pid = QString(args.at(0)).section(':', 1).toInt();
53             args.removeFirst();
54         }
55
56         if (QString(args.at(0)).startsWith("-locale:")) {
57             locale = QString(args.at(0)).section(':', 1);
58             args.removeFirst();
59         }
60         if (args.at(0).startsWith("in="))
61             in = args.takeFirst().section('=', -1).toInt();
62         if (args.at(0).startsWith("out="))
63             out = args.takeFirst().section('=', -1).toInt();
64         if (args.at(0).startsWith("preargs="))
65             preargs = args.takeFirst().section('=', 1).split(' ', QString::SkipEmptyParts);
66
67         QString render = args.takeFirst();
68         QString profile = args.takeFirst();
69         QString rendermodule = args.takeFirst();
70         QString player = args.takeFirst();
71         QByteArray srcString = args.takeFirst().toUtf8();
72         QUrl srcurl = QUrl::fromEncoded(srcString);
73         QString src = srcurl.path();
74         // The QUrl path() strips the consumer: protocol, so re-add it if necessary
75         if (srcString.startsWith("consumer:"))
76             src.prepend("consumer:");
77         QUrl desturl = QUrl::fromEncoded(args.takeFirst().toUtf8());
78         QString dest = desturl.path();
79         bool dualpass = false;
80         bool doerase;
81         QString vpre;
82
83         int vprepos = args.indexOf(QRegExp("vpre=.*"));
84         if (vprepos >= 0) {
85             vpre=args.at(vprepos);
86         }
87         QStringList vprelist = vpre.replace("vpre=", "").split(',');
88         if (vprelist.size() > 0) {
89             args.replaceInStrings(QRegExp("^vpre=.*"), QString("vpre=").append(vprelist.at(0)));
90         }
91
92         if (args.contains("pass=2")) {
93             // dual pass encoding
94             dualpass = true;
95             doerase = false;
96             args.replace(args.indexOf("pass=2"), "pass=1");
97             if (args.contains("vcodec=libx264")) args << QString("passlogfile=%1").arg(dest + ".log");
98         } else {
99             args.removeAll("pass=1");
100             doerase = erase;
101         }
102         
103         // Decode metadata
104         for (int i = 0; i < args.count(); ++i) {
105             if (args.at(i).startsWith("meta.attr")) {
106                 QString data = args.at(i);
107                 args.replace(i, data.section('=', 0, 0) + "=\"" + QUrl::fromPercentEncoding(data.section('=', 1).toUtf8()) + "\"");
108             }
109         }
110
111         qDebug() << "//STARTING RENDERING: " << erase << "," << usekuiserver << "," << render << "," << profile << "," << rendermodule << "," << player << "," << src << "," << dest << "," << preargs << "," << args << "," << in << "," << out ;
112         RenderJob *job = new RenderJob(doerase, usekuiserver, pid, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
113         if (!locale.isEmpty()) job->setLocale(locale);
114         job->start();
115         if (dualpass) {
116             if (vprelist.size()>1)
117                 args.replaceInStrings(QRegExp("^vpre=.*"),QString("vpre=").append(vprelist.at(1)));
118             args.replace(args.indexOf("pass=1"), "pass=2");
119             RenderJob *dualjob = new RenderJob(erase, usekuiserver, pid, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
120             QObject::connect(job, SIGNAL(renderingFinished()), dualjob, SLOT(start()));
121         }
122         app.exec();
123     } else {
124         fprintf(stderr, "Kdenlive video renderer for MLT.\nUsage: "
125                 "kdenlive_render [-erase] [-kuiserver] [-locale:LOCALE] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] [arg2] ...]\n"
126                 "  -erase: if that parameter is present, src file will be erased at the end\n"
127                 "  -kuiserver: if that parameter is present, use KDE job tracker\n"
128                 "  -locale:LOCALE : set a locale for rendering. For example, -locale:fr_FR.UTF-8 will use a french locale (comma as numeric separator)\n"
129                 "  in=pos: start rendering at frame pos\n"
130                 "  out=pos: end rendering at frame pos\n"
131                 "  render: path to MLT melt renderer\n"
132                 "  profile: the MLT video profile\n"
133                 "  rendermodule: the MLT consumer used for rendering, usually it is avformat\n"
134                 "  player: path to video player to play when rendering is over, use '-' to disable playing\n"
135                 "  src: source file (usually MLT XML)\n"
136                 "  dest: destination file\n"
137                 "  args: space separated libavformat arguments\n");
138     }
139 }
140