]> git.sesse.net Git - kdenlive/blob - renderer/kdenlive_render.cpp
fixes segfault bug, introduces earlier
[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     int in = -1;
35     int out = -1;
36     if (args.count() >= 7) {
37         // Remove program name
38         args.removeFirst();
39
40         bool erase = false;
41         if (args.at(0) == "-erase") {
42             erase = true;
43             args.removeFirst();
44         }
45         bool usekuiserver = false;
46         if (args.at(0) == "-kuiserver") {
47             usekuiserver = true;
48             args.removeFirst();
49         }
50         if (args.at(0).startsWith("in="))
51             in = args.takeFirst().section('=', -1).toInt();
52         if (args.at(0).startsWith("out="))
53             out = args.takeFirst().section('=', -1).toInt();
54         if (args.at(0).startsWith("preargs="))
55             preargs = args.takeFirst().section('=', 1).split(' ', QString::SkipEmptyParts);
56
57         QString render = args.takeFirst();
58         QString profile = args.takeFirst();
59         QString rendermodule = args.takeFirst();
60         QString player = args.takeFirst();
61         QString src = args.takeFirst();
62         QUrl desturl = QUrl::fromEncoded(args.takeFirst().toUtf8());
63         QString dest = desturl.path();
64         bool dualpass = false;
65         bool doerase;
66         QString vpre;
67                 int vprepos=args.indexOf(QRegExp("vpre=.*"));
68                 if (vprepos>=0)
69                         vpre=args.at(vprepos);
70         QStringList vprelist=vpre.replace("vpre=","").split(",");
71         if (vprelist.size()>0)
72             args.replaceInStrings(QRegExp("^vpre=.*"),QString("vpre=").append(vprelist.at(0)));
73         if (args.contains("pass=2")) {
74             // dual pass encoding
75             dualpass = true;
76             doerase = false;
77             args.replace(args.indexOf("pass=2"), "pass=1");
78         } else doerase = erase;
79         qDebug() << "//STARTING RENDERING: " << erase << "," << usekuiserver << "," << render << "," << profile << "," << rendermodule << "," << player << "," << src << "," << dest << "," << preargs << "," << args << "," << in << "," << out ;
80         RenderJob *job = new RenderJob(doerase, usekuiserver, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
81         job->start();
82         if (dualpass) {
83             if (vprelist.size()>1)
84                 args.replaceInStrings(QRegExp("^vpre=.*"),QString("vpre=").append(vprelist.at(1)));
85             args.replace(args.indexOf("pass=1"), "pass=2");
86             RenderJob *dualjob = new RenderJob(erase, usekuiserver, render, profile, rendermodule, player, src, dest, preargs, args, in, out);
87             QObject::connect(job, SIGNAL(renderingFinished()), dualjob, SLOT(start()));
88         }
89         app.exec();
90     } else {
91         fprintf(stderr, "Kdenlive video renderer for MLT.\nUsage: "
92                 "kdenlive_render [-erase] [-kuiserver] [in=pos] [out=pos] [render] [profile] [rendermodule] [player] [src] [dest] [[arg1] [arg2] ...]\n"
93                 "  -erase: if that parameter is present, src file will be erased at the end\n"
94                 "  -kuiserver: if that parameter is present, use KDE job tracker\n"
95                 "  in=pos: start rendering at frame pos\n"
96                 "  out=pos: end rendering at frame pos\n"
97                 "  render: path to MLT melt renderer\n"
98                 "  profile: the MLT video profile\n"
99                 "  rendermodule: the MLT consumer used for rendering, usually it is avformat\n"
100                 "  player: path to video player to play when rendering is over, use '-' to disable playing\n"
101                 "  src: source file (usually MLT XML)\n"
102                 "  dest: destination file\n"
103                 "  args: space separated libavformat arguments\n");
104     }
105 }
106