source: smplayer/trunk/src/mplayeroptions.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 12.4 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
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 Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "subtracks.h"
20#include <QDir>
21#include <QDebug>
22
23void MplayerProcess::setMedia(const QString & media, bool is_playlist) {
24 if (is_playlist) arg << "-playlist";
25 arg << media;
26}
27
28void MplayerProcess::setFixedOptions() {
29 arg << "-noquiet" << "-slave" << "-identify";
30}
31
32void MplayerProcess::disableInput() {
33 arg << "-nomouseinput";
34
35#if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
36 arg << "-input" << "nodefault-bindings:conf=/dev/null";
37#endif
38}
39
40#ifdef CAPTURE_STREAM
41void MplayerProcess::setCaptureDirectory(const QString & dir) {
42 PlayerProcess::setCaptureDirectory(dir);
43 if (!capture_filename.isEmpty()) {
44 arg << "-capture" << "-dumpfile" << capture_filename;
45 }
46}
47#endif
48
49void MplayerProcess::enableScreenshots(const QString & dir, const QString & /* templ */, const QString & /* format */) {
50 QString f = "screenshot";
51 if (!dir.isEmpty()) {
52 QString d = QDir::toNativeSeparators(dir);
53 if (MplayerVersion::isMplayerAtLeast(36848)) {
54 f += "="+ d + "/shot";
55 } else {
56 // Keep compatibility with older versions
57 qDebug() << "MplayerProcess::enableScreenshots: this version of mplayer is very old";
58 qDebug() << "MplayerProcess::enableScreenshots: changing working directory to" << d;
59 setWorkingDirectory(d);
60 }
61 }
62 arg << "-vf-add" << f;
63}
64
65void MplayerProcess::setOption(const QString & option_name, const QVariant & value) {
66 if (option_name == "cache") {
67 int cache = value.toInt();
68 if (cache > 31) {
69 arg << "-cache" << value.toString();
70 } else {
71 arg << "-nocache";
72 }
73 }
74 else
75 if (option_name == "stop-xscreensaver") {
76 bool stop_ss = value.toBool();
77 if (stop_ss) arg << "-stop-xscreensaver"; else arg << "-nostop-xscreensaver";
78 }
79 else
80 if (option_name == "correct-pts") {
81 bool b = value.toBool();
82 if (b) arg << "-correct-pts"; else arg << "-nocorrect-pts";
83 }
84 else
85 if (option_name == "framedrop") {
86 QString o = value.toString();
87 if (o.contains("vo")) arg << "-framedrop";
88 if (o.contains("decoder")) arg << "-hardframedrop";
89 }
90 else
91 if (option_name == "osd-scale") {
92 arg << "-subfont-osd-scale" << value.toString();
93 }
94 else
95 if (option_name == "verbose") {
96 arg << "-v";
97 }
98 else
99 if (option_name == "enable_streaming_sites_support") {
100 // Not supported
101 }
102 else
103 if (option_name == "hwdec") {
104 // Not supported
105 }
106 else
107 if (option_name == "fontconfig") {
108 bool b = value.toBool();
109 if (b) arg << "-fontconfig"; else arg << "-nofontconfig";
110 }
111 else
112 if (option_name == "mute") {
113 // Not supported
114 }
115 else
116 if (option_name == "keepaspect" ||
117 option_name == "dr" || option_name == "double" ||
118 option_name == "fs" || option_name == "slices" ||
119 option_name == "flip-hebrew")
120 {
121 bool b = value.toBool();
122 if (b) arg << "-" + option_name; else arg << "-no" + option_name;
123 }
124 else {
125 arg << "-" + option_name;
126 if (!value.isNull()) arg << value.toString();
127 }
128}
129
130void MplayerProcess::addUserOption(const QString & option) {
131 arg << option;
132}
133
134void MplayerProcess::addVF(const QString & filter_name, const QVariant & value) {
135 QString option = value.toString();
136
137 if (filter_name == "blur" || filter_name == "sharpen") {
138 arg << "-vf-add" << "unsharp=" + option;
139 }
140 else
141 if (filter_name == "deblock") {
142 arg << "-vf-add" << "pp=" + option;
143 }
144 else
145 if (filter_name == "dering") {
146 arg << "-vf-add" << "pp=dr";
147 }
148 else
149 if (filter_name == "postprocessing") {
150 arg << "-vf-add" << "pp";
151 }
152 else
153 if (filter_name == "lb" || filter_name == "l5") {
154 arg << "-vf-add" << "pp=" + filter_name;
155 }
156 else
157 if (filter_name == "subs_on_screenshots") {
158 if (option == "ass") {
159 arg << "-vf-add" << "ass";
160 } else {
161 arg << "-vf-add" << "expand=osd=1";
162 }
163 }
164 else
165 if (filter_name == "flip") {
166 // expand + flip doesn't work well, a workaround is to add another
167 // filter between them, so that's why harddup is here
168 arg << "-vf-add" << "harddup,flip";
169 }
170 else
171 if (filter_name == "expand") {
172 arg << "-vf-add" << "expand=" + option + ",harddup";
173 // Note: on some videos (h264 for instance) the subtitles doesn't disappear,
174 // appearing the new ones on top of the old ones. It seems adding another
175 // filter after expand fixes the problem. I chose harddup 'cos I think
176 // it will be harmless in mplayer.
177 }
178 else {
179 QString s = filter_name;
180 QString option = value.toString();
181 if (!option.isEmpty()) s += "=" + option;
182 arg << "-vf-add" << s;
183 }
184}
185
186void MplayerProcess::addStereo3DFilter(const QString & in, const QString & out) {
187 QString filter = "stereo3d=" + in + ":" + out;
188 filter += ",scale"; // In my PC it doesn't work without scale :?
189 arg << "-vf-add" << filter;
190}
191
192void MplayerProcess::addAF(const QString & filter_name, const QVariant & value) {
193 QString s = filter_name;
194 if (!value.isNull()) s += "=" + value.toString();
195 arg << "-af-add" << s;
196}
197
198void MplayerProcess::quit() {
199 writeToStdin("quit");
200}
201
202void MplayerProcess::setVolume(int v) {
203 writeToStdin("volume " + QString::number(v) + " 1");
204}
205
206void MplayerProcess::setOSD(int o) {
207 writeToStdin(pausing_prefix + " osd " + QString::number(o));
208}
209
210void MplayerProcess::setAudio(int ID) {
211 writeToStdin("switch_audio " + QString::number(ID));
212}
213
214void MplayerProcess::setVideo(int ID) {
215 writeToStdin("set_property switch_video " + QString::number(ID));
216}
217
218void MplayerProcess::setSubtitle(int type, int ID) {
219 switch (type) {
220 case SubData::Vob:
221 writeToStdin( "sub_vob " + QString::number(ID) );
222 break;
223 case SubData::Sub:
224 writeToStdin( "sub_demux " + QString::number(ID) );
225 break;
226 case SubData::File:
227 writeToStdin( "sub_file " + QString::number(ID) );
228 break;
229 default: {
230 qWarning("MplayerProcess::setSubtitle: unknown type!");
231 }
232 }
233}
234
235void MplayerProcess::disableSubtitles() {
236 writeToStdin("sub_source -1");
237}
238
239void MplayerProcess::setSubtitlesVisibility(bool b) {
240 writeToStdin(QString("sub_visibility %1").arg(b ? 1 : 0));
241}
242
243void MplayerProcess::seek(double secs, int mode, bool precise) {
244 QString s = QString("seek %1 %2").arg(secs).arg(mode);
245 if (precise) s += " 1"; else s += " -1";
246 writeToStdin(s);
247}
248
249void MplayerProcess::mute(bool b) {
250 writeToStdin(pausing_prefix + " mute " + QString::number(b ? 1 : 0));
251}
252
253void MplayerProcess::setPause(bool /*b*/) {
254 writeToStdin("pause"); // pauses / unpauses
255}
256
257void MplayerProcess::frameStep() {
258 writeToStdin("frame_step");
259}
260
261void MplayerProcess::frameBackStep() {
262 qDebug("MplayerProcess::frameBackStep: function not supported by mplayer");
263 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
264}
265
266
267void MplayerProcess::showOSDText(const QString & text, int duration, int level) {
268 QString str = QString("osd_show_text \"%1\" %2 %3").arg(text).arg(duration).arg(level);
269 if (!pausing_prefix.isEmpty()) str = pausing_prefix + " " + str;
270 writeToStdin(str);
271}
272
273void MplayerProcess::showFilenameOnOSD() {
274 writeToStdin("osd_show_property_text \"${filename}\" 2000 0");
275}
276
277void MplayerProcess::showTimeOnOSD() {
278 writeToStdin("osd_show_property_text \"${time_pos} / ${length} (${percent_pos}%)\" 2000 0");
279}
280
281void MplayerProcess::setContrast(int value) {
282 writeToStdin(pausing_prefix + " contrast " + QString::number(value) + " 1");
283}
284
285void MplayerProcess::setBrightness(int value) {
286 writeToStdin(pausing_prefix + " brightness " + QString::number(value) + " 1");
287}
288
289void MplayerProcess::setHue(int value) {
290 writeToStdin(pausing_prefix + " hue " + QString::number(value) + " 1");
291}
292
293void MplayerProcess::setSaturation(int value) {
294 writeToStdin(pausing_prefix + " saturation " + QString::number(value) + " 1");
295}
296
297void MplayerProcess::setGamma(int value) {
298 writeToStdin(pausing_prefix + " gamma " + QString::number(value) + " 1");
299}
300
301void MplayerProcess::setChapter(int ID) {
302 writeToStdin("seek_chapter " + QString::number(ID) +" 1");
303}
304
305void MplayerProcess::nextChapter() {
306 writeToStdin("seek_chapter 1 0");
307}
308
309void MplayerProcess::previousChapter() {
310 writeToStdin("seek_chapter -1 0");
311}
312
313void MplayerProcess::setExternalSubtitleFile(const QString & filename) {
314 writeToStdin("sub_load \""+ filename +"\"");
315}
316
317void MplayerProcess::setSubPos(int pos) {
318 writeToStdin("sub_pos " + QString::number(pos) + " 1");
319}
320
321void MplayerProcess::setSubScale(double value) {
322 writeToStdin("sub_scale " + QString::number(value) + " 1");
323}
324
325void MplayerProcess::setSubStep(int value) {
326 writeToStdin("sub_step " + QString::number(value));
327}
328
329#ifdef MPV_SUPPORT
330void MplayerProcess::seekSub(int /*value*/) {
331 /* Not supported */
332 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
333};
334#endif
335
336void MplayerProcess::setSubForcedOnly(bool b) {
337 writeToStdin(QString("forced_subs_only %1").arg(b ? 1 : 0));
338}
339
340void MplayerProcess::setSpeed(double value) {
341 writeToStdin("speed_set " + QString::number(value));
342}
343
344void MplayerProcess::enableKaraoke(bool b) {
345 if (b) writeToStdin("af_add karaoke"); else writeToStdin("af_del karaoke");
346}
347
348void MplayerProcess::enableExtrastereo(bool b) {
349 if (b) writeToStdin("af_add extrastereo"); else writeToStdin("af_del extrastereo");
350}
351
352void MplayerProcess::enableVolnorm(bool b, const QString & option) {
353 if (b) writeToStdin("af_add volnorm=" + option); else writeToStdin("af_del volnorm");
354}
355
356void MplayerProcess::setAudioEqualizer(const QString & values) {
357 writeToStdin("af_cmdline equalizer " + values);
358}
359
360void MplayerProcess::setAudioDelay(double delay) {
361 writeToStdin(pausing_prefix + " audio_delay " + QString::number(delay) +" 1");
362}
363
364void MplayerProcess::setSubDelay(double delay) {
365 writeToStdin(pausing_prefix + " sub_delay " + QString::number(delay) +" 1");
366}
367
368void MplayerProcess::setLoop(int v) {
369 writeToStdin(QString("loop %1 1").arg(v));
370}
371
372void MplayerProcess::takeScreenshot(ScreenshotType t, bool /*include_subtitles*/) {
373 if (t == Single) {
374 writeToStdin(pausing_prefix + " screenshot 0");
375 } else {
376 writeToStdin("screenshot 1");
377 }
378}
379
380#ifdef CAPTURE_STREAM
381void MplayerProcess::switchCapturing() {
382 writeToStdin("capturing");
383}
384#endif
385
386void MplayerProcess::setTitle(int ID) {
387 writeToStdin("switch_title " + QString::number(ID));
388}
389
390#if DVDNAV_SUPPORT
391void MplayerProcess::discSetMousePos(int x, int y) {
392 writeToStdin(QString("set_mouse_pos %1 %2").arg(x).arg(y));
393}
394
395void MplayerProcess::discButtonPressed(const QString & button_name) {
396 writeToStdin("dvdnav " + button_name);
397}
398#endif
399
400void MplayerProcess::setAspect(double aspect) {
401 writeToStdin("switch_ratio " + QString::number(aspect));
402}
403
404void MplayerProcess::setFullscreen(bool b) {
405 writeToStdin(QString("vo_fullscreen %1").arg(b ? "1" : "0"));
406}
407
408#if PROGRAM_SWITCH
409void MplayerProcess::setTSProgram(int ID) {
410 writeToStdin("set_property switch_program " + QString::number(ID) );
411 writeToStdin("get_property switch_audio");
412 writeToStdin("get_property switch_video");
413}
414#endif
415
416void MplayerProcess::toggleDeinterlace() {
417 writeToStdin("step_property deinterlace");
418}
419
420void MplayerProcess::askForLength() {
421 writeToStdin(pausing_prefix + " get_property length");
422}
423
424void MplayerProcess::setOSDScale(double /*value*/) {
425 // not available
426 /* writeToStdin("set_property subfont-osd-scale " + QString::number(value)); */
427}
428
429void MplayerProcess::changeVF(const QString & /*filter*/, bool /*enable*/, const QVariant & /*option*/) {
430 // not supported
431}
432
433void MplayerProcess::changeStereo3DFilter(bool /*enable*/, const QString & /*in*/, const QString & /*out*/) {
434 // not supported
435}
436
437void MplayerProcess::setSubStyles(const AssStyles & styles, const QString & assStylesFile) {
438 if (assStylesFile.isEmpty()) {
439 qWarning("MplayerProcess::setSubStyles: assStylesFile is invalid");
440 return;
441 }
442
443 // Load the styles.ass file
444 if (!QFile::exists(assStylesFile)) {
445 // If file doesn't exist, create it
446 styles.exportStyles(assStylesFile);
447 }
448 if (QFile::exists(assStylesFile)) {
449 setOption("ass-styles", assStylesFile);
450 } else {
451 qWarning("MplayerProcess::setSubStyles: '%s' doesn't exist", assStylesFile.toUtf8().constData());
452 }
453}
Note: See TracBrowser for help on using the repository browser.