source: smplayer/trunk/src/mpvoptions.cpp@ 178

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

smplayer: update trunk to version 16.4

File size: 23.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 <QDir>
20#include <QDebug>
21#include "inforeader.h"
22
23void MPVProcess::addArgument(const QString & /*a*/) {
24}
25
26void MPVProcess::setMedia(const QString & media, bool is_playlist) {
27 arg << "--term-playing-msg="
28 "MPV_VERSION=${=mpv-version:}\n"
29 "INFO_VIDEO_WIDTH=${=width}\nINFO_VIDEO_HEIGHT=${=height}\n"
30 "INFO_VIDEO_ASPECT=${=video-aspect}\n"
31// "INFO_VIDEO_DSIZE=${=dwidth}x${=dheight}\n"
32 "INFO_VIDEO_FPS=${=fps}\n"
33// "INFO_VIDEO_BITRATE=${=video-bitrate}\n"
34 "INFO_VIDEO_FORMAT=${=video-format}\n"
35 "INFO_VIDEO_CODEC=${=video-codec}\n"
36
37// "INFO_AUDIO_BITRATE=${=audio-bitrate}\n"
38// "INFO_AUDIO_FORMAT=${=audio-format}\n" // old
39 "INFO_AUDIO_FORMAT=${=audio-codec-name}\n"
40 "INFO_AUDIO_CODEC=${=audio-codec}\n"
41// "INFO_AUDIO_RATE=${=audio-samplerate}\n" // old
42 "INFO_AUDIO_RATE=${=audio-params/samplerate}\n"
43// "INFO_AUDIO_NCH=${=audio-channels}\n" // old
44 "INFO_AUDIO_NCH=${=audio-params/channel-count}\n"
45
46// "INFO_LENGTH=${=length}\n"
47 "INFO_LENGTH=${=duration:${=length}}\n"
48
49 "INFO_DEMUXER=${=demuxer}\n"
50 "INFO_TITLES=${=disc-titles}\n"
51 "INFO_CHAPTERS=${=chapters}\n"
52 "INFO_TRACKS_COUNT=${=track-list/count}\n"
53
54 "METADATA_TITLE=${metadata/by-key/title:}\n"
55 "METADATA_ARTIST=${metadata/by-key/artist:}\n"
56 "METADATA_ALBUM=${metadata/by-key/album:}\n"
57 "METADATA_GENRE=${metadata/by-key/genre:}\n"
58 "METADATA_DATE=${metadata/by-key/date:}\n"
59 "METADATA_TRACK=${metadata/by-key/track:}\n"
60 "METADATA_COPYRIGHT=${metadata/by-key/copyright:}\n"
61
62 "INFO_MEDIA_TITLE=${=media-title:}\n";
63
64#ifdef CUSTOM_STATUS
65 arg << "--term-status-msg=STATUS: ${=time-pos} / ${=duration:${=length:0}} P: ${=pause} B: ${=paused-for-cache} I: ${=core-idle}";
66#endif
67
68 if (is_playlist) {
69 arg << "--playlist=" + media;
70 } else {
71 arg << media;
72 }
73
74#ifdef CAPTURE_STREAM
75 capturing = false;
76#endif
77}
78
79void MPVProcess::setFixedOptions() {
80 arg << "--no-config";
81 arg << "--no-quiet";
82 arg << "--terminal";
83 arg << "--no-msg-color";
84 arg << "--input-file=/dev/stdin";
85 //arg << "--no-osc";
86 //arg << "--msg-level=vd=v";
87}
88
89void MPVProcess::disableInput() {
90 arg << "--no-input-default-bindings";
91 arg << "--input-x11-keyboard=no";
92 arg << "--no-input-cursor";
93 arg << "--cursor-autohide=no";
94}
95
96bool MPVProcess::isOptionAvailable(const QString & option) {
97 InfoReader * ir = InfoReader::obj(executable());
98 ir->getInfo();
99 //qDebug() << "MPVProcess::isOptionAvailable: option_list:" << ir->optionList();
100 return ir->optionList().contains(option);
101}
102
103void MPVProcess::addVFIfAvailable(const QString & vf, const QString & value) {
104 InfoReader * ir = InfoReader::obj(executable());
105 ir->getInfo();
106 if (ir->vfList().contains(vf)) {
107 QString s = "--vf-add=" + vf;
108 if (!value.isEmpty()) s += "=" + value;
109 arg << s;
110 } else {
111 QString f = vf +"="+ value;
112 qDebug("MPVProcess::addVFIfAvailable: filter %s is not used because it's not available", f.toLatin1().constData());
113 }
114}
115
116void MPVProcess::messageFilterNotSupported(const QString & filter_name) {
117 QString text = tr("the '%1' filter is not supported by mpv").arg(filter_name);
118 writeToStdin(QString("show_text \"%1\" 3000").arg(text));
119}
120
121void MPVProcess::enableScreenshots(const QString & dir, const QString & templ, const QString & format) {
122 if (!templ.isEmpty()) {
123 arg << "--screenshot-template=" + templ;
124 }
125
126 if (!format.isEmpty()) {
127 arg << "--screenshot-format=" + format;
128 }
129
130 if (!dir.isEmpty()) {
131 QString d = QDir::toNativeSeparators(dir);
132 if (!isOptionAvailable("--screenshot-directory")) {
133 qDebug() << "MPVProcess::enableScreenshots: the option --screenshot-directory is not available in this version of mpv";
134 qDebug() << "MPVProcess::enableScreenshots: changing working directory to" << d;
135 setWorkingDirectory(d);
136 } else {
137 arg << "--screenshot-directory=" + d;
138 }
139 }
140}
141
142void MPVProcess::setOption(const QString & option_name, const QVariant & value) {
143 if (option_name == "cache") {
144 int cache = value.toInt();
145 if (cache > 31) {
146 arg << "--cache=" + value.toString();
147 } else {
148 arg << "--cache=no";
149 }
150 }
151 else
152 if (option_name == "ss") {
153 arg << "--start=" + value.toString();
154 }
155 else
156 if (option_name == "endpos") {
157 arg << "--length=" + value.toString();
158 }
159 else
160 if (option_name == "loop") {
161 QString o = value.toString();
162 if (o == "0") o = "inf";
163 arg << "--loop=" + o;
164 }
165 else
166 if (option_name == "ass") {
167 arg << "--sub-ass";
168 }
169 else
170 if (option_name == "noass") {
171 arg << "--no-sub-ass";
172 }
173 else
174 if (option_name == "sub-fuzziness") {
175 QString v;
176 switch (value.toInt()) {
177 case 1: v = "fuzzy"; break;
178 case 2: v = "all"; break;
179 default: v = "exact";
180 }
181 arg << "--sub-auto=" + v;
182 }
183 else
184 if (option_name == "audiofile") {
185 arg << "--audio-file=" + value.toString();
186 }
187 else
188 if (option_name == "delay") {
189 arg << "--audio-delay=" + value.toString();
190 }
191 else
192 if (option_name == "subdelay") {
193 arg << "--sub-delay=" + value.toString();
194 }
195 else
196 if (option_name == "sub") {
197 arg << "--sub-file=" + value.toString();
198 }
199 else
200 if (option_name == "subpos") {
201 arg << "--sub-pos=" + value.toString();
202 }
203 else
204 if (option_name == "font") {
205 arg << "--osd-font=" + value.toString();
206 }
207 else
208 if (option_name == "subcp") {
209 QString cp = value.toString();
210 if (!cp.startsWith("enca")) cp = "utf8:" + cp;
211 arg << "--sub-codepage=" + cp;
212 }
213 else
214 if (option_name == "osdlevel") {
215 arg << "--osd-level=" + value.toString();
216 }
217 else
218 if (option_name == "sws") {
219 arg << "--sws-scaler=lanczos";
220 }
221 else
222 if (option_name == "channels") {
223 arg << "--audio-channels=" + value.toString();
224 }
225 else
226 if (option_name == "subfont-text-scale" || option_name == "ass-font-scale") {
227 arg << "--sub-scale=" + value.toString();
228 }
229 else
230 if (option_name == "stop-xscreensaver") {
231 bool stop_ss = value.toBool();
232 if (stop_ss) arg << "--stop-screensaver"; else arg << "--no-stop-screensaver";
233 }
234 else
235 if (option_name == "correct-pts") {
236 bool b = value.toBool();
237 if (b) arg << "--correct-pts"; else arg << "--no-correct-pts";
238 }
239 else
240 if (option_name == "idx") {
241 arg << "--index=default";
242 }
243 else
244 if (option_name == "softvol") {
245 arg << "--softvol=yes";
246 }
247 else
248 if (option_name == "softvol-max") {
249 int v = value.toInt();
250 if (v < 100) v = 100;
251 arg << "--softvol-max=" + QString::number(v);
252 }
253 else
254 if (option_name == "subfps") {
255 arg << "--sub-fps=" + value.toString();
256 }
257 else
258 if (option_name == "forcedsubsonly") {
259 arg << "--sub-forced-only";
260 }
261 else
262 if (option_name == "prefer-ipv4" || option_name == "prefer-ipv6" ||
263 option_name == "dr" || option_name == "double" ||
264 option_name == "adapter" || option_name == "edl" ||
265 option_name == "slices" || option_name == "colorkey" ||
266 option_name == "subcc" || option_name == "vobsub" ||
267 option_name == "zoom" || option_name == "flip-hebrew" ||
268 option_name == "autoq")
269 {
270 // Ignore
271 }
272 else
273 if (option_name == "tsprog") {
274 // Unsupported
275 }
276 else
277 if (option_name == "dvdangle") {
278 /*
279 arg << "--dvd-angle=" + value.toString();
280 */
281 }
282 else
283 if (option_name == "threads") {
284 arg << "--vd-lavc-threads=" + value.toString();
285 }
286 else
287 if (option_name == "skiploopfilter") {
288 arg << "--vd-lavc-skiploopfilter=all";
289 }
290 else
291 if (option_name == "keepaspect" || option_name == "fs") {
292 bool b = value.toBool();
293 if (b) arg << "--" + option_name; else arg << "--no-" + option_name;
294 }
295 else
296 if (option_name == "ao") {
297 QString o = value.toString();
298 if (o.startsWith("alsa:device=")) {
299 QString device = o.mid(12);
300 //qDebug() << "MPVProcess::setOption: alsa device:" << device;
301 device = device.replace("=", ":").replace(".", ",");
302 o = "alsa:device=[" + device + "]";
303 }
304 arg << "--ao=" + o;
305 }
306 else
307 if (option_name == "vc") {
308 qDebug() << "MPVProcess::setOption: video codec ignored";
309 }
310 else
311 if (option_name == "ac") {
312 qDebug() << "MPVProcess::setOption: audio codec ignored";
313 }
314 else
315 if (option_name == "afm") {
316 QString s = value.toString();
317 if (s == "hwac3") arg << "--ad=spdif:ac3,spdif:dts";
318 }
319 else
320 if (option_name == "enable_streaming_sites_support") {
321 if (isOptionAvailable("--ytdl")) {
322 if (value.toBool()) arg << "--ytdl"; else arg << "--ytdl=no";
323 }
324 }
325 else
326 if (option_name == "fontconfig") {
327 if (isOptionAvailable("--use-text-osd")) {
328 bool b = value.toBool();
329 if (b) arg << "--use-text-osd=yes"; else arg << "--use-text-osd=no";
330 }
331 }
332 else
333 if (option_name == "verbose") {
334 arg << "-v";
335 verbose = true;
336 }
337 else
338 if (option_name == "mute") {
339 arg << "--mute=yes";
340 }
341 else
342 if (option_name == "vf-add") {
343 if (!value.isNull()) arg << "--vf-add=" + value.toString();
344 }
345 else
346 if (option_name == "af-add") {
347 if (!value.isNull()) arg << "--af-add=" + value.toString();
348 }
349 else
350 if (option_name == "wid" ||
351 option_name == "vo" ||
352 option_name == "aid" || option_name == "vid" ||
353 option_name == "volume" ||
354 option_name == "ass-styles" || option_name == "ass-force-style" ||
355 option_name == "ass-line-spacing" ||
356 option_name == "embeddedfonts" ||
357 option_name == "osd-scale" ||
358 option_name == "speed" ||
359 option_name == "contrast" || option_name == "brightness" ||
360 option_name == "hue" || option_name == "saturation" || option_name == "gamma" ||
361 option_name == "monitorpixelaspect" || option_name == "monitoraspect" ||
362 option_name == "mc" ||
363 option_name == "framedrop" ||
364 option_name == "priority" ||
365 option_name == "hwdec" ||
366 option_name == "autosync" ||
367 option_name == "dvd-device" || option_name == "cdrom-device" ||
368 option_name == "demuxer" ||
369 option_name == "frames")
370 {
371 QString s = "--" + option_name;
372 if (!value.isNull()) s += "=" + value.toString();
373 arg << s;
374 }
375 else
376 {
377 qDebug() << "MPVProcess::setOption: unknown option:" << option_name;
378 }
379}
380
381void MPVProcess::addUserOption(const QString & option) {
382 arg << option;
383 if (option == "-v") {
384 verbose = true;
385 }
386}
387
388void MPVProcess::addVF(const QString & filter_name, const QVariant & value) {
389 QString option = value.toString();
390
391 if ((filter_name == "harddup") || (filter_name == "hue")) {
392 // ignore
393 }
394 else
395 if (filter_name == "eq2") {
396 arg << "--vf-add=eq";
397 }
398 else
399 if (filter_name == "blur") {
400 addVFIfAvailable("lavfi", "[unsharp=la=-1.5:ca=-1.5]");
401 }
402 else
403 if (filter_name == "sharpen") {
404 addVFIfAvailable("lavfi", "[unsharp=la=1.5:ca=1.5]");
405 }
406 else
407 if (filter_name == "noise") {
408 addVFIfAvailable("lavfi", "[noise=alls=9:allf=t]");
409 }
410 else
411 if (filter_name == "deblock") {
412 addVFIfAvailable("lavfi", "[pp=" + option +"]");
413 }
414 else
415 if (filter_name == "dering") {
416 addVFIfAvailable("lavfi", "[pp=dr]");
417 }
418 else
419 if (filter_name == "phase") {
420 addVFIfAvailable("lavfi", "[phase=" + option +"]");
421 }
422 else
423 if (filter_name == "postprocessing") {
424 addVFIfAvailable("lavfi", "[pp]");
425 }
426 else
427 if (filter_name == "hqdn3d") {
428 QString o;
429 if (!option.isEmpty()) o = "=" + option;
430 addVFIfAvailable("lavfi", "[hqdn3d" + o +"]");
431 }
432 else
433 if (filter_name == "yadif") {
434 if (option == "1") {
435 arg << "--vf-add=yadif=field";
436 } else {
437 arg << "--vf-add=yadif";
438 }
439 }
440 else
441 if (filter_name == "kerndeint") {
442 addVFIfAvailable("lavfi", "[kerndeint=" + option +"]");
443 }
444 else
445 if (filter_name == "lb" || filter_name == "l5") {
446 addVFIfAvailable("lavfi", "[pp=" + filter_name +"]");
447 }
448 else
449 if (filter_name == "subs_on_screenshots") {
450 // Ignore
451 }
452 else
453 if (filter_name == "rotate") {
454 if (option == "0") {
455 arg << "--vf-add=rotate=270,flip";
456 }
457 else
458 if (option == "1") {
459 arg << "--vf-add=rotate=90";
460 }
461 else
462 if (option == "2") {
463 arg << "--vf-add=rotate=270";
464 }
465 else
466 if (option == "3") {
467 arg << "--vf-add=rotate=90,flip";
468 }
469 }
470 else {
471 if (filter_name == "pp") {
472 QString s;
473 if (option.isEmpty()) s = "[pp]"; else s = "[pp=" + option + "]";
474 addVFIfAvailable("lavfi", s);
475 } else {
476 QString s = filter_name;
477 if (!option.isEmpty()) s += "=" + option;
478 arg << "--vf-add=" + s;
479 }
480 }
481}
482
483void MPVProcess::addStereo3DFilter(const QString & in, const QString & out) {
484 arg << "--vf-add=stereo3d=" + in + ":" + out;
485}
486
487void MPVProcess::addAF(const QString & filter_name, const QVariant & value) {
488 QString option = value.toString();
489
490 if (filter_name == "volnorm") {
491 QString s = "drc";
492 if (!option.isEmpty()) s += "=" + option;
493 arg << "--af-add=" + s;
494 }
495 else
496 if (filter_name == "channels") {
497 if (option == "2:2:0:1:0:0") arg << "--af-add=channels=2:[0-1,0-0]";
498 else
499 if (option == "2:2:1:0:1:1") arg << "--af-add=channels=2:[1-0,1-1]";
500 else
501 if (option == "2:2:0:1:1:0") arg << "--af-add=channels=2:[0-1,1-0]";
502 }
503 else
504 if (filter_name == "pan") {
505 if (option == "1:0.5:0.5") {
506 arg << "--af-add=pan=1:[0.5,0.5]";
507 }
508 }
509 else
510 if (filter_name == "equalizer") {
511 previous_eq = option;
512 arg << "--af-add=equalizer=" + option;
513 }
514 else
515 if (filter_name == "extrastereo") {
516 arg << "--af-add=lavfi=[extrastereo]";
517 }
518 else
519 if (filter_name == "karaoke") {
520 /* Not supported anymore */
521 /* Ignore */
522 }
523 else {
524 QString s = filter_name;
525 if (!option.isEmpty()) s += "=" + option;
526 arg << "--af-add=" + s;
527 }
528}
529
530void MPVProcess::quit() {
531 writeToStdin("quit 0");
532}
533
534void MPVProcess::setVolume(int v) {
535 writeToStdin("set volume " + QString::number(v));
536}
537
538void MPVProcess::setOSD(int o) {
539 writeToStdin("osd " + QString::number(o));
540}
541
542void MPVProcess::setAudio(int ID) {
543 writeToStdin("set aid " + QString::number(ID));
544}
545
546void MPVProcess::setVideo(int ID) {
547 writeToStdin("set vid " + QString::number(ID));
548}
549
550void MPVProcess::setSubtitle(int /*type*/, int ID) {
551 writeToStdin("set sid " + QString::number(ID));
552}
553
554void MPVProcess::disableSubtitles() {
555 writeToStdin("set sid no");
556}
557
558void MPVProcess::setSecondarySubtitle(int ID) {
559 writeToStdin("set secondary-sid " + QString::number(ID));
560}
561
562void MPVProcess::disableSecondarySubtitles() {
563 writeToStdin("set secondary-sid no");
564}
565
566void MPVProcess::setSubtitlesVisibility(bool b) {
567 writeToStdin(QString("set sub-visibility %1").arg(b ? "yes" : "no"));
568}
569
570void MPVProcess::seek(double secs, int mode, bool precise) {
571 QString s = "seek " + QString::number(secs) + " ";
572 switch (mode) {
573 case 0 : s += "relative "; break;
574 case 1 : s += "absolute-percent "; break;
575 case 2 : s += "absolute "; break;
576 }
577 if (precise) s += "exact"; else s += "keyframes";
578 writeToStdin(s);
579}
580
581void MPVProcess::mute(bool b) {
582 writeToStdin(QString("set mute %1").arg(b ? "yes" : "no"));
583}
584
585void MPVProcess::setPause(bool b) {
586 writeToStdin(QString("set pause %1").arg(b ? "yes" : "no"));
587}
588
589void MPVProcess::frameStep() {
590 writeToStdin("frame_step");
591}
592
593void MPVProcess::frameBackStep() {
594 writeToStdin("frame_back_step");
595}
596
597void MPVProcess::showOSDText(const QString & text, int duration, int level) {
598 QString str = QString("show_text \"%1\" %2 %3").arg(text).arg(duration).arg(level);
599 writeToStdin(str);
600}
601
602void MPVProcess::showFilenameOnOSD() {
603 writeToStdin("show_text \"${filename}\" 2000 0");
604}
605
606void MPVProcess::showTimeOnOSD() {
607 writeToStdin("show_text \"${time-pos} / ${length:0} (${percent-pos}%)\" 2000 0");
608}
609
610void MPVProcess::setContrast(int value) {
611 writeToStdin("set contrast " + QString::number(value));
612}
613
614void MPVProcess::setBrightness(int value) {
615 writeToStdin("set brightness " + QString::number(value));
616}
617
618void MPVProcess::setHue(int value) {
619 writeToStdin("set hue " + QString::number(value));
620}
621
622void MPVProcess::setSaturation(int value) {
623 writeToStdin("set saturation " + QString::number(value));
624}
625
626void MPVProcess::setGamma(int value) {
627 writeToStdin("set gamma " + QString::number(value));
628}
629
630void MPVProcess::setChapter(int ID) {
631 writeToStdin("set chapter " + QString::number(ID));
632}
633
634void MPVProcess::nextChapter() {
635 writeToStdin("add chapter 1");
636}
637
638void MPVProcess::previousChapter() {
639 writeToStdin("add chapter -1");
640}
641
642void MPVProcess::setExternalSubtitleFile(const QString & filename) {
643 writeToStdin("sub_add \""+ filename +"\"");
644 //writeToStdin("print_text ${track-list}");
645 writeToStdin("print_text \"INFO_TRACKS_COUNT=${=track-list/count}\"");
646}
647
648void MPVProcess::setSubPos(int pos) {
649 writeToStdin("set sub-pos " + QString::number(pos));
650}
651
652void MPVProcess::setSubScale(double value) {
653 writeToStdin("set sub-scale " + QString::number(value));
654}
655
656void MPVProcess::setSubStep(int value) {
657 writeToStdin("sub_step " + QString::number(value));
658}
659
660void MPVProcess::seekSub(int value) {
661 writeToStdin("sub-seek " + QString::number(value));
662}
663
664void MPVProcess::setSubForcedOnly(bool b) {
665 writeToStdin(QString("set sub-forced-only %1").arg(b ? "yes" : "no"));
666}
667
668void MPVProcess::setSpeed(double value) {
669 writeToStdin("set speed " + QString::number(value));
670}
671
672#ifdef MPLAYER_SUPPORT
673void MPVProcess::enableKaraoke(bool /*b*/) {
674 /*
675 if (b) writeToStdin("af add karaoke"); else writeToStdin("af del karaoke");
676 */
677 messageFilterNotSupported("karaoke");
678}
679#endif
680
681void MPVProcess::enableExtrastereo(bool b) {
682 if (b) writeToStdin("af add lavfi=[extrastereo]"); else writeToStdin("af del lavfi=[extrastereo]");
683}
684
685void MPVProcess::enableVolnorm(bool b, const QString & option) {
686 if (b) writeToStdin("af add drc=" + option); else writeToStdin("af del drc=" + option);
687}
688
689void MPVProcess::setAudioEqualizer(const QString & values) {
690 if (values == previous_eq) return;
691
692 if (!previous_eq.isEmpty()) {
693 writeToStdin("af del equalizer=" + previous_eq);
694 }
695 writeToStdin("af add equalizer=" + values);
696 previous_eq = values;
697}
698
699void MPVProcess::setAudioDelay(double delay) {
700 writeToStdin("set audio-delay " + QString::number(delay));
701}
702
703void MPVProcess::setSubDelay(double delay) {
704 writeToStdin("set sub-delay " + QString::number(delay));
705}
706
707void MPVProcess::setLoop(int v) {
708 QString o;
709 switch (v) {
710 case -1: o = "no"; break;
711 case 0: o = "inf"; break;
712 default: o = QString::number(v);
713 }
714 writeToStdin(QString("set loop %1").arg(o));
715}
716
717void MPVProcess::takeScreenshot(ScreenshotType t, bool include_subtitles) {
718 writeToStdin(QString("screenshot %1 %2").arg(include_subtitles ? "subtitles" : "video").arg(t == Single ? "single" : "each-frame"));
719}
720
721#ifdef CAPTURE_STREAM
722void MPVProcess::switchCapturing() {
723 if (!capture_filename.isEmpty()) {
724 if (!capturing) {
725 QString f = capture_filename;
726 #ifdef Q_OS_WIN
727 // I hate Windows
728 f = f.replace("\\", "\\\\");
729 #endif
730 writeToStdin("set stream-capture \"" + f + "\"");
731 } else {
732 writeToStdin("set stream-capture \"\"");
733 }
734 capturing = !capturing;
735 }
736}
737#endif
738
739void MPVProcess::setTitle(int ID) {
740 writeToStdin("set disc-title " + QString::number(ID));
741}
742
743#if DVDNAV_SUPPORT
744void MPVProcess::discSetMousePos(int x, int y) {
745 qDebug("MPVProcess::discSetMousePos: %d %d", x, y);
746 //writeToStdin(QString("discnav mouse_move %1 %2").arg(x).arg(y));
747 // mouse_move doesn't accept options :?
748
749 // For some reason this doesn't work either...
750 // So it's not possible to select options in the dvd menus just
751 // because there's no way to pass the mouse position to mpv, or it
752 // ignores it.
753 writeToStdin(QString("mouse %1 %2").arg(x).arg(y));
754 //writeToStdin("discnav mouse_move");
755}
756
757void MPVProcess::discButtonPressed(const QString & button_name) {
758 writeToStdin("discnav " + button_name);
759}
760#endif
761
762void MPVProcess::setAspect(double aspect) {
763 writeToStdin("set video-aspect " + QString::number(aspect));
764}
765
766void MPVProcess::setFullscreen(bool b) {
767 writeToStdin(QString("set fullscreen %1").arg(b ? "yes" : "no"));
768}
769
770#if PROGRAM_SWITCH
771void MPVProcess::setTSProgram(int ID) {
772 qDebug("MPVProcess::setTSProgram: function not supported");
773}
774#endif
775
776void MPVProcess::toggleDeinterlace() {
777 writeToStdin("cycle deinterlace");
778}
779
780void MPVProcess::askForLength() {
781 writeToStdin("print_text \"INFO_LENGTH=${=length}\"");
782}
783
784void MPVProcess::setOSDScale(double value) {
785 writeToStdin("set osd-scale " + QString::number(value));
786}
787
788void MPVProcess::changeVF(const QString & filter, bool enable, const QVariant & option) {
789 qDebug() << "MPVProcess::changeVF:" << filter << enable;
790
791 QString f;
792 if (filter == "letterbox") {
793 f = QString("expand=aspect=%1").arg(option.toDouble());
794 }
795 else
796 if (filter == "noise") {
797 f = "lavfi=[noise=alls=9:allf=t]";
798 }
799 else
800 if (filter == "blur") {
801 f = "lavfi=[unsharp=la=-1.5:ca=-1.5]";
802 }
803 else
804 if (filter == "sharpen") {
805 f = "lavfi=[unsharp=la=1.5:ca=1.5]";
806 }
807 else
808 if (filter == "deblock") {
809 f = "lavfi=[pp=" + option.toString() +"]";
810 }
811 else
812 if (filter == "dering") {
813 f = "lavfi=[pp=dr]";
814 }
815 else
816 if (filter == "phase") {
817 f = "lavfi=[phase=" + option.toString() +"]";
818 }
819 else
820 if (filter == "postprocessing") {
821 f = "lavfi=[pp]";
822 }
823 else
824 if (filter == "hqdn3d") {
825 QString o = option.toString();
826 if (!o.isEmpty()) o = "=" + o;
827 f = "lavfi=[hqdn3d" + o +"]";
828 }
829 else
830 if (filter == "rotate") {
831 QString o = option.toString();
832 if (o == "0") {
833 f = "rotate=270,flip";
834 }
835 else
836 if (o == "1") {
837 f = "rotate=90";
838 }
839 else
840 if (o == "2") {
841 f = "rotate=270";
842 }
843 else
844 if (o == "3") {
845 f = "rotate=90,flip";
846 }
847 }
848 else
849 if (filter == "flip" || filter == "mirror") {
850 f = filter;
851 }
852 else
853 if (filter == "scale" || filter == "gradfun") {
854 f = filter;
855 QString o = option.toString();
856 if (!o.isEmpty()) f += "=" + o;
857 }
858 else
859 if (filter == "lb" || filter == "l5") {
860 f = "lavfi=[pp=" + filter +"]";
861 }
862 else
863 if (filter == "yadif") {
864 if (option.toString() == "1") {
865 f = "yadif=field";
866 } else {
867 f = "yadif";
868 }
869 }
870 else
871 if (filter == "kerndeint") {
872 f = "lavfi=[kerndeint=" + option.toString() +"]";
873 }
874 else {
875 qDebug() << "MPVProcess::changeVF: unknown filter:" << filter;
876 }
877
878 if (!f.isEmpty()) {
879 writeToStdin(QString("vf %1 \"%2\"").arg(enable ? "add" : "del").arg(f));
880 }
881}
882
883void MPVProcess::changeStereo3DFilter(bool enable, const QString & in, const QString & out) {
884 QString filter = "stereo3d=" + in + ":" + out;
885 writeToStdin(QString("vf %1 \"%2\"").arg(enable ? "add" : "del").arg(filter));
886}
887
888void MPVProcess::setSubStyles(const AssStyles & styles, const QString &) {
889 QString font = styles.fontname;
890 //arg << "--sub-text-font=" + font.replace(" ", "");
891 arg << "--sub-text-font=" + font;
892 arg << "--sub-text-color=#" + ColorUtils::colorToRRGGBB(styles.primarycolor);
893
894 if (styles.borderstyle == AssStyles::Outline) {
895 arg << "--sub-text-shadow-color=#" + ColorUtils::colorToRRGGBB(styles.backcolor);
896 } else {
897 arg << "--sub-text-back-color=#" + ColorUtils::colorToRRGGBB(styles.outlinecolor);
898 }
899 arg << "--sub-text-border-color=#" + ColorUtils::colorToRRGGBB(styles.outlinecolor);
900
901 arg << "--sub-text-border-size=" + QString::number(styles.outline * 2.5);
902 arg << "--sub-text-shadow-offset=" + QString::number(styles.shadow * 2.5);
903
904 if (isOptionAvailable("--sub-text-font-size")) {
905 arg << "--sub-text-font-size=" + QString::number(styles.fontsize * 2.5);
906 }
907
908 if (isOptionAvailable("--sub-text-bold")) {
909 arg << QString("--sub-text-bold=%1").arg(styles.bold ? "yes" : "no");
910 }
911
912 QString halign;
913 switch (styles.halignment) {
914 case AssStyles::Left: halign = "left"; break;
915 case AssStyles::Right: halign = "right"; break;
916 }
917
918 QString valign;
919 switch (styles.valignment) {
920 case AssStyles::VCenter: valign = "center"; break;
921 case AssStyles::Top: valign = "top"; break;
922 }
923
924 if (!halign.isEmpty() || !valign.isEmpty()) {
925 if (isOptionAvailable("--sub-text-align-x")) {
926 if (!halign.isEmpty()) arg << "--sub-text-align-x=" + halign;
927 if (!valign.isEmpty()) arg << "--sub-text-align-y=" + valign;
928 }
929 }
930}
931
932void MPVProcess::setChannelsFile(const QString & filename) {
933 arg << "--dvbin-file=" + filename;
934}
Note: See TracBrowser for help on using the repository browser.