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

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

smplayer: update trunk to version 16.8.0

File size: 12.8 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 == "cache_auto") {
76 // Nothing to do
77 }
78 else
79 if (option_name == "stop-xscreensaver") {
80 bool stop_ss = value.toBool();
81 if (stop_ss) arg << "-stop-xscreensaver"; else arg << "-nostop-xscreensaver";
82 }
83 else
84 if (option_name == "correct-pts") {
85 bool b = value.toBool();
86 if (b) arg << "-correct-pts"; else arg << "-nocorrect-pts";
87 }
88 else
89 if (option_name == "framedrop") {
90 QString o = value.toString();
91 if (o.contains("vo")) arg << "-framedrop";
92 if (o.contains("decoder")) arg << "-hardframedrop";
93 }
94 else
95 if (option_name == "osd-scale") {
96 arg << "-subfont-osd-scale" << value.toString();
97 }
98 else
99 if (option_name == "verbose") {
100 arg << "-v";
101 }
102 else
103 if (option_name == "enable_streaming_sites_support") {
104 // Not supported
105 }
106 else
107 if (option_name == "hwdec") {
108 // Not supported
109 }
110 else
111 if (option_name == "fontconfig") {
112 bool b = value.toBool();
113 if (b) arg << "-fontconfig"; else arg << "-nofontconfig";
114 }
115 else
116 if (option_name == "mute") {
117 // Not supported
118 }
119 else
120 if (option_name == "softvol") {
121 if (value.toString() != "off") {
122 int v = value.toInt();
123 if (v < 100) v = 100;
124 arg << "-softvol" << "-softvol-max" << QString::number(v);
125 }
126 }
127 else
128 if (option_name == "keepaspect" ||
129 option_name == "dr" || option_name == "double" ||
130 option_name == "fs" || option_name == "slices" ||
131 option_name == "flip-hebrew")
132 {
133 bool b = value.toBool();
134 if (b) arg << "-" + option_name; else arg << "-no" + option_name;
135 }
136 else {
137 arg << "-" + option_name;
138 if (!value.isNull()) arg << value.toString();
139 }
140}
141
142void MplayerProcess::addUserOption(const QString & option) {
143 arg << option;
144}
145
146void MplayerProcess::addVF(const QString & filter_name, const QVariant & value) {
147 QString option = value.toString();
148
149 if (filter_name == "blur" || filter_name == "sharpen") {
150 arg << "-vf-add" << "unsharp=" + option;
151 }
152 else
153 if (filter_name == "deblock") {
154 arg << "-vf-add" << "pp=" + option;
155 }
156 else
157 if (filter_name == "dering") {
158 arg << "-vf-add" << "pp=dr";
159 }
160 else
161 if (filter_name == "postprocessing") {
162 arg << "-vf-add" << "pp";
163 }
164 else
165 if (filter_name == "lb" || filter_name == "l5") {
166 arg << "-vf-add" << "pp=" + filter_name;
167 }
168 else
169 if (filter_name == "subs_on_screenshots") {
170 if (option == "ass") {
171 arg << "-vf-add" << "ass";
172 } else {
173 arg << "-vf-add" << "expand=osd=1";
174 }
175 }
176 else
177 if (filter_name == "flip") {
178 // expand + flip doesn't work well, a workaround is to add another
179 // filter between them, so that's why harddup is here
180 arg << "-vf-add" << "harddup,flip";
181 }
182 else
183 if (filter_name == "expand") {
184 arg << "-vf-add" << "expand=" + option + ",harddup";
185 // Note: on some videos (h264 for instance) the subtitles doesn't disappear,
186 // appearing the new ones on top of the old ones. It seems adding another
187 // filter after expand fixes the problem. I chose harddup 'cos I think
188 // it will be harmless in mplayer.
189 }
190 else {
191 QString s = filter_name;
192 QString option = value.toString();
193 if (!option.isEmpty()) s += "=" + option;
194 arg << "-vf-add" << s;
195 }
196}
197
198void MplayerProcess::addStereo3DFilter(const QString & in, const QString & out) {
199 QString filter = "stereo3d=" + in + ":" + out;
200 filter += ",scale"; // In my PC it doesn't work without scale :?
201 arg << "-vf-add" << filter;
202}
203
204void MplayerProcess::addAF(const QString & filter_name, const QVariant & value) {
205 QString s = filter_name;
206 if (!value.isNull()) s += "=" + value.toString();
207 arg << "-af-add" << s;
208}
209
210void MplayerProcess::quit() {
211 writeToStdin("quit");
212}
213
214void MplayerProcess::setVolume(int v) {
215 writeToStdin("volume " + QString::number(v) + " 1");
216}
217
218void MplayerProcess::setOSD(int o) {
219 writeToStdin(pausing_prefix + " osd " + QString::number(o));
220}
221
222void MplayerProcess::setAudio(int ID) {
223 writeToStdin("switch_audio " + QString::number(ID));
224}
225
226void MplayerProcess::setVideo(int ID) {
227 writeToStdin("set_property switch_video " + QString::number(ID));
228}
229
230void MplayerProcess::setSubtitle(int type, int ID) {
231 switch (type) {
232 case SubData::Vob:
233 writeToStdin( "sub_vob " + QString::number(ID) );
234 break;
235 case SubData::Sub:
236 writeToStdin( "sub_demux " + QString::number(ID) );
237 break;
238 case SubData::File:
239 writeToStdin( "sub_file " + QString::number(ID) );
240 break;
241 default: {
242 qWarning("MplayerProcess::setSubtitle: unknown type!");
243 }
244 }
245}
246
247void MplayerProcess::disableSubtitles() {
248 writeToStdin("sub_source -1");
249}
250
251void MplayerProcess::setSubtitlesVisibility(bool b) {
252 writeToStdin(QString("sub_visibility %1").arg(b ? 1 : 0));
253}
254
255void MplayerProcess::seek(double secs, int mode, bool precise) {
256 QString s = QString("seek %1 %2").arg(secs).arg(mode);
257 if (precise) s += " 1"; else s += " -1";
258 writeToStdin(s);
259}
260
261void MplayerProcess::mute(bool b) {
262 writeToStdin(pausing_prefix + " mute " + QString::number(b ? 1 : 0));
263}
264
265void MplayerProcess::setPause(bool /*b*/) {
266 writeToStdin("pause"); // pauses / unpauses
267}
268
269void MplayerProcess::frameStep() {
270 writeToStdin("frame_step");
271}
272
273void MplayerProcess::frameBackStep() {
274 qDebug("MplayerProcess::frameBackStep: function not supported by mplayer");
275 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
276}
277
278
279void MplayerProcess::showOSDText(const QString & text, int duration, int level) {
280 QString str = QString("osd_show_text \"%1\" %2 %3").arg(text).arg(duration).arg(level);
281 if (!pausing_prefix.isEmpty()) str = pausing_prefix + " " + str;
282 writeToStdin(str);
283}
284
285void MplayerProcess::showFilenameOnOSD() {
286 writeToStdin("osd_show_property_text \"${filename}\" 2000 0");
287}
288
289void MplayerProcess::showTimeOnOSD() {
290 writeToStdin("osd_show_property_text \"${time_pos} / ${length} (${percent_pos}%)\" 2000 0");
291}
292
293void MplayerProcess::setContrast(int value) {
294 writeToStdin(pausing_prefix + " contrast " + QString::number(value) + " 1");
295}
296
297void MplayerProcess::setBrightness(int value) {
298 writeToStdin(pausing_prefix + " brightness " + QString::number(value) + " 1");
299}
300
301void MplayerProcess::setHue(int value) {
302 writeToStdin(pausing_prefix + " hue " + QString::number(value) + " 1");
303}
304
305void MplayerProcess::setSaturation(int value) {
306 writeToStdin(pausing_prefix + " saturation " + QString::number(value) + " 1");
307}
308
309void MplayerProcess::setGamma(int value) {
310 writeToStdin(pausing_prefix + " gamma " + QString::number(value) + " 1");
311}
312
313void MplayerProcess::setChapter(int ID) {
314 writeToStdin("seek_chapter " + QString::number(ID) +" 1");
315}
316
317void MplayerProcess::nextChapter() {
318 writeToStdin("seek_chapter 1 0");
319}
320
321void MplayerProcess::previousChapter() {
322 writeToStdin("seek_chapter -1 0");
323}
324
325void MplayerProcess::setExternalSubtitleFile(const QString & filename) {
326 writeToStdin("sub_load \""+ filename +"\"");
327}
328
329void MplayerProcess::setSubPos(int pos) {
330 writeToStdin("sub_pos " + QString::number(pos) + " 1");
331}
332
333void MplayerProcess::setSubScale(double value) {
334 writeToStdin("sub_scale " + QString::number(value) + " 1");
335}
336
337void MplayerProcess::setSubStep(int value) {
338 writeToStdin("sub_step " + QString::number(value));
339}
340
341#ifdef MPV_SUPPORT
342void MplayerProcess::seekSub(int /*value*/) {
343 /* Not supported */
344 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
345};
346#endif
347
348void MplayerProcess::setSubForcedOnly(bool b) {
349 writeToStdin(QString("forced_subs_only %1").arg(b ? 1 : 0));
350}
351
352void MplayerProcess::setSpeed(double value) {
353 writeToStdin("speed_set " + QString::number(value));
354}
355
356void MplayerProcess::enableKaraoke(bool b) {
357 if (b) writeToStdin("af_add karaoke"); else writeToStdin("af_del karaoke");
358}
359
360void MplayerProcess::enableExtrastereo(bool b) {
361 if (b) writeToStdin("af_add extrastereo"); else writeToStdin("af_del extrastereo");
362}
363
364void MplayerProcess::enableVolnorm(bool b, const QString & option) {
365 if (b) writeToStdin("af_add volnorm=" + option); else writeToStdin("af_del volnorm");
366}
367
368void MplayerProcess::setAudioEqualizer(const QString & values) {
369 writeToStdin("af_cmdline equalizer " + values);
370}
371
372void MplayerProcess::setAudioDelay(double delay) {
373 writeToStdin(pausing_prefix + " audio_delay " + QString::number(delay) +" 1");
374}
375
376void MplayerProcess::setSubDelay(double delay) {
377 writeToStdin(pausing_prefix + " sub_delay " + QString::number(delay) +" 1");
378}
379
380void MplayerProcess::setLoop(int v) {
381 writeToStdin(QString("loop %1 1").arg(v));
382}
383
384void MplayerProcess::setAMarker(int /*sec*/) {
385 /* Not supported */
386}
387
388void MplayerProcess::setBMarker(int /*sec*/) {
389 /* Not supported */
390}
391
392void MplayerProcess::clearABMarkers() {
393 /* Not supported */
394}
395
396void MplayerProcess::takeScreenshot(ScreenshotType t, bool /*include_subtitles*/) {
397 if (t == Single) {
398 writeToStdin(pausing_prefix + " screenshot 0");
399 } else {
400 writeToStdin("screenshot 1");
401 }
402}
403
404#ifdef CAPTURE_STREAM
405void MplayerProcess::switchCapturing() {
406 writeToStdin("capturing");
407}
408#endif
409
410void MplayerProcess::setTitle(int ID) {
411 writeToStdin("switch_title " + QString::number(ID));
412}
413
414#if DVDNAV_SUPPORT
415void MplayerProcess::discSetMousePos(int x, int y) {
416 writeToStdin(QString("set_mouse_pos %1 %2").arg(x).arg(y));
417}
418
419void MplayerProcess::discButtonPressed(const QString & button_name) {
420 writeToStdin("dvdnav " + button_name);
421}
422#endif
423
424void MplayerProcess::setAspect(double aspect) {
425 writeToStdin("switch_ratio " + QString::number(aspect));
426}
427
428void MplayerProcess::setFullscreen(bool b) {
429 writeToStdin(QString("vo_fullscreen %1").arg(b ? "1" : "0"));
430}
431
432#if PROGRAM_SWITCH
433void MplayerProcess::setTSProgram(int ID) {
434 writeToStdin("set_property switch_program " + QString::number(ID) );
435 writeToStdin("get_property switch_audio");
436 writeToStdin("get_property switch_video");
437}
438#endif
439
440void MplayerProcess::toggleDeinterlace() {
441 writeToStdin("step_property deinterlace");
442}
443
444void MplayerProcess::askForLength() {
445 writeToStdin(pausing_prefix + " get_property length");
446}
447
448void MplayerProcess::setOSDScale(double /*value*/) {
449 // not available
450 /* writeToStdin("set_property subfont-osd-scale " + QString::number(value)); */
451}
452
453void MplayerProcess::changeVF(const QString & /*filter*/, bool /*enable*/, const QVariant & /*option*/) {
454 // not supported
455}
456
457void MplayerProcess::changeStereo3DFilter(bool /*enable*/, const QString & /*in*/, const QString & /*out*/) {
458 // not supported
459}
460
461void MplayerProcess::setSubStyles(const AssStyles & styles, const QString & assStylesFile) {
462 if (assStylesFile.isEmpty()) {
463 qWarning("MplayerProcess::setSubStyles: assStylesFile is invalid");
464 return;
465 }
466
467 // Load the styles.ass file
468 if (!QFile::exists(assStylesFile)) {
469 // If file doesn't exist, create it
470 styles.exportStyles(assStylesFile);
471 }
472 if (QFile::exists(assStylesFile)) {
473 setOption("ass-styles", assStylesFile);
474 } else {
475 qWarning("MplayerProcess::setSubStyles: '%s' doesn't exist", assStylesFile.toUtf8().constData());
476 }
477}
Note: See TracBrowser for help on using the repository browser.