]> git.sesse.net Git - kdenlive/blob - renderer/kdenlive_render.cpp
Fix rendering of documents that have a locale different than the system's locale
[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 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("-locale:")) {
52             locale = QString(args.at(0)).section(':', 1);
53             args.removeFirst();
54         }
55         if (args.at(0).startsWith("in="))
56             in = args.takeFirst().section('=', -1).toInt();
57         if (args.at(0).startsWith("out="))
58             out = args.takeFirst().section('=', -1).toInt();
59         if (args.at(0).startsWith("preargs="))
60             preargs = args.takeFirst().section('=', 1).split(' ', QString::SkipEmptyParts);
61
62         QString render = args.takeFirst();
63         QString profile = args.takeFirst();
64         QString rendermodule = args.takeFirst();
65         QString player = args.takeFirst();
66         QString src = args.takeFirst();
67         QUrl desturl = QUrl::fromEncoded(args.takeFirst().toUtf8());
68         QString dest = desturl.path();
69         bool dualpass = false;
70         bool doerase;
71         QString vpre;
72
73         int vprepos = args.indexOf(QRegExp("vpre=.*"));
74         if (vprepos >= 0) {
75             vpre=args.at(vprepos);
76         }
77         QStringList vprelist = vpre.replace("vpre=", "").split(",");
78         if (vprelist.size() > 0) {
79             args.replaceInStrings(QRegExp("^vpre=.*"), QString("vpre=").append(vprelist.at(0)));
80         }
81
82         if (args.contains("pass=2")) {
83             // dual pass encoding
84             dualpass = true;
85             doerase = false;
86             args.replace(args.indexOf("pass=2"), "pass=1");
87         } else {
88             args.removeAll("pass=1");
89             doerase = erase;
90         }
91
92         qDebug() << "//STARTING RENDERING: " << erase << "," << usekuiserver << "," << render << "," << profile << "," << rendermodule << "," << player << "," << src << "," << dest << "," << preargs << "," << args << "," << in << "," << out ;
93         RenderJob *job = new RenderJob(doerase, usekuiserver, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
94         if (!locale.isEmpty()) job->setLocale(locale);
95         job->start();
96         if (dualpass) {
97             if (vprelist.size()>1)
98                 args.replaceInStrings(QRegExp("^vpre=.*"),QString("vpre=").append(vprelist.at(1)));
99             args.replace(args.indexOf("pass=1"), "pass=2");
100             RenderJob *dualjob = new RenderJob(erase, usekuiserver, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
101             QObject::connect(job, SIGNAL(renderingFinished()), dualjob, SLOT(start()));
102         }
103         app.exec();
104     } else {
105         fprintf(stderr, "Kdenlive video renderer for MLT.\nUsage: "
106                 "kdenlive_render [-erase] [-kuiserver] [-locale:LOCALE] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] [arg2] ...]\n"
107                 "  -erase: if that parameter is present, src file will be erased at the end\n"
108                 "  -kuiserver: if that parameter is present, use KDE job tracker\n"
109                 "  -locale:LOCALE : set a locale for rendering. For example, -locale:fr_FR.UTF-8 will use a french locale (comma as numeric separator)\n"
110                 "  in=pos: start rendering at frame pos\n"
111                 "  out=pos: end rendering at frame pos\n"
112                 "  render: path to MLT melt renderer\n"
113                 "  profile: the MLT video profile\n"
114                 "  rendermodule: the MLT consumer used for rendering, usually it is avformat\n"
115                 "  player: path to video player to play when rendering is over, use '-' to disable playing\n"
116                 "  src: source file (usually MLT XML)\n"
117                 "  dest: destination file\n"
118                 "  args: space separated libavformat arguments\n");
119     }
120 }
121