https://wiki.archlinux.org/api.php?action=feedcontributions&user=Triplc&feedformat=atomArchWiki - User contributions [en]2024-03-28T18:45:51ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Talk:Input_method&diff=788472Talk:Input method2023-09-26T11:51:27Z<p>Triplc: Emacs works well with ibus/fcitx, the warning is old</p>
<hr />
<div>== More of that stuff ==<br />
<br />
* Emoji support<br />
* Steps to configure desktop environments for IME support (GNOME has top-notch out-of-the-box support by having integrated IBus, KDE can be a right b*tch to set up correctly with either IBus or Fcitx but works almost perfectly afterwards, and I don't know enough about how well other DEs support IMEs)<br />
* Some info on XIM<br />
* Some info on GTK's "simple" unicode input support via {{ic|Ctrl+Shift+u}}<br />
* Some info on how to properly set up shortcuts for changing IME input modes (e.g. from Hiragana to Katakana in the Japanese IMEs). This one is really important, but I personally still haven't found a solution to gracefully resolve the conflicts with the various DEs' global shortcuts, or to emulate some needed keyboard keys present in non-Latin keyboards without affecting text input when the IME is inactive (see e.g. [[Mozc#Use_CapsLock_as_Eisu_toggle_key_on_ASCII_layout_keyboard]])<br />
<br />
-- [[User:Nocifer|Nocifer]] ([[User talk:Nocifer|talk]]) 11:46, 21 November 2020 (UTC)<br />
<br />
:When I first Googled how to switch between Hiragana and Katakana, I saw (Windows?) users saying it's generally F6/F7. I was wonderfully surprised to find this worked out the box with mozc in both fcitx and ibus. I didn't have any DE shortcuts on these keys (I'm on Cinnamon). Note, this isn't the same as changing your "input mode" to START typing in hiragana/katakana (which you can do elsewhere). F6/F7 will convert the word you're busy typing, you can press the other key to convert back. F6 - Hiragana, and F7 - Katakana.<br />
<br />
: -- [[User:Gadicc|Gadicc]] ([[User talk:Gadicc|talk]]) 08:26, 7 December 2020 (UTC)<br />
<br />
:: I'm aware of these shortcuts, but unfortunately they conflict with shortcuts in very common applications like Firefox, Chromium or Libreoffice, so that makes them kind of unusable. In the meantime I think I've found a good solution to add emulation for Eisu, Muhenkan, Hiragana, Katakana and other specialized keys by utilizing XKB (which is the modern, display server agnostic way of modifying keyboard layouts instead of the deprecated and X11-only Xmodmap that is mentioned in [[Mozc#Use_CapsLock_as_Eisu_toggle_key_on_ASCII_layout_keyboard]]) but I've not mentioned it anywhere yet because I'm currently in the process of thinking how all the various localization pages should be organized and which pieces of information should reside where, in order to both avoid duplication and make it easy for a new and totally clueless user to find whatever they may be looking for in the place they'd expect to find it.<br />
<br />
::P.S. I hope you don't mind that I moved your comment below mine, as per the [[Help:Discussion|talk page guidelines]] (in practice, so we can reply to each other without messing up the conversation flow).<br />
<br />
:: -- [[User:Nocifer|Nocifer]] ([[User talk:Nocifer|talk]]) 11:36, 7 December 2020 (UTC)<br />
<br />
== Not all IMEs work by romanisation ==<br />
<br />
So basically, I added [[Wikipedia:Cangjie_input_method]] into the table a month ago. Now I suddenly realise the existence of this statement:<br />
:The IME does this through a process called '''romanization''', which is the transliteration of non-Latin language sounds into the Latin equivalents that most closely resemble them.<br />
Which is totally wrong: in [[Wikipedia:Input method]], '''Cangjie is considered an IME''', but it '''doesn't use romanisation'''. Saying that an IME {{ic|takes Latin characters that you type on your keyboard and outputs them on your screen as non-Latin characters}} is also incorrect in my opinion as users are indeed '''typing Chinese characters''' — radicals — to create Chinese characters. (For more info on how Cangjie works, read the wiki I linked.) And if you are wondering, it is ''practically'' using its own keyboard layout. I'm not sure about the technical details.<br />
<br />
In conclusion, we either need to remove that definition, or need a redefinition. I am adding [[Template:Accuracy]] there, let me know what you think.<br />
<br />
— [[User:Windowsboy111|windowsboy111]] ([[User Talk:Windowsboy111|talk]]) 09:11, 28 April 2021 (UTC)<br />
<br />
:Cangjie does not work by typing Chinese characters and it doesn't use its own keyboard layout, it works by typing standard Latin characters on a standard QWERTY keyboard using a standard US layout, and then these Latin characters are intercepted by the IME, matched to their equivalent Cangjie radicals, and combined to form the hanzi that is finally outputted to the screen. In other words this is still a textbook case of romanization, it's just that it doesn't rely on spoken sounds but rather on written shapes.<br />
<br />
:The inaccuracy here is not in the parts you highlighted, but rather that I described romanization as using only sounds (because it's by far the most common case) where in practice it's a more generic method that can actually use other stuff like e.g. shapes, as in this case. So the last part "''...which is the transliteration of non-Latin language sounds into the Latin equivalents that most closely resemble them''" could be written more generically as something like "''...which is the transliteration of non-Latin language sounds into letters of the Latin alphabet''", and then the example section could be expanded to also showcase the non-sound-based methods like Cangjie.<br />
<br />
:-- [[User:Nocifer|Nocifer]] ([[User talk:Nocifer|talk]]) 14:46, 28 April 2021 (UTC)<br />
<br />
::In my opinion, you can type the radicals directly in Cangjie, so saying it as romanisation isn't that appropriate, as it is not listed [https://en.wikipedia.org/wiki/Romanization here]. Anyway, I think having examples of non-phonetic based examples is a pretty good idea as you've stated. — [[User:Windowsboy111|windowsboy111]] ([[User Talk:Windowsboy111|talk]]) 14:56, 28 April 2021 (UTC)<br />
<br />
:::Ah, so you mean that one can use a Cangjie-specific keyboard layout that directly outputs the Cangjie radicals without an intervening IME? OK, I didn't know that. And well, if Wikipedia doesn't consider Cangjie as a romanization-based input method, then who am I to disagree; so I stand corrected.<br />
<br />
:::So we could have the section changed to read something like "input method editors mainly work via romanization which is the transliteration of sounds etc etc, with the exception of some cases like the Cangjie method which instead work with character shapes like so etc etc". And then remake the Japanese example as the showcase for sound based methods, and add an equivalent Cangjie example as the showcase for shape-based methods.<br />
<br />
:::-- [[User:Nocifer|Nocifer]] ([[User talk:Nocifer|talk]]) 18:38, 28 April 2021 (UTC)<br />
<br />
::::The thing is, every key is "binded" to a radical when you are using Cangjie. I can accept that it is using qwerty and may type English character (since most IMEs support it and I don't see any that doesn't do that), but I don't accept that it's using romanisation. :D<br />
<br />
::::"input method editors mainly work via romanization which is the transliteraion of sounds ..." — We can skip the part of the exception thing since we are showcasing it as an example later in the article.<br />
<br />
::::— [[User:Windowsboy111|windowsboy111]] ([[User Talk:Windowsboy111|talk]]) 00:50, 29 April 2021 (UTC)<br />
<br />
== Regarding the Mozc packages ==<br />
<br />
The "official" {{ic|fcitx5-mozc}} and {{ic|fcitx-mozc}} packages in the community repo are IMHO not properly packaged, in that they bundle both the Mozc-specific components and the Fcitx-specific components, which makes them unable to be installed and used alongside their {{ic|ibus-mozc}} and {{ic|emacs-mozc}} counterparts (which utilize a separate, independent package to provide the Mozc parts) due to file conflicts.<br />
<br />
Also, the two community packages are not updated regularly; the last update was on February 3rd, with the previous one having been back in May 2021, and that was only after I prodded things by posting about this on the AUR mailing list.<br />
<br />
I'm all for finding a proper solution to this issue, but for the time being I'm against using the two community packages as default and have reverted the change by [[User:TheDukeofErl|@TheDukeofErl]] until we can discuss it a bit more.<br />
<br />
[[User:Nocifer|Nocifer]] ([[User talk:Nocifer|talk]]) 09:52, 13 May 2022 (UTC)<br />
<br />
:Packaging issues should not be reported on the wiki, but in the [https://bugs.archlinux.org/ bug tracker]. — [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 15:39, 13 May 2022 (UTC)<br />
<br />
== Moving Emacs section ==<br />
<br />
The section is about setting up input methods, why is Emacs listed here? A better place for it is Emacs#Troubleshooting.<br />
<br />
--[[User:AvidSeeker|AvidSeeker]] ([[User talk:AvidSeeker|talk]]) 12:59, 6 August 2023 (UTC)<br />
<br />
:: That's how you setup input methods to work on Emacs.<br />
:: — [[User:Windowsboy111|windowsboy111]] ([[User Talk:Windowsboy111|talk]]) 13:06, 6 August 2023 (UTC)<br />
<br />
::: If it's specific to emacs then move it to [[emacs]] article. This is configuration of input methods programs like ibus and fcitx. Emacs is irrelevant to those. --[[User:AvidSeeker|AvidSeeker]] ([[User talk:AvidSeeker|talk]]) 13:40, 6 August 2023 (UTC)<br />
<br />
:::: Emacs has a built-in IMF. I'd rather keep it there to make it easier for Emacs users to configure the IMF. I don't see any issues keeping it anyway. — [[User:Windowsboy111|windowsboy111]] ([[User Talk:Windowsboy111|talk]]) 13:42, 6 August 2023 (UTC)<br />
<br />
::Emacs has its own IMF, not feature rich as ibus/fcitx5 for sure. Latest version of Emacs works with ibus/fcitx5 out of the box. What written in the wiki page is old. I personally use the internal IMF of Emacs because I use the vim emulation, which is not very friendly with external IMF. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 11:51, 26 September 2023 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Mpv&diff=654573Talk:Mpv2021-03-12T13:46:44Z<p>Triplc: delete my previous comment</p>
<hr />
<div></div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:JFS&diff=650051Talk:JFS2021-01-28T10:31:30Z<p>Triplc: spelling fixes</p>
<hr />
<div>== Initial draft ==<br />
<br />
I have left out two points from the JFS wiki article:<br />
<br />
# Changing of virtual memory parameters to optimize file system access.<br />
# Claims of JFS 'losing' files.<br />
<br />
The reason that I have not included ways to optimize VM parameters is due to the fact that the JFS port itself has been optimized for the Linux kernel using default values for parameters like /proc/sys/vm/swappiness. Also, changing these parameters can adversely affect certain programs and machines with certain work loads. If people really want to know how to do this type of thing, I'll consider writing up a separate wiki article on that type of optimization for file systems.<br />
<br />
As for claims made about JFS loosing files, I have never experienced in the time I've been using JFS; and I am unable to find sources detailing this problem beyond that of hearsay in forum posts. My personal feeling is that these claims of JFS loosing files are probably the result of a badly written script, backup process or careless command execution. Personally, I have had files 'go missing' on me a few times only to realize that I had done something to erase them. This seems far more likely an explanation than JFS just up-and-remove files at random without the file system itself being damaged in some way. If someone does indeed have this problem, send me an email outlining all the details surrounding the lose and I will see about trying to replicate the problem. <br />
<br />
I have also seen a claim of JFS 'ruining' an 'expensive' hard drive with very valuable data. This person went on to say how he got a quote that said it would be 30k to recover the data, but that it was too expensive, etc. etc. I don't believe this story. How come this data wasn't backed up if it was so extremely valuable? I have accidentally deleted a JFS partition and I was still able to recover much of the data from that drive using jfsrec. Anyway, I am hoping these claims don't work their way into this JFS article without some proper citations to actual file systems tests whose results can be replicated.<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Regarding point two: [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing]<br />
Feel free to ask me for anything else that I didn't think of when posting that.<br />
:--[[User:Byte|byte]]<br />
<br />
<hr><br />
Byte, thanks for bringing that to my attention; I have noted the issue in the JFS article. However, as I noted in [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing] this may very well be a problem due to the device mapper subsystem or a faulty package install. I was able to replicate the problem only on a system using the device mapper, and the issue was fixed by reinstalling all the packages that used the man3 directory. Anyway, thanks again for posting the details so that the problem could be replicated :).<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Shouldn't nodiratime be included with the noatime tip? Admittedly, it doesn't give as much of a performance increase as noatime, but, depending on what you're doing, it CAN still be a substantial enhancement.<br />
<br />
Also, what exactly do you mean by "more testers"? People to purposefully crash systems? I have also been using JFS on everything but /boot (and one oddball partition) for a few months now (3 large standalone partitions, and 4 in an LVM), have had a number of crashes, and, to my knowledge, at least, have never lost anything whatsoever.<br />
:--[[User:Grndrush|Grndrush]] 16:06, 25 March 2008 (EDT)<br />
<br />
== Link 7 ==<br />
<br />
Are we sure link 7 is relevent? According to: http://en.wikipedia.org/wiki/JFS_(file_system) HP-UX has another, different filesystem named JFS that is actually an OEM version of Veritas Software's VxFS. I think link 7 may be refering to the wrong JFS.<br />
<br />
{{Unsigned|Revision as of 18:52, 21 May 2009|Wyxj69vm}}<br />
<br />
== nodiratime ==<br />
<br />
Grndrush: enabling noatime also enables nodiratime.<br />
<br />
{{Unsigned|18:56, 21 May 2009|Wyxj69vm}}<br />
<br />
== JFS losing files. ==<br />
<br />
I've found some evidence of JFS losing files: https://www.usenix.org/events/usenix05/tech/general/full_papers/prabhakaran/prabhakaran.pdf<br />
<br />
Read the section on JFS from page 14 to 15.<br />
<br />
{{Unsigned|11:53, 22 May 2009|Wyxj69vm}}<br />
<br />
:I've reproduced the incident of JFS losing files as described in that pdf, and have edited the wiki accordingly.<br />
:{{Unsigned|14:54, 1 June 2009|1pwl1z8h}}<br />
<br />
== CPU Usage ==<br />
<br />
I have experienced much less CPU usage and faster reads with ext4 and the default I/O scheduler, than with JFS and the deadline I/O scheduler. I feel the claim that JFS uses less CPU may be slightly exaggerated, however I am hesitant to edit the Wiki based on my results alone. I have also had some problems with losing files.<br />
<br />
I have edited the Wiki to include it's noted slowdown when working with many files, as this is verified by at least two sources, one of which is in the references section. I added one more reference as well.<br />
<br />
{{Unsigned|01:28, 14 April 2011|Lupusarcanus}}<br />
<br />
:I use JFS for years and strongly believe that JFS use much less CPU, especially after long years usage. For SSD disks, the fragmented files are nolonger issue. I have not experienced file lost. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 04:33, 18 October 2017 (UTC)<br />
<br />
:"JFS use much less CPU" means less CPU; *does not* mean faster. I believe it uses less RAM too. It is good for low end computers, or laptop batteries. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 10:30, 28 January 2021 (UTC)<br />
<br />
== Definitely slower than ext4 ==<br />
<br />
The article is a bit misleading. I've been using JFS for a week with the Deadline scheduler and this is definitely '''slower''' '''than ext4''' and btrfs even. ''A'' ''lot'' slower than ext4.<br />
<br />
Optimizing the pacman database takes about 3 times longer, resolving dependencies 5, installing the packages may be the same, have not measured it, but feels slower as well. Maybe we should do some proper research on this? Run some real benchmarks on clean systems and discuss them in the forum or elsewhere?<br />
<br />
Also I should add that CPU usage remains exactly the same on most operations.<br />
<br />
{{Unsigned|Revision as of 07:19, 29 April 2018|CarterCox}}</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:JFS&diff=650050Talk:JFS2021-01-28T10:30:36Z<p>Triplc: CPU Usage clarification</p>
<hr />
<div>== Initial draft ==<br />
<br />
I have left out two points from the JFS wiki article:<br />
<br />
# Changing of virtual memory parameters to optimize file system access.<br />
# Claims of JFS 'losing' files.<br />
<br />
The reason that I have not included ways to optimize VM parameters is due to the fact that the JFS port itself has been optimized for the Linux kernel using default values for parameters like /proc/sys/vm/swappiness. Also, changing these parameters can adversely affect certain programs and machines with certain work loads. If people really want to know how to do this type of thing, I'll consider writing up a separate wiki article on that type of optimization for file systems.<br />
<br />
As for claims made about JFS loosing files, I have never experienced in the time I've been using JFS; and I am unable to find sources detailing this problem beyond that of hearsay in forum posts. My personal feeling is that these claims of JFS loosing files are probably the result of a badly written script, backup process or careless command execution. Personally, I have had files 'go missing' on me a few times only to realize that I had done something to erase them. This seems far more likely an explanation than JFS just up-and-remove files at random without the file system itself being damaged in some way. If someone does indeed have this problem, send me an email outlining all the details surrounding the lose and I will see about trying to replicate the problem. <br />
<br />
I have also seen a claim of JFS 'ruining' an 'expensive' hard drive with very valuable data. This person went on to say how he got a quote that said it would be 30k to recover the data, but that it was too expensive, etc. etc. I don't believe this story. How come this data wasn't backed up if it was so extremely valuable? I have accidentally deleted a JFS partition and I was still able to recover much of the data from that drive using jfsrec. Anyway, I am hoping these claims don't work their way into this JFS article without some proper citations to actual file systems tests whose results can be replicated.<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Regarding point two: [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing]<br />
Feel free to ask me for anything else that I didn't think of when posting that.<br />
:--[[User:Byte|byte]]<br />
<br />
<hr><br />
Byte, thanks for bringing that to my attention; I have noted the issue in the JFS article. However, as I noted in [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing] this may very well be a problem due to the device mapper subsystem or a faulty package install. I was able to replicate the problem only on a system using the device mapper, and the issue was fixed by reinstalling all the packages that used the man3 directory. Anyway, thanks again for posting the details so that the problem could be replicated :).<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Shouldn't nodiratime be included with the noatime tip? Admittedly, it doesn't give as much of a performance increase as noatime, but, depending on what you're doing, it CAN still be a substantial enhancement.<br />
<br />
Also, what exactly do you mean by "more testers"? People to purposefully crash systems? I have also been using JFS on everything but /boot (and one oddball partition) for a few months now (3 large standalone partitions, and 4 in an LVM), have had a number of crashes, and, to my knowledge, at least, have never lost anything whatsoever.<br />
:--[[User:Grndrush|Grndrush]] 16:06, 25 March 2008 (EDT)<br />
<br />
== Link 7 ==<br />
<br />
Are we sure link 7 is relevent? According to: http://en.wikipedia.org/wiki/JFS_(file_system) HP-UX has another, different filesystem named JFS that is actually an OEM version of Veritas Software's VxFS. I think link 7 may be refering to the wrong JFS.<br />
<br />
{{Unsigned|Revision as of 18:52, 21 May 2009|Wyxj69vm}}<br />
<br />
== nodiratime ==<br />
<br />
Grndrush: enabling noatime also enables nodiratime.<br />
<br />
{{Unsigned|18:56, 21 May 2009|Wyxj69vm}}<br />
<br />
== JFS losing files. ==<br />
<br />
I've found some evidence of JFS losing files: https://www.usenix.org/events/usenix05/tech/general/full_papers/prabhakaran/prabhakaran.pdf<br />
<br />
Read the section on JFS from page 14 to 15.<br />
<br />
{{Unsigned|11:53, 22 May 2009|Wyxj69vm}}<br />
<br />
:I've reproduced the incident of JFS losing files as described in that pdf, and have edited the wiki accordingly.<br />
:{{Unsigned|14:54, 1 June 2009|1pwl1z8h}}<br />
<br />
== CPU Usage ==<br />
<br />
I have experienced much less CPU usage and faster reads with ext4 and the default I/O scheduler, than with JFS and the deadline I/O scheduler. I feel the claim that JFS uses less CPU may be slightly exaggerated, however I am hesitant to edit the Wiki based on my results alone. I have also had some problems with losing files.<br />
<br />
I have edited the Wiki to include it's noted slowdown when working with many files, as this is verified by at least two sources, one of which is in the references section. I added one more reference as well.<br />
<br />
{{Unsigned|01:28, 14 April 2011|Lupusarcanus}}<br />
<br />
:I use JFS for years and strongly believe that JFS use much less CPU, especially after long years usage. For SSD disks, the fragmented files are nolonger issue. I have not experienced file lost. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 04:33, 18 October 2017 (UTC)<br />
<br />
:"JFS use much less CPU" means less CPU; *does not* mean faster. I believe it uses less RAM too. It is good for low end computer, or laptop battery. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 10:30, 28 January 2021 (UTC)<br />
<br />
== Definitely slower than ext4 ==<br />
<br />
The article is a bit misleading. I've been using JFS for a week with the Deadline scheduler and this is definitely '''slower''' '''than ext4''' and btrfs even. ''A'' ''lot'' slower than ext4.<br />
<br />
Optimizing the pacman database takes about 3 times longer, resolving dependencies 5, installing the packages may be the same, have not measured it, but feels slower as well. Maybe we should do some proper research on this? Run some real benchmarks on clean systems and discuss them in the forum or elsewhere?<br />
<br />
Also I should add that CPU usage remains exactly the same on most operations.<br />
<br />
{{Unsigned|Revision as of 07:19, 29 April 2018|CarterCox}}</div>Triplchttps://wiki.archlinux.org/index.php?title=Map_scancodes_to_keycodes&diff=650002Map scancodes to keycodes2021-01-27T14:57:59Z<p>Triplc: fix error: hdb.d -> hwdb.d</p>
<hr />
<div>[[Category:Keyboard configuration]]<br />
[[ja:スキャンコードをキーコードにマップ]]<br />
This page assumes that you have read [[Keyboard input]], which provides wider context.<br />
<br />
Mapping ''scancodes'' to ''keycodes'' is achieved in a layer lower than Xorg and Linux console, which means that changes to this mapping will be effective in both. [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/input-event-codes.h#n64][https://elixir.bootlin.com/linux/latest/A/ident/hid_keyboard][https://elixir.bootlin.com/linux/latest/A/ident/atkbd_set2_keycode]<br />
<br />
There are two ways of mapping ''scancodes'' to ''keycodes'':<br />
* Using [[udev]]<br />
* Using {{man|8|setkeycodes}}<br />
<br />
The preferred method is to use ''udev'' because it uses hardware information (which is a quite reliable source) to choose the keyboard model in a database. It means that if your keyboard model has been found in the database, your keys are recognized ''out of the box''.<br />
<br />
== Identifying scancodes ==<br />
<br />
You need to know the ''scancodes'' of keys you wish to remap. See [[Keyboard input#Identifying scancodes]] for details.<br />
<br />
== Using udev ==<br />
<br />
[[udev]] provides a builtin function called ''hwdb'' to maintain the hardware database index in {{ic|/etc/udev/hwdb.bin}}. The database is compiled from files with ''.hwdb'' extension located in directories {{ic|/usr/lib/udev/hwdb.d/}}, {{ic|/run/udev/hwdb.d/}} and {{ic|/etc/udev/hwdb.d/}}. The default ''scancodes-to-keycodes'' mapping file is {{ic|/usr/lib/udev/hwdb.d/60-keyboard.hwdb}}. See {{man|7|udev}} for details.<br />
<br />
{{Note|From systemd 220 the udev ABI changed. Users using custom udev hwdb rules should update them according to the new ABI}}<br />
<br />
The ''.hwdb'' file can contain multiple blocks of mappings for different keyboards, or one block can be applied to multiple keyboards. The {{ic|evdev:}} prefix is used to match a block against a hardware, the following hardware matches are supported:<br />
<br />
* Generic input devices (also USB keyboards) identified by the usb kernel modalias: {{bc|evdev:input:b''<bus_id>''v''<vendor_id>''p''<product_id>''e''<version_id>''-''<modalias>''}} where {{ic|''<vendor_id>''}}, {{ic|''<product_id>''}} and {{ic|''<version_id>''}} are the 4-digit hex uppercase vendor, product and version IDs (you can find those by running the {{ic|lsusb}} command) and {{ic|''<modalias>''}} is an arbitrary length input-modalias describing the device capabilities. {{ic|''<bus_id>''}} is the 4-digit hex bus id and should be 0003 for usb devices. The possible {{ic|''<bus_id>''}} values are defined in {{ic|/usr/include/linux/input.h}} (you can run {{ic|awk '/BUS_/ {print $2, $3}' /usr/include/linux/input.h}} to get a list).<br />
* AT keyboard DMI data matches: {{bc|evdev:atkbd:dmi:bvn*:bvr*:bd*:svn''<vendor>'':pn''<product>'':pvr*}} where {{ic|''<vendor>''}} and {{ic|''<product>''}} are the firmware-provided strings exported by the kernel DMI modalias.<br />
* Input driver device name and DMI data match: {{bc|evdev:name:''<input device name>'':dmi:bvn*:bvr*:bd*:svn''<vendor>'':pn*}} where {{ic|''<input_device_name>''}} is the name device specified by the driver and {{ic|''<vendor>''}} is the firmware-provided string exported by the kernel DMI modalias.<br />
<br />
The format of each line in the block body is {{ic|1=KEYBOARD_KEY_''<scancode>''=''<keycode>''}}. The value of {{ic|''<scancode>''}} is hexadecimal, but without the leading {{ic|0x}} (i.e. specify {{ic|a0}} instead of {{ic|0xa0}}), whereas the value of {{ic|''<keycode>''}} is the lower-case keycode name string as listed in {{ic|/usr/include/linux/input-event-codes.h}} (see the {{ic|KEY_''<KEYCODE>''}} variables), a sorted list is available at [https://hal.freedesktop.org/quirk/quirk-keymap-list.txt]. It is not possible to specify decimal value in {{ic|''<keycode>''}}.<br />
<br />
{{Tip|You can obtain the identificator for the device you want to set up a custom ''hwdb'' rule for by using {{ic|evemu-describe}} as the root user. This utility is provided by the {{pkg|evemu}} package. You can obtain the identificator for the device you want to set up a custom ''hwdb'' rule and the key scancode for by running ''evtest'' as the root user. This utility is provided by the {{pkg|evtest}} package.}}<br />
<br />
=== Example for custom hwdb ===<br />
<br />
The example hwdb file will match all AT keyboards:<br />
<br />
{{hc|/etc/udev/hwdb.d/90-custom-keyboard.hwdb|<nowiki><br />
evdev:atkbd:dmi:bvn*:bvr*:bd*:svn*:pn*:pvr*<br />
KEYBOARD_KEY_10=suspend<br />
KEYBOARD_KEY_a0=search<br />
</nowiki>}}<br />
<br />
Here is an example of rebinding modifiers on a laptop and USB keyboard:<br />
<br />
{{hc|/etc/udev/hwdb.d/10-my-modifiers.hwdb|<nowiki><br />
evdev:input:b0003v05AFp8277* # was tested on Kensington Slim Type USB (with old ABI)<br />
KEYBOARD_KEY_70039=leftalt # bind capslock to leftalt<br />
KEYBOARD_KEY_700e2=leftctrl # bind leftalt to leftctrl<br />
<br />
evdev:atkbd:dmi:* # built-in keyboard: match all AT keyboards for now<br />
KEYBOARD_KEY_3a=leftalt # bind capslock to leftalt<br />
KEYBOARD_KEY_38=leftctrl # bind leftalt to leftctrl<br />
</nowiki>}}<br />
<br />
To block the {{ic|Sleep}} key, bind it to the "reserved" keyword. Alternatively, you can use "unknown" to map it to the {{ic|NoSymbol}} key. For example:<br />
<br />
{{hc|/etc/udev/hwdb.d/90-block-sleep.hwdb|2=<br />
evdev:input:b0003v03F0p020C* # hp 5308 keyboard controller<br />
KEYBOARD_KEY_10082=reserved<br />
}}<br />
<br />
=== Updating the Hardware Database Index ===<br />
<br />
After changing the configuration files, the hardware database index, {{ic|hwdb.bin}}, needs to be rebuilt. <br />
<br />
* Update {{ic|hwdb.bin}} manually by running<br />
# systemd-hwdb update<br />
<br />
{{Out of date|{{ic|1=ConditionNeedsUpdate=/etc}} seems to be commented out by default in {{ic|systemd-hwdb-update.service}} (checked in {{pkg|systemd}} 232).}}<br />
{{Accuracy|Don't edit in {{ic|/usr/lib/}}, use [[Systemd#Editing_provided_units|systemctl edit]].}}<br />
<br />
* Update automatically on each reboot by commenting out {{ic|ConditionNeedsUpdate}} in {{ic|systemd-hwdb-update.service}}.<br />
<br />
{{hc|/usr/lib/systemd/system/systemd-hwdb-update.service|<nowiki><br />
# This file is part of systemd.<br />
.<br />
.<br />
#ConditionNeedsUpdate=/etc<br />
.<br />
.<br />
</nowiki>}}<br />
<br />
After {{ic|systemd-hwdb-update.service}} finished loading {{ic|systemd-trigger.service}} will reload the changes from <br />
{{ic|hwdb.bin}}.<br />
<br />
* Automatically after [[Systemd]] upgrade.<br />
<br />
On each upgrade of [[Systemd]], the installation script rebuilds {{ic|hwdb.bin}} by running {{ic|udevadm hwdb --update}} as the root user, so we do not need to care about it.<br />
<br />
=== Reloading the Hardware Database Index ===<br />
<br />
The kernel loads {{ic|hwdb.bin}} as part of the boot process, rebooting the system will promise the loading of the updated {{ic|hwdb.bin}}.<br />
<br />
With {{ic|udevadm}} it is possible to load new key mapping from the updated {{ic|hwdb.bin}} by running<br />
# udevadm trigger<br />
Be aware that with {{ic|udevadm}} only added or changed key mapping are loaded so if we delete a mapping from the config file, rebuild {{ic|hwdb.bin}} and run {{ic|udevadm trigger}} as the root user, then the deleted mapping still kept by the kernel, at least until a reboot.<br />
<br />
=== Querying the database ===<br />
<br />
You can check that your configuration was loaded either by pressing keys, or by running {{ic|udevadm info}}. For the USB keyboard in the above example, this outputs the mapping we configured as follows:<br />
<br />
# udevadm info /dev/input/by-path/*-usb-*-kbd | grep KEYBOARD_KEY<br />
E: KEYBOARD_KEY_70039=leftalt<br />
E: KEYBOARD_KEY_700e2=leftctrl<br />
<br />
== Using setkeycodes ==<br />
<br />
''setkeycodes'' is a tool to load ''scancodes''-to-''keycodes'' mapping table into Linux kernel. Its usage is:<br />
<br />
# setkeycodes ''scancode'' ''keycode'' ...<br />
<br />
It is possible to specify multiple pairs at once. ''Scancodes'' are given in hexadecimal, ''keycodes'' in decimal.<br />
<br />
{{Note|Apparently ''setkeycodes'' does not work with USB keyboards (Linux 3.14.44-1-lts):<br />
<br />
# setkeycodes 45 30 # bind NumLock (0x45) to KEY_A (30) on AT keyboard<br />
(successful)<br />
# setkeycodes 70053 30 # bind NumLock (0x70053) to KEY_A (30) on USB keyboard<br />
KDSETKEYCODE: Invalid argument<br />
failed to set scancode 620d3 to keycode 31<br />
}}</div>Triplchttps://wiki.archlinux.org/index.php?title=Map_scancodes_to_keycodes&diff=636574Map scancodes to keycodes2020-09-26T18:50:32Z<p>Triplc: (i) add an quick example to block sleep key, it is usefull for me, i searcg bbs.archlinux.org and see some questions about it too; (ii) evtest can show both scancode and device id</p>
<hr />
<div>[[Category:Keyboard configuration]]<br />
[[ja:スキャンコードをキーコードにマップ]]<br />
This page assumes that you have read [[Keyboard input]], which provides wider context.<br />
<br />
Mapping ''scancodes'' to ''keycodes'' is achieved in a layer lower than Xorg and Linux console, which means that changes to this mapping will be effective in both. [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/input-event-codes.h#n64][https://elixir.bootlin.com/linux/latest/A/ident/hid_keyboard][https://elixir.bootlin.com/linux/latest/A/ident/atkbd_set2_keycode]<br />
<br />
There are two ways of mapping ''scancodes'' to ''keycodes'':<br />
* Using [[udev]]<br />
* Using {{man|8|setkeycodes}}<br />
<br />
The preferred method is to use ''udev'' because it uses hardware information (which is a quite reliable source) to choose the keyboard model in a database. It means that if your keyboard model has been found in the database, your keys are recognized ''out of the box''.<br />
<br />
== Identifying scancodes ==<br />
<br />
You need to know the ''scancodes'' of keys you wish to remap. See [[Keyboard input#Identifying scancodes]] for details.<br />
<br />
== Using udev ==<br />
<br />
[[udev]] provides a builtin function called ''hwdb'' to maintain the hardware database index in {{ic|/etc/udev/hwdb.bin}}. The database is compiled from files with ''.hwdb'' extension located in directories {{ic|/usr/lib/udev/hwdb.d/}}, {{ic|/run/udev/hwdb.d/}} and {{ic|/etc/udev/hwdb.d/}}. The default ''scancodes-to-keycodes'' mapping file is {{ic|/usr/lib/udev/hwdb.d/60-keyboard.hwdb}}. See {{man|7|udev}} for details.<br />
<br />
{{Note|From systemd 220 the udev ABI changed. Users using custom udev hwdb rules should update them according to the new ABI}}<br />
<br />
The ''.hwdb'' file can contain multiple blocks of mappings for different keyboards, or one block can be applied to multiple keyboards. The {{ic|evdev:}} prefix is used to match a block against a hardware, the following hardware matches are supported:<br />
<br />
* Generic input devices (also USB keyboards) identified by the usb kernel modalias: {{bc|evdev:input:b''<bus_id>''v''<vendor_id>''p''<product_id>''e''<version_id>''-''<modalias>''}} where {{ic|''<vendor_id>''}}, {{ic|''<product_id>''}} and {{ic|''<version_id>''}} are the 4-digit hex uppercase vendor, product and version IDs (you can find those by running the {{ic|lsusb}} command) and {{ic|''<modalias>''}} is an arbitrary length input-modalias describing the device capabilities. {{ic|''<bus_id>''}} is the 4-digit hex bus id and should be 0003 for usb devices. The possible {{ic|''<bus_id>''}} values are defined in {{ic|/usr/include/linux/input.h}} (you can run {{ic|awk '/BUS_/ {print $2, $3}' /usr/include/linux/input.h}} to get a list).<br />
* AT keyboard DMI data matches: {{bc|evdev:atkbd:dmi:bvn*:bvr*:bd*:svn''<vendor>'':pn''<product>'':pvr*}} where {{ic|''<vendor>''}} and {{ic|''<product>''}} are the firmware-provided strings exported by the kernel DMI modalias.<br />
* Input driver device name and DMI data match: {{bc|evdev:name:''<input device name>'':dmi:bvn*:bvr*:bd*:svn''<vendor>'':pn*}} where {{ic|''<input_device_name>''}} is the name device specified by the driver and {{ic|''<vendor>''}} is the firmware-provided string exported by the kernel DMI modalias.<br />
<br />
The format of each line in the block body is {{ic|1=KEYBOARD_KEY_''<scancode>''=''<keycode>''}}. The value of {{ic|''<scancode>''}} is hexadecimal, but without the leading {{ic|0x}} (i.e. specify {{ic|a0}} instead of {{ic|0xa0}}), whereas the value of {{ic|''<keycode>''}} is the lower-case keycode name string as listed in {{ic|/usr/include/linux/input-event-codes.h}} (see the {{ic|KEY_''<KEYCODE>''}} variables), a sorted list is available at [https://hal.freedesktop.org/quirk/quirk-keymap-list.txt]. It is not possible to specify decimal value in {{ic|''<keycode>''}}.<br />
<br />
{{Tip|You can obtain the identificator for the device you want to setup a custom ''hwdb'' rule for by using {{ic|evemu-describe}} as the root user. This utility provided by the {{pkg|evemu}} package. You can obtain the identificator for the device you want to setup a custom ''hwdb'' rule and the key scancode for by using {{ic|evtest}} as the root user. This utility provided by the {{pkg|evtest}} package.}}<br />
<br />
=== Example for custom hwdb ===<br />
<br />
The example hwdb file will match all AT keyboards:<br />
<br />
{{hc|/etc/udev/hwdb.d/90-custom-keyboard.hwdb|<nowiki><br />
evdev:atkbd:dmi:bvn*:bvr*:bd*:svn*:pn*:pvr*<br />
KEYBOARD_KEY_10=suspend<br />
KEYBOARD_KEY_a0=search<br />
</nowiki>}}<br />
<br />
Here is an example of rebinding modifiers on a laptop and USB keyboard:<br />
<br />
{{hc|/etc/udev/hwdb.d/10-my-modifiers.hwdb|<nowiki><br />
evdev:input:b0003v05AFp8277* # was tested on Kensington Slim Type USB (with old ABI)<br />
KEYBOARD_KEY_70039=leftalt # bind capslock to leftalt<br />
KEYBOARD_KEY_700e2=leftctrl # bind leftalt to leftctrl<br />
<br />
evdev:atkbd:dmi:* # built-in keyboard: match all AT keyboards for now<br />
KEYBOARD_KEY_3a=leftalt # bind capslock to leftalt<br />
KEYBOARD_KEY_38=leftctrl # bind leftalt to leftctrl<br />
<br />
evdev:input:b0003v03F0p020C* # hp 5308 keyboard controller<br />
KEYBOARD_KEY_10082=reserved # block the sleep key by 'reserved' it<br />
# map to 'unknown' to map it to NoSymbol key<br />
<br />
</nowiki>}}<br />
<br />
=== Updating the Hardware Database Index ===<br />
<br />
After changing the configuration files, the hardware database index, {{ic|hwdb.bin}}, needs to be rebuilt. <br />
<br />
* Update {{ic|hwdb.bin}} manually by running<br />
# systemd-hwdb update<br />
<br />
{{Out of date|{{ic|1=ConditionNeedsUpdate=/etc}} seems to be commented out by default in {{ic|systemd-hwdb-update.service}} (checked in {{pkg|systemd}} 232).}}<br />
{{Accuracy|Don't edit in {{ic|/usr/lib/}}, use [[Systemd#Editing_provided_units|systemctl edit]].}}<br />
<br />
* Update automatically on each reboot by commenting out {{ic|ConditionNeedsUpdate}} in {{ic|systemd-hwdb-update.service}}.<br />
<br />
{{hc|/usr/lib/systemd/system/systemd-hwdb-update.service|<nowiki><br />
# This file is part of systemd.<br />
.<br />
.<br />
#ConditionNeedsUpdate=/etc<br />
.<br />
.<br />
</nowiki>}}<br />
<br />
After {{ic|systemd-hwdb-update.service}} finished loading {{ic|systemd-trigger.service}} will reload the changes from <br />
{{ic|hwdb.bin}}.<br />
<br />
* Automatically after [[Systemd]] upgrade.<br />
<br />
On each upgrade of [[Systemd]], the installation script rebuilds {{ic|hwdb.bin}} by running {{ic|udevadm hwdb --update}} as the root user, so we do not need to care about it.<br />
<br />
=== Reloading the Hardware Database Index ===<br />
<br />
The kernel loads {{ic|hwdb.bin}} as part of the boot process, rebooting the system will promise the loading of the updated {{ic|hwdb.bin}}.<br />
<br />
With {{ic|udevadm}} it is possible to load new key mapping from the updated {{ic|hwdb.bin}} by running<br />
# udevadm trigger<br />
Be aware that with {{ic|udevadm}} only added or changed key mapping are loaded so if we delete a mapping from the config file, rebuild {{ic|hwdb.bin}} and run {{ic|udevadm trigger}} as the root user, then the deleted mapping still kept by the kernel, at least until a reboot.<br />
<br />
=== Querying the database ===<br />
<br />
You can check that your configuration was loaded either by pressing keys, or by running {{ic|udevadm info}}. For the USB keyboard in the above example, this outputs the mapping we configured as follows:<br />
<br />
# udevadm info /dev/input/by-path/*-usb-*-kbd | grep KEYBOARD_KEY<br />
E: KEYBOARD_KEY_70039=leftalt<br />
E: KEYBOARD_KEY_700e2=leftctrl<br />
<br />
== Using setkeycodes ==<br />
<br />
''setkeycodes'' is a tool to load ''scancodes''-to-''keycodes'' mapping table into Linux kernel. Its usage is:<br />
<br />
# setkeycodes ''scancode'' ''keycode'' ...<br />
<br />
It is possible to specify multiple pairs at once. ''Scancodes'' are given in hexadecimal, ''keycodes'' in decimal.<br />
<br />
{{Note|Apparently ''setkeycodes'' does not work with USB keyboards (Linux 3.14.44-1-lts):<br />
<br />
# setkeycodes 45 30 # bind NumLock (0x45) to KEY_A (30) on AT keyboard<br />
(successful)<br />
# setkeycodes 70053 30 # bind NumLock (0x70053) to KEY_A (30) on USB keyboard<br />
KDSETKEYCODE: Invalid argument<br />
failed to set scancode 620d3 to keycode 31<br />
}}</div>Triplchttps://wiki.archlinux.org/index.php?title=User_talk:Triplc&diff=635230User talk:Triplc2020-09-14T02:39:35Z<p>Triplc: Blanked the page</p>
<hr />
<div></div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=633419Mpv2020-08-25T20:21:20Z<p>Triplc: /* Volume normalization */ no need the lavfi</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
{{Expansion|Add little more details about the available filters, see [https://superuser.com/a/323127] for a comparison of {{ic|loudnorm}} and {{ic|dynaudnorm}}.}}<br />
<br />
Different sources may have different or inconsistent loudness, so ''mpv'' users may need to configure automatic volume normalization. For example:<br />
<br />
{{hc|~/.config/mpv/input.conf|2=<br />
n cycle_values af loudnorm=I=-30 loudnorm=I=-15 anull<br />
}}<br />
<br />
This binds the key {{ic|n}} to cycle the audio filter settings ({{ic|af}}) through the specified values:<br />
<br />
* {{ic|1=loudnorm=I=-30}}: loudnorm setting with {{ic|1=I=-30}}, soft volume, might be suitable for background music<br />
* {{ic|1=loudnorm=I=-15}}: louder volume, might be good for the video currently in view<br />
* {{ic|anull}}: reset audio filter to null, i.e., disable the audio filter<br />
<br />
{{Note|Binding a key does not change the default audio filter. To change the default, add e.g. {{ic|1=af=loudnorm=I=-30}} to the main configuration file.}}<br />
<br />
Audio filtering in ''mpv'' is provided by the [[ffmpeg]] backend. See [[Wikipedia:EBU R 128]] and [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg loudnorm filter] for details.<br />
<br />
See also upstream issues [https://github.com/mpv-player/mpv/issues/3979] and [https://github.com/mpv-player/mpv/issues/2883] which mention different options.<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Mpv&diff=632955Talk:Mpv2020-08-22T22:08:16Z<p>Triplc: add example</p>
<hr />
<div>+ As for volume normalization, I've tested both dynaudnorm, and loudnorm, and I think loudnorm is better, in the sense that it more correctly normalize the loudness that human ears perceive, not peak value. I listen to 3 types of audio: (i) music; (ii) speech only, no music; (iii) audio containing both voice and music. Dynaudnorm tend to make music (i) louder than speech (ii). Anyway, this is only personal experience. Others may have different opinions of cause.<br />
<br />
Example:<br />
<br />
mpv --vid=no --af='lavfi=[loudnorm=I=-15]' 'https://www.youtube.com/watch?v=bPTVUFu5Zyw' 'https://www.youtube.com/watch?v=vP4iY1TtS3s'<br />
<br />
mpv --vid=no --af='lavfi=[dynaudnorm=p=0.95]' 'https://www.youtube.com/watch?v=bPTVUFu5Zyw' 'https://www.youtube.com/watch?v=vP4iY1TtS3s'<br />
<br />
2 videos: one is a music only, and one is a speech only<br />
<br />
loudnorm and dynaudnorm are set with similar loudness when we hear the music; however, when it comes to the speech, the dynaudnorm volume too low.<br />
<br />
[[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 22:08, 22 August 2020 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Mpv&diff=632954Talk:Mpv2020-08-22T21:57:53Z<p>Triplc: small fix</p>
<hr />
<div>+ As for volume normalization, I've tested both dynaudnorm, and loudnorm, and I think loudnorm is better, in the sense that it more correctly normalize the loudness that human ears perceive, not peak value. I listen to 3 types of audio: (i) music; (ii) speech only, no music; (iii) audio containing both voice and music. Dynaudnorm tend to make music (i) louder than speech (ii). Anyway, this is only personal experience. Others may have different opinions of cause. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 21:57, 22 August 2020 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Mpv&diff=632951Talk:Mpv2020-08-22T21:57:11Z<p>Triplc: about loudnorm</p>
<hr />
<div>+ As for volume normalization, I've tested both dynaudnorm, and loudnorm, and I think loudnorm is better, in the sense that it more correctly normalize the loudness that human ears perceive, not peak value. I listen two 3 types of audio: (i) music; (ii) speech only, no music; (iii) audio containing both voice and music. Dynaudnorm tend to make music (i) louder than speech (ii). Anyway, this is only personal experience. Others may have different opinions of cause. [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 21:57, 22 August 2020 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632839Mpv2020-08-21T23:20:37Z<p>Triplc: /* Video on/off (audio only) */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, or inconsistent loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, might suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for the video currently in view<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]] backend; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Video on/off (audio only) ===<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
N cycle_values vid no 1<br />
<br />
## N : bind to 'N' key<br />
## cycle_values : set value in one of predefined values<br />
## vid : video source selection<br />
## no : no video, audio only, bandwidth saving, might good for youtube music<br />
## 1 : video source 1, the default video source<br />
</nowiki>}}<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632838Mpv2020-08-21T23:14:57Z<p>Triplc: /* Video on/off (audio only) */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, or inconsistent loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, might suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for the video currently in view<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]] backend; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Video on/off (audio only) ===<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
N cycle_values vid no 1<br />
<br />
## N : bind to 'N' key<br />
## cycle_values : set value in one of predefined values<br />
## vid : video source selection<br />
## no : no video, audio only, might good for listening from youtube<br />
## 1 : video source 1, the default video source<br />
</nowiki>}}<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632837Mpv2020-08-21T23:11:01Z<p>Triplc: /* Video on/off */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, or inconsistent loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, might suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for the video currently in view<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]] backend; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Video on/off ===<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
N cycle_values vid no 1<br />
<br />
## N : bind to 'N' key<br />
## cycle_values : set value in one of predefined values<br />
## vid : video source selection<br />
## no : no video, audio only, might good for listening from youtube<br />
## 1 : video source 1, the first default video<br />
</nowiki>}}<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632836Mpv2020-08-21T23:00:07Z<p>Triplc: /* Volume normalization */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, or inconsistent loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, might suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for the video currently in view<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]] backend; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632835Mpv2020-08-21T22:55:04Z<p>Triplc: /* Volume normalization */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, or inconsistent loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, may suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for currently viewing video<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]]; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=Mpv&diff=632834Mpv2020-08-21T22:48:54Z<p>Triplc: /* Volume normalization */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Video]]<br />
[[Category:Audio]]<br />
[[Category:Streaming]]<br />
[[es:Mpv]]<br />
[[ja:Mpv]]<br />
[[ru:Mpv]]<br />
[[zh-hans:Mpv]]<br />
{{Related articles start}}<br />
{{Related|MPlayer}}<br />
{{Related|youtube-dl}}<br />
{{Related articles end}}<br />
<br />
[https://mpv.io/ mpv] is a media player based on [[MPlayer]] and the now unmaintained ''mplayer2''. It supports a wide variety of video file formats, audio and video codecs, and subtitle types. A comprehensive (although admittedly incomplete) list of differences between ''mpv'' and the aforementioned players can be found [https://github.com/mpv-player/mpv/blob/master/DOCS/mplayer-changes.rst here].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|mpv}} package or {{AUR|mpv-git}} for the development version.<br />
<br />
=== Front ends ===<br />
<br />
See [[List of applications/Multimedia#mpv-based]].<br />
<br />
== Configuration ==<br />
<br />
''mpv'' comes with good all-around defaults that should work well on computers with weaker/older video cards. However, if you have a computer with a more modern video card then ''mpv'' allows you to do a great deal of configuration to achieve better video quality (limited only by the power of your video card). To do this one only needs to create a few configuration files (they do not exist by default).<br />
<br />
{{Note| Configuration files are read system-wide from {{ic|/etc/mpv}} and per-user from {{ic|~/.config/mpv}} (unless the [[environment variable]] {{ic|XDG_CONFIG_HOME}} is set), where per-user settings override system-wide settings, all of which are overridden by the command line. User specific configuration is suggested since it may require some trial and error.}}<br />
<br />
To help you get started ''mpv'' provides sample configuration files with default settings. Copy them to use as a starting point:<br />
<br />
$ cp -r /usr/share/doc/mpv/ ~/.config/<br />
<br />
{{ic|mpv.conf}} contains the majority of ''mpv'''s settings, {{ic|input.conf}} contains key bindings. Read through both of them to get an idea of how they work and what options are available.<br />
<br />
=== General settings ===<br />
<br />
Add the following settings to {{ic|~/.config/mpv/mpv.conf}}.<br />
<br />
==== High quality configurations ====<br />
<br />
This loads high quality OpenGL options when using {{ic|1=vo=gpu}} as video output (default). Most users can run these without any problems, but they are not enabled by default to avoid causing problems for the few users who cannot run them:<br />
<br />
profile=gpu-hq<br />
<br />
The {{ic|gpu-hq}} profile defaults to the {{ic|spline36}} scaling filter for mid quality and speed. For the best quality video output, the manual states that if your hardware can run it, {{ic|ewa_lanczossharp}} is probably what you should use.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
<br />
These last three options are a little more complicated. The first option makes it so that if audio and video go out of sync then instead of dropping video frames it will resample the audio (a slight change in audio pitch is often less noticeable than dropped frames). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Display-synchronization Display Synchronization]. The remaining two essentially make motion appear smoother on your display by changing the way that frames are shown so that the source framerate jives better with your display's refresh rate (not to be confused with SVP's technique which actually converts video to 60fps). The mpv wiki has an in depth article on it titled [https://github.com/mpv-player/mpv/wiki/Interpolation Interpolation] though it is also commonly known as ''smoothmotion''.<br />
<br />
profile=gpu-hq<br />
scale=ewa_lanczossharp<br />
cscale=ewa_lanczossharp<br />
video-sync=display-resample<br />
interpolation<br />
tscale=oversample<br />
<br />
{{Note| If [[NVIDIA Optimus]] is being used, the line {{ic|1=video-sync=display-resample}} may cause video to be sped up.}}<br />
<br />
Beyond this there is still a lot you can do but things become more complicated, require more powerful video cards, and are in constant development. As a brief overview, it is possible to load special shaders that perform exotic scaling and sharpening techniques including some that actually use deep neural networks trained on images (for both real world and animated content). To learn more about this take a look around the [https://github.com/mpv-player/mpv/wiki mpv wiki], particularly the [https://github.com/mpv-player/mpv/wiki/User-Scripts#user-shaders user shader's section].<br />
<br />
There are also plenty of other options you may find desirable as well. It is worthwhile taking a look at {{man|1|mpv}}. It is also helpful to run ''mpv'' from the command line to check for error messages about the config.<br />
<br />
==== Custom profiles ====<br />
<br />
In {{ic|mpv.conf}} it is possible to create ''profiles'' which are essentially just "groups of options" with which you can:<br />
<br />
* Quickly switch between different configurations without having to rewrite the file.<br />
* Create special profiles for special content.<br />
* ''nest'' profiles so that you can make more complicated ''profiles'' out of simpler ones.<br />
<br />
Creating a profile is easy. The area at the top of {{ic|mpv.conf}} is called the top level, any options you write there will kick into effect once ''mpv'' is started. However, once you define a profile by writing its name in brackets then every option you write below it (until you define a new profile) is considered part of that profile. Here is an example {{ic|mpv.conf}}:<br />
<br />
profile=myprofile2 #Top level area, load myprofile2<br />
ontop=yes #Always on top<br />
<br />
[myprofile1] #A simple profile, top level area ends here<br />
profile-desc="a profile" #Optional description for profile<br />
fs=yes #Start in full screen<br />
<br />
[myprofile2] #Another simple profile<br />
profile=gpu-hq #A built in profile that comes with mpv<br />
log-file=~~/log #Sets a location for writing a log file, ~~/ translates to ~/.config/mpv<br />
<br />
There are only two lines within the top level area and there are two separate profiles defined below it. When ''mpv'' starts it sees the first line, loads the options in {{ic|myprofile2}} (which means it loads the options in {{ic|gpu-hq}} and {{ic|1=log-file=~~/log}}) finally it loads {{ic|1=ontop=yes}} and finishes starting up. Note, {{ic|myprofile1}} is never loaded because it is never called in the top level area.<br />
<br />
Alternatively one could call ''mpv'' from the command line with:<br />
<br />
$ mpv --profile=myprofile1 video.mkv<br />
<br />
and it would ignore all options except the ones for {{ic|myprofile1}}.<br />
<br />
=== Key bindings ===<br />
<br />
Key bindings are fairly straightforward given the examples in {{ic|/usr/share/doc/mpv/input.conf}} and the relevant section in the [https://mpv.io/manual/master/#command-interface manual].<br />
<br />
Add the following examples to {{ic|~/.config/mpv/input.conf}}:<br />
<br />
shift+s screenshot each-frame<br />
Shift+UP seek 600<br />
Shift+DOWN seek -600<br />
= cycle video-unscaled<br />
- cycle-values window-scale 2 3 1 .5<br />
WHEEL_UP add volume 5<br />
WHEEL_DOWN add volume -5<br />
WHEEL_LEFT ignore<br />
WHEEL_RIGHT ignore<br />
Alt+RIGHT add video-rotate 90<br />
Alt+LEFT add video-rotate -90<br />
Alt+- add video-zoom -0.25<br />
Alt+= add video-zoom 0.25<br />
Alt+j add video-pan-x -0.05<br />
Alt+l add video-pan-x 0.05<br />
Alt+i add video-pan-y 0.05<br />
Alt+k add video-pan-y -0.05<br />
Alt+BS set video-zoom 0; set video-pan-x 0; set video-pan-y 0<br />
<br />
For an attempt to reproduce MPC-HC key bindings in mpv, see [https://github.com/dragons4life/MPC-HC-config-for-MPV/blob/master/input.conf].<br />
<br />
=== Additional configuration files ===<br />
<br />
In addition there are a few more configuration files and directories that can be created, among which:<br />
<br />
* {{ic|~/.config/mpv/script-opts/osc.conf}} manages the [https://mpv.io/manual/master/#on-screen-controller On Screen Controller].<br />
* {{ic|~/.config/mpv/scripts/''script-name''.lua}} for Lua scripts. See [https://github.com/mpv-player/mpv/issues/3500#issuecomment-305646994] for an example.<br />
<br />
See https://mpv.io/manual/master/#files for more.<br />
<br />
== Scripts ==<br />
<br />
''mpv'' has a [https://github.com/mpv-player/mpv/wiki/User-Scripts large variety of scripts] that extend the functionality of the player. To this end, it has internal bindings for both Lua and JavaScript (added recently).<br />
<br />
Scripts are typically installed by putting them in the {{ic|~/.config/mpv/scripts/}} directory (you may have to create it first). After that they will be automatically loaded when mpv starts (this behavior can be altered with other ''mpv'' options). Some scripts come with their own installation and configuration instructions, so make sure to have a look. In addition some scripts are old, broken, and unmaintained.<br />
<br />
=== JavaScript ===<br />
<br />
JavaScript (ES5 via [https://mujs.com/ MuJS]) has been supported as an mpv scripting language since 2014. Currently only [https://github.com/mpv-player/mpv/wiki/User-Scripts#javascript a few scripts] are available, but [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst documentation exists] for anyone interested in making their own.<br />
<br />
To get started, drop a script with a {{ic|.js}} extension in the mpv {{ic|scripts}} directory, e.g.:<br />
<br />
{{hc|~/.config/mpv/scripts/fullscreen-off-on-pause.js|<br />
<nowiki><br />
function onPauseChange (prop, enabled) {<br />
if (enabled) {<br />
mp.set_property('fullscreen', 'no')<br />
}<br />
}<br />
<br />
mp.observe_property('pause', 'bool', onPauseChange)<br />
</nowiki><br />
}}<br />
<br />
For more details, e.g. on using {{ic|require}} to load CommonJS modules, see the [https://github.com/mpv-player/mpv/blob/master/DOCS/man/javascript.rst#commonjs-modules-and-requireid documentation].<br />
<br />
JavaScript support is available in the {{Pkg|mpv}} package, as well as some AUR packages, e.g. {{AUR|mpv-full}} and {{AUR|mpv-full-git}}.<br />
<br />
=== Lua ===<br />
<br />
There are a lot of interesting Lua scripts for mpv. If you would like to make your own, the relevant documentation may be found [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst here].<br />
<br />
==== mpv-stats ====<br />
<br />
[https://github.com/Argon-/mpv-stats/ mpv-stats] (or simply ''stats'') is a Lua script that outputs a lot of live statistics showing how well ''mpv'' is currently doing. It is very useful for making sure that your hardware can keep up with your configuration and for comparing different configurations. Since version [https://github.com/mpv-player/mpv/releases/tag/v0.28.0 v0.28.0], the script is built into {{Pkg|mpv}} and can be toggled on or off with the {{ic|i}} or {{ic|I}} keys (by default).<br />
<br />
==== mpv-webm ====<br />
<br />
[https://github.com/ekisu/mpv-webm mpv-webm] (or simply ''webm'') is a very easy to use Lua script that allows one to create WebM files while watching videos. It includes several features and does not have any extra dependencies (relies entirely on mpv).<br />
<br />
=== C ===<br />
<br />
==== mpv-mpris ====<br />
<br />
The C plugin [https://github.com/hoyon/mpv-mpris mpv-mpris] allows other applications to integrate with ''mpv'' via the [[MPRIS]] protocol. For example, with ''mpv-mpris'' installed, {{pkg|kdeconnect}} can automatically pause video playback in ''mpv'' when a phone call arrives. Another example is buttons (play\pause etc) on bluetooth audio-devices.<br />
<br />
Install {{AUR|mpv-mpris}} and follow the post-installation instructions displayed by Pacman.<br />
<br />
== Vapoursynth ==<br />
<br />
Vapoursynth is an alternative to AviSynth that can be used on Linux and allows for Video manipulation via python scripts. Vapoursynths python scripts can be used as video filters for ''mpv''.<br />
<br />
To use vapoursynth filters you have to install the {{Pkg|vapoursynth}} package (or {{AUR|vapoursynth-git}}) and compile ''mpv'' with the {{ic|--enable-vapoursynth}} build flag.<br />
<br />
This is easier to do by first installing Vapoursynth and then installing (or re-installing if it is already installed) {{AUR|mpv-git}}. The configure script for {{AUR|mpv-git}} will auto-detect Vapoursynth (as long as it has already been installed) and it will automatically compile ''mpv'' with support for Vapoursynth without having to manually change any configure options or anything (this makes it very easy to update ''mpv'' as well).<br />
<br />
=== SVP 4 Linux (SmoothVideoProject) ===<br />
<br />
[https://www.svp-team.com/wiki/Main_Page SmoothVideoProject SVP] is a program that is primarily known for converting video to 60fps. It is free [as in beer] and full featured for 64bit Linux (costs money for Windows and OS X and is incompatible with 32bit Linux).<br />
<br />
It has three main features and each one can be disabled/enabled as one chooses (you are not forced to use motion interpolation).<br />
<br />
# [https://www.svp-team.com/wiki/Manual:FRC Motion interpolation] ([https://www.youtube.com/watch?v=Wjb6CSe4708 youtube video]) - An algorithm that converts video to 60fps. This creates the somewhat controversial "soap opera effect" that some people love and others hate. Unfortunately the algorithm is not perfect and it also introduces more than its share of weird artifacts. The algorithm can be tuned (via a slider) for either performance or quality. It also has some artifact reduction settings that interpolate actual frames with the generated frames reducing the noticeability of the artifacts. The framerate detection can be set to automatic or manual (manual seems to resolve performance issues for some users).<br />
# [https://www.svp-team.com/wiki/Manual:Outer_lighting Black bar lighting] ([https://www.youtube.com/watch?v=yTzTpW3kTBE youtube video]) - If the image has an aspect ratio that produces black bars on your display then SVP will illuminate the black bars with "lights" generated by the content on the screen. It has some amount of customization but the defaults are pretty close to optimal.<br />
# [https://www.svp-team.com/wiki/Manual:SVPlight LED ambient lighting control] ([https://www.youtube.com/watch?v=UUM2n-8kIJ8 youtube video]) - Has the ability to control LED ambient lighting attached to your television.<br />
<br />
Once you have ''mpv'' compiled with Vapoursynth support it is fairly easy to get SVP working with ''mpv''. Simply install {{AUR|svp}}, open the SVP program to let it assess your system performance (you may want to close other programs first so that it gets an accurate reading), and finally add the following ''mpv'' profile to your mpv.conf[https://www.svp-team.com/wiki/SVP:mpv]:<br />
<br />
{{hc|1=mpv.conf|2=<br />
[svp]<br />
input-ipc-server=/tmp/mpvsocket # Receives input from SVP<br />
hr-seek-framedrop=no # Fixes audio desync<br />
resume-playback=no # Not compatible with SVP<br />
<br />
# Can fix stuttering in some cases, in other cases probably causes it. Try it if you experience stuttering.<br />
#opengl-early-flush=yes <br />
}}<br />
<br />
Then, in order to use SVP you must have the SVP program running in the background before opening the file using ''mpv'' with that profile. Either do:<br />
<br />
$ mpv --profile=svp video.mkv<br />
<br />
or set {{ic|1=profile=svp}} in the top-level portion of the ''mpv'' [[#Custom profiles|configuration]].<br />
<br />
If you want to use hardware decoding then you must use a copy-back decoder since normal decoders are not compatible with Vapoursynth (choose a {{ic|hwdec}} option that ends in {{ic|-copy}}). For instance:<br />
<br />
hwdec=auto-copy<br />
hwdec-codecs=all<br />
<br />
Either way, hardware decoding is discouraged by ''mpv'' developers and is not likely to make a significant difference in performance.<br />
<br />
== Tips and Tricks ==<br />
<br />
=== Hardware video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
Hardware accelerated video decoding is available via {{ic|1=--hwdec=''API''}} option. For list of all supported APIs and other required options see [https://mpv.io/manual/stable/#options-hwdec relevant manual section].<br />
<br />
For [[Wayland]] use {{ic|1=--gpu-context=wayland}} option. For list of other available GPU APIs see [https://mpv.io/manual/stable/#options-gpu-context manual].<br />
<br />
=== Save position on quit ===<br />
<br />
By default you can save the position and quit by pressing {{ic|Shift+q}}. The shortcut can be changed by setting {{ic|quit_watch_later}} in the key bindings configuration file.<br />
<br />
To automatically save the current playback position on quit, start ''mpv'' with {{ic|--save-position-on-quit}}, or add {{ic|save-position-on-quit}} to the configuration file.<br />
<br />
=== Volume is too low ===<br />
<br />
Set {{ic|1=volume-max=''value''}} in your configuration file to a reasonable amount, such as {{ic|1=volume-max=150}}, which then allows you to increase your volume up to 150%, which is more than twice as loud. Increasing your volume too high will result in clipping artefacts. Additionally (or alternatively), you can utilize [[Wikipedia:Dynamic range compression|dynamic range compression]] with {{ic|1=af=acompressor}}.<br />
<br />
=== Volume normalization ===<br />
<br />
Different sources may have different loudness, so {{ic|mpv}} users may need automatically volume normalization. Example:<br />
<br />
{{hc|~/.config/mpv/input.conf|<nowiki><br />
n cycle_values af lavfi=[loudnorm=I=-30] lavfi=[loudnorm=I=-15] anull<br />
<br />
## n : bind to 'n' key<br />
## cycle_values : set value in one of predefined values<br />
## af : audio filter settings<br />
## lavfi=[loudnorm=I=-30] : loudnorm setting with I=-30, soft volume, may suitable for background music<br />
## lavfi=[loudnorm=I=-15] : louder volume, might good for currently viewing video<br />
## anull : reset audio filter to null, namely, disable audio filter<br />
</nowiki>}}<br />
<br />
Audio filtering in mpv is provided by [[ffmpeg]]; ref.: [[Wikipedia:EBU R 128|EBU R128 of loudnorm]], [https://ffmpeg.org/ffmpeg-filters.html#loudnorm ffmpeg filters]<br />
<br />
=== Play a DVD ===<br />
<br />
mpv does not support DVD menus. To start the main stream with the longest title of a video DVD, use the command:<br />
<br />
$ mpv dvd://<br />
<br />
An optional title specifier is a number (starting at 0) which selects between separate video streams on the DVD:<br />
<br />
$ mpv dvd://[title] <br />
<br />
DVDs which have been copied on to a local file system (by e.g. the [[dvdbackup]] tool) are accommodated by specifying the path to the local copy: {{ic|1=--dvd-device=''PATH''}}.<br />
<br />
See the following [[desktop file]] example for playing DVDs from a local file system:<br />
<br />
[Desktop Entry]<br />
Type=Application<br />
Name=mpv Media Player DVD <br />
GenericName=Multimedia player<br />
Comment=Play movies and songs<br />
Icon=mpv<br />
Exec=mpv dvd:// --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
Terminal=false<br />
Categories=AudioVideo;Audio;Video;Player;TV;<br />
# (MimeType and X-KDE-Protocols omitted, see orginianl mpv.desktop file)<br />
<br />
By replacing the Exec line with<br />
<br />
Exec=mpv dvd://0 dvd://1 dvd://2 dvd://3 dvd://4 dvd://5 dvd://6 dvd://7 dvd://8 dvd://9 --player-operation-mode=pseudo-gui --force-window --idle --dvd-device=%f<br />
<br />
the mpv player will queue DVD title 0 to 9 in the playlist, which allows the user to play the titles consecutively or jump forward and backward in the DVD titles with the mpv GUI.<br />
<br />
Install {{Pkg|libdvdcss}}, to fix the error:<br />
<br />
[dvdnav] Error getting next block from DVD 1 (Error reading from DVD.)<br />
<br />
=== Quickly cycle between aspect ratios ===<br />
<br />
You can cycle between aspect ratios using {{ic|Shift+a}}.<br />
<br />
=== Ignoring aspect ratio ===<br />
<br />
You can ignore aspect ratio using {{ic|1=--keepaspect=''no''}}. To make option permanent, add line {{ic|1=keepaspect=''no''}} to configuration file.<br />
<br />
=== Draw to the root window ===<br />
<br />
Run ''mpv'' with {{ic|1=--wid=0}}. ''mpv'' will draw to the window with a window ID of 0.<br />
<br />
=== Always show application window ===<br />
<br />
To show application window even for audio files when launching mpv from command line use {{ic|--force-window}} option. To make option permament, add line {{ic|1=force-window=yes}} to the configuration file.<br />
<br />
=== Disable video output ===<br />
<br />
To disable video output when launching from command line use {{ic|1=--vid=no}} option, or its alias, {{ic|--no-video}}.<br />
<br />
=== Restoring old OSC ===<br />
<br />
Since version 0.21.0, ''mpv'' has replaced the on-screen controls by a bottombar. In case you want on-screen controls back, you can edit the ''mpv'' configuration [https://github.com/mpv-player/mpv/wiki/FAQ#i-want-the-old-osc-back as described here].<br />
<br />
=== Use as a browser plugin ===<br />
<br />
With the help of {{AUR|mozplugger}}, ''mpv'' can be used in a supported browser to play video. See [[Browser plugins#MozPlugger]] for configuration details. This coupled with a user script such as [http://isebaro.com/viewtube/?ln=en ViewTube], allows you to use ''mpv'' in place of a site's integrated video player.<br />
<br />
It may be needed to specify a valid user agent for HTTP streaming, e.g. {{ic|1=user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"}}.<br />
<br />
[[Browser plugins#Multimedia playback]] page shows other easy ways to watch videos.<br />
<br />
=== Improving mpv as a music player with Lua scripts ===<br />
<br />
The development of ''mpv'''s Lua scripts are documented in [https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst DOCS/man/lua.rst]<br />
and examples are shown in [https://github.com/mpv-player/mpv/tree/master/TOOLS/lua TOOLS/lua]<br />
of the [https://github.com/mpv-player/mpv mpv repository].<br />
[https://web.archive.org/web/20160320001546/http://bamos.github.io/2014/07/05/mpv-lua-scripting/ This blog post] introduces the<br />
[https://github.com/bamos/dotfiles/blob/master/.mpv/scripts.old/music.lua music.lua] script,<br />
which shows how Lua scripts can be used to improve ''mpv'' as a music player.<br />
<br />
=== Twitch.tv streaming over mpv ===<br />
<br />
If [[youtube-dl]] is installed, ''mpv'' can directly open a Twitch livestream.<br />
<br />
Alternatively, see [[Streamlink#Twitch]].<br />
<br />
Another alternative based on Livestreamer is this Lua script: https://gist.github.com/ChrisK2/8701184fe3ea7701c9cc<br />
<br />
=== youtube-dl and choosing formats ===<br />
<br />
The default {{ic|--ytdl-format}} is {{ic|bestvideo+bestaudio/best}}. For youtube videos that have 4K resolutions available, this may mean that your device will struggle to decode 4K VP9 encoded video in software even if the attached monitor is much lower resolution.<br />
<br />
Setting the right youtube-dl format selectors can fix this easily though. In the following configuration example, only videos with a vertical resolution of 1080 pixels or less will be considered.<br />
<br />
ytdl-format="bestvideo[height<=?1080]+bestaudio/best"<br />
<br />
If you wish to avoid a certain codec altogether because you cannot hardware-decode it, you can add this to the format selector. For example, we can additionally choose to ignore VP9 as follows:<br />
<br />
ytdl-format="bestvideo[height<=?1080][vcodec!=vp9]+bestaudio/best"<br />
<br />
If you prefer best quality open codecs (VP9 and Opus), use:<br />
ytdl-format="((bestvideo[vcodec^=vp9]/bestvideo)+(bestaudio[acodec=opus]/bestaudio[acodec=vorbis]/bestaudio[acodec=aac]/bestaudio))/best"<br />
<br />
=== youtube-dl audio with search ===<br />
<br />
To find and stream audio from your terminal emulator with {{ic|yta ''search terms''}} put the following function in your {{ic|.bashrc}}:<br />
<br />
function yta() {<br />
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$*"<br />
}<br />
<br />
=== Creating a single screenshot ===<br />
An example of creating a single screenshot, by using a start time ({{ic|HH:MM:SS}}):<br />
<br />
$ mpv --no-audio --start=00:01:30 --frames=1 /path/to/video/file --o=/path/to/screenshot.png<br />
<br />
Screenshots will be saved in /path/to/screenshot.png.<br />
<br />
== Troubleshooting ==<br />
<br />
=== General debugging ===<br />
<br />
If you are having trouble with ''mpv'''s playback (or if it is flat out failing to run) then the first three things you should do are:<br />
<br />
# Run ''mpv'' from the command line (the -v flag increases verbosity). If you are lucky there will be an error message there telling you what is wrong.<br>{{ic|$ mpv -v video.mkv}}<br />
# Have ''mpv'' output a log file. The log file might be difficult to sift through but if something is broken you might see it there.<br>{{ic|1=$ mpv -v --log-file=./log video.mkv}}<br />
# Run ''mpv'' without a configuration. If this runs well then the problem is somewhere in your configuration (perhaps your hardware cannot keep up with your settings).<br>{{ic|$ mpv --no-config video.mkv}}<br />
<br />
If ''mpv'' runs but it just does not run well then a fourth thing that might be worth taking a look at is installing the [[#mpv-stats|mpv-stats]] script and using it to see exactly how it is performing.<br />
<br />
=== Fix jerky playback and tearing ===<br />
<br />
''mpv'' defaults to using the OpenGL video output device setting on hardware that supports it. In cases such as trying to play video back on a 4K display using a Intel HD4XXX series card or similar, you will find video playback unreliable, jerky to the point of stopping entirely at times and with major tearing when using any OpenGL output setting. If you experience any of these issues, using the XV ([[Xorg]] only) video output device may help:<br />
<br />
{{hc|1=~/.config/mpv/mpv.conf|2=<br />
vo=xv<br />
}}<br />
<br />
{{Note|This is the most compatible VO on X, but may be low-quality, and has issues with OSD and subtitle display.}}<br />
<br />
It is possible to increase playback performance even more (especially on lower hardware), but this decreases the video quality dramatically in most cases.<br />
<br />
The following [[#Configuration|options]] may be considered to increase the video playback performance:<br />
<br />
{{hc|~/.config/mpv/mpv.conf|2=<br />
vd-lavc-fast<br />
vd-lavc-skiploopfilter=<skipvalue><br />
vd-lavc-skipframe=<skipvalue><br />
vd-lavc-framedrop=<skipvalue><br />
vd-lavc-threads=<threads><br />
}}<br />
<br />
=== Problems with window compositors ===<br />
<br />
Window compositors such as KWin or Mutter can cause trouble for playback smoothness. In such cases, it may help to set {{ic|1=x11-bypass-compositor=yes}} to make ''mpv'' also disable window compositing when playing in windowed mode (if supported by the compositor).<br />
<br />
With KWin compositing and hardware decoding, you may also want to set {{ic|1=x11-bypass-compositor=no}} to keep compositing enabled in fullscreen, since reanabling compositing after leaving fullscreen may introduce stutter for a period of time.<br />
<br />
=== No volume bar, cannot change volume ===<br />
<br />
Spin the mouse wheel over the volume icon.<br />
<br />
=== GNOME Blank screen (Wayland) ===<br />
<br />
''mpv'' may not suspend GNOME's Power Saving Settings if using Wayland resulting in screen saver turning off the monitor during video playback. A workaround is to add {{ic|gnome-session-inhibit}} to the beginning of the {{ic|1=Exec=}} line in {{ic|mpv.desktop}}.<br />
<br />
=== Use mpv with a compositor ===<br />
<br />
If you are using a compositor (e.g. in KDE Plasma 5) and find that composition is disabled (e.g. in Plasma this would make you unable to present windows or see window thumbnails in the default app switcher) when ''mpv'' is playing a video, try {{ic|1=x11-bypass-compositor=no}}<br />
<br />
=== Cursor theme not respected under GNOME Wayland ===<br />
<br />
On Wayland, clients can display different cursor themes because there is not a unique configuration file for it. For the cursor theme, Qt apps usually accept the value that is set for the [[environment variable]] {{ic|XCURSOR_THEME}}. However, in the specific case of mpv, the cursor theme that is displayed needs to be the one set in {{ic|~/.icons/default/index.theme}}. Since GNOME does not update this file when changing the cursor theme with GNOME Tweaks, you will have to do it manually. See [[Cursor themes#XDG specification]] for more information.</div>Triplchttps://wiki.archlinux.org/index.php?title=JFS&diff=509472JFS2018-02-03T12:03:05Z<p>Triplc: "tar --one" produce error</p>
<hr />
<div>[[Category:File systems]]<br />
[[ja:JFS]]<br />
[[ru:JFS]]<br />
{{Related articles start}}<br />
{{Related|File systems}}<br />
{{Related articles end}}<br />
<br />
This article introduces the reader to the JFS file system. In particular, procedures for implementation, maintenance and optimization will be presented along with background information on the file system itself and some cautionary notes on precarious implementations.<br />
<br />
== Background ==<br />
<br />
The Journaled File System (JFS) is a [[wikipedia:Journaling_file_system|journaling file system]] that was open-sourced by IBM in 1999 and support for which has been available in the Linux kernel since 2002. <br />
<br />
* In 1990, JFS1, (then simply called JFS), was released for AIX version 3.1. The filesystem was closely tied to its targeted hardware, IBM's AIX line of UNIX servers, being a proprietary design. <br />
* In 1995, heavy development began on improving JFS, focusing on scalability and expanded features. <br />
* In 1997, parallel development began on moving the improved JFS source back to AIX. <br />
* In 1999, the improved JFS design was released for OS/2.<br />
* In 2001, the improved filesystem (newly termed JFS2), was released for AIX 5L. <br />
* The current GNU/Linux version is a port based on JFS for OS/2.<br />
<br />
{{Note|1=While there are potential issues, JFS file systems for OS/2 and GNU/Linux are inter-operable.[http://72.14.253.104/search?q=cache:xrFItCW2XdUJ:osdir.com/ml/file-systems.jfs.general/2006-02/msg00008.html+jfs+os/2+linux&hl=en&ct=clnk&cd=1&gl=au&client=firefox-a].}}<br />
<br />
While it is difficult to make general comparisons between JFS and other file systems available on UNIX and UNIX-like operating systems, it is claimed that JFS uses less CPU resources than other GNU/Linux file systems [http://www.debian-administration.org/articles/388]. With certain optimizations, JFS has also been claimed to be faster for certain file operations, as compared to other GNU/Linux file systems (see [http://www.redhat.com/archives/ext3-users/2005-July/msg00018.html],[[#Benchmarks|Benchmarks]]). <br />
<br />
=== GNU/Linux development team ===<br />
<br />
The development of the GNU/Linux JFS port is headed by<br />
* Dave Kleikamp (dave dot kleikamp at oracle dot com)<br />
* HP: http://jfs.sourceforge.net/<br />
<br />
=== Technical features ===<br />
<br />
JFS is a modern file system supporting many features, a few of which are listed here.<br />
* fully 64-bit.<br />
* dynamic space allocation for i-nodes, i.e. no running out of i-nodes on file systems with large number of small files.<br />
* Directory structures designed for speed and efficiency:<br />
:- directories with eight or fewer entries have their contents storied inline within that directory's i-node.<br />
:- directories with more than eight entries have their contents stored in a [[wikipedia:B+ tree|B+ tree]] keyed on name.<br />
* JFS utilizes extents for allocating blocks for large files.<br />
* Support for extended attributes in addition to standard Unix-style permissions.<br />
* Support for both internal and external logs ([[#External journal|see below]]).<br />
* Extremely Scalable; Consistent performance from minimum file size up to 4 petabytes.<br />
* Algorithms designed for high performance on very large systems.<br />
* Performance tuned for GNU/Linux.<br />
* Designed from the ground up to provide Transaction/Log (not an add-on).<br />
* Restarts after a system failure < 1 sec.<br />
* Proven Journaling FS technology (10+ years in AIX).<br />
* Original design goals: Performance, Robustness, SMP.<br />
* Team members from the original AIX JFS Designed/Developed this file system.<br />
* Designed to operate on SMP hardware, with code optimized for at least a 4-way SMP machine.<br />
* TRIM support (since Kernel 3.7).<br />
<br />
{{Note|JFS uses a journal to maintain consistency of metadata ''only''. Thus, only consistency of metadata (and not actual file contents) can be assured in the case of improper shutdown. This is also the case for XFS and ReiserFS. Ext3, on the other hand, does support journaling of ''both'' metadata and data [http://www.thehackademy.net/madchat/ebooks/FileSystem/up2-6Galli.pdf], though with a significant performance penalty, and not by default.}}<br />
<br />
A more comprehensive (and technical) overview of the features in JFS can be found in the [http://jfs.sourceforge.net/project/pub/jfs.pdf JFS Overview] authored by developer Steve Best.<br />
<br />
== Implementing on GNU/Linux ==<br />
<br />
Implementing a JFS file system is just like implementing most other file systems under GNU/Linux. JFS was merged into the Linux kernel as of version 2.4 [http://kerneltrap.org/node/385]. The JFS driver is built as a module in the standard Arch kernel packages. If building a custom kernel on a machine that will be (or does) use JFS file systems, be sure to enable JFS in your kernel config:<br />
<br />
File systems<br />
---> [*/M] JFS filesystem support<br />
<br />
If extended attributes are desired, one will also need to enable "JFS POSIX Access Control Lists" and/or "JFS Security Labels"<br />
<br />
File systems<br />
---> [*/M] JFS filesystem support <br />
---> [*] JFS POSIX Access Control Lists<br />
---> [*] JFS Security Labels<br />
<br />
Next, the {{Pkg|jfsutils}} package will be needed to perform all file system related tasks.<br />
<br />
Actual creation of a JFS file system can be done with the either:<br />
<br />
# mkfs.jfs /dev/target_dev<br />
<br />
or:<br />
<br />
# jfs_mkfs /dev/target_dev<br />
<br />
Both commands are equivalent.<br />
<br />
== Optimizations ==<br />
<br />
There are several concepts that can be implemented with a JFS filesystem to boost its performance:<br />
* Periodic defragmentation of the file system.<br />
* Using the deadline I/O scheduler.<br />
* Utilizing an external journal.<br />
* Attaching the ''noatime'' attribute the the file system in {{ic|/etc/fstab}}.<br />
<br />
=== Defragmenting JFS ===<br />
<br />
JFS, like all file systems, will degrade in performance over time due to file fragmentation [http://docs.hp.com/en/5576/JFS_Tuning.pdf]. While there is in-place defragmentation code in the JFS utilities, this is code held over from the OS/2 port and has yet to be implemented [http://www.mail-archive.com/jfs-discussion@lists.sourceforge.net/msg00573.html]. For file systems that can be taken off-line for a time, one can execute a script like the following to defragment their JFS file system<br />
<br />
{{Warning|This script is '''dangerous''' and may result in the wiping of an entire hard disk, if arguments get switched! Doing this type of operation is only recommended for people who have confidence in doing backups and file system operations.}}<br />
<br />
umount /dev/hdc1<br />
dd bs=4k if=/dev/hdc1 of=/dev/hdj1<br />
jfs_fsck /dev/hdj1<br />
mount -o ro /dev/hdj1 /fs/hdj1<br />
jfs_mkfs /dev/hdc1<br />
mount -o rw /dev/hdc1 /fs/hdc1<br />
(cd /fs/hdj1 && tar -cS -b8 --one-file-system -f - .) | (cd /fs/hdc1 && tar -xS -b8 -p -f -)<br />
umount /dev/hdj1<br />
<br />
In this example, {{ic|/dev/hdc1}} is the device with the data that needs backing up and {{ic|/dev/hdj1}} is the device that holds the backup. <br />
<br />
Basically, this script copies the data off the JFS file system to a backup drive, formats the original JFS file system and finally writes back the data from the backup to the freshly formatted drive in a way that JFS will write its allocation trees in a defragmentated way.<br />
<br />
{{Warning|If a VMWare session is sitting on an underlying JFS partition that is highly fragmented, performance of the virtual machine may be significantly degraded.}}<br />
<br />
=== Deadline I/O scheduler===<br />
<br />
JFS seems to perform better when the kernel has been configured to use the ''Deadline I/O Scheduler''. Indeed, JFS's performance seems to exceed that of other GNU/Linux file systems with this particular scheduler being employed [http://www.redhat.com/archives/ext3-users/2005-July/msg00018.html]. There are several ways to utilize this scheduler. One is to recompile with the Deadline I/O scheduler set to the default:<br />
<br />
Block layer<br />
---> I/O Schedulers<br />
---> [*] Deadline I/O scheduler<br />
---> Default I/O scheduler (Deadline) ---><br />
<br />
If you are using a generic Arch package for your kernel, you can simply append ''elevator=deadline'' to the kernel line commandline or permenantly to kernel line in your ''/etc/default/grub'' and run ''grub-mkconfig -o /boot/grub/grub.cfg''. The kernel entry would look something like:<br />
<br />
# (0) Arch 2.6.22<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda3 elevator=deadline<br />
initrd /initramfs-linux.img<br />
<br />
It is also possible to enable the Deadline I/O scheduler for specific devices by invoking the following command:<br />
<br />
echo deadline > /sys/block/sda/queue/scheduler <br />
<br />
This sets the Deadline scheduler as the default for {{ic|/dev/sda}} (the entire physical device).<br />
<br />
=== External journal ===<br />
<br />
{{Warning|As this is a relatively new feature to the GNU/Linux port of JFS, it is recommended to upgrade to the very latest version of jfsutils before attempting to implement an external journal (earlier versions seem to give errors when trying to create the journal device).}}<br />
<br />
As with any journaled file system, a journal is constantly accessed in accordance with disk activity. Having the journal log on the same device as the its corresponding file system thus can cause a degradation in I/O throughput. This degradation can be alleviated by putting the journal log on a separate device all together. <br />
<br />
To make a journal device, first create a partition that is 128MB. Using a partition that is bigger than 128MB results in the excess being ignored, according to mkfs.jfs. You can either create an external log for an already-existing JFS file system by executing the following:<br />
<br />
# mkfs.jfs -J journal_dev /dev/external_journal # creates a journal on device /dev/external_journal<br />
# mkfs.jfs -J device=/dev/external_journal /dev/jfs_device # attaches the external journal to the existing file <br />
# system on /dev/jfs_device<br />
<br />
or a command can be issued to create both a new external journal and its corresponding JFS file system:<br />
<br />
# mkfs.jfs -j /dev/external_journal /dev/jfs_device<br />
<br />
This last command formats BOTH the external journal and the JFS file system.<br />
<br />
{{Note|Obviously, an external journal is only effective if the journal and its file system exists on separate ''physical'' devices.}}<br />
<br />
=== noatime fstab attribute ===<br />
<br />
Every time a file is accessed (read or write) the default for most file systems is to append the metadata associated with that file with an updated access time. Thus, even read operations incur an overhead associated with a write to the file system. This can lead to a significant degradation in performance in some usage scenarios. Appending ''noatime'' to the fstab line for a JFS file system stops this action from happening. As access time is of little importance in most scenarios, this alteration has been widely touted as a fast and easy way to get a performance boost out of one's hardware. Even Linus Torvalds seems to be a proponent of this optimization [http://kerneltrap.org/node/14148].<br />
<br />
{{Note|<br />
* One may also specify a '''relatime''' option which updates the atime if the previous atime is older than the mtime or ctime [http://kerneltrap.org/node/14148]. In terms of performance, this will not be as fast as the ''noatime'' mount option, but is useful if using applications that need to know when files were last read (like ''mutt'').<br />
* Using the ''noatime/relatime'' option can improve disk performance with any file system, not just JFS.<br />
}}<br />
<br />
Here is an example {{ic|/etc/fstab}} entry with the '''noatime''' tag:<br />
<br />
/dev/sdb1 /media/backup jfs rw,users,noauto,noatime 0 0<br />
<br />
One may also mount a file system with the '''noatime''' attribute by invoking something similar to the following:<br />
<br />
# mount -o noatime -t jfs /dev/jfs_dev /mnt/jfs_fs<br />
<br />
{{Note|Access time is NOT the same as the ''last-modified'' time. Disabling access time will still enable you to see when files were last modified by a write operation.}}<br />
<br />
=== Journal modes ===<br />
<br />
JFS does not support various journal modes like [[ext3]]. Thus, passing the mount option ''data=writeback'' with ''mount'' or in {{ic|/etc/fstab}} will have no effect on a JFS file system. JFS's current journaling mode is similar to Ext3's default journaling mode: ''ordered'' [http://www.ibm.com/developerworks/linux/linux390/perf/tuning_res_journaling.html].<br />
<br />
=== Variable block sizes ===<br />
<br />
While the OS/2 port of JFS supports block sizes of 512, 1024, 2048, and 4096 bytes, the Linux port of JFS is only able to use 4k blocks. Even though code exists in JFS utilities that correspond to file systems using variable size blocks, this has yet to be implemented [http://osdir.com/ml/file-systems.jfs.general/2003-02/msg00017.html]. As larger block sizes tend to favor performance (smaller ones favor efficient space usage), implementing smaller block sizes for JFS in Linux has been given a low priority for implementation by JFS developers.<br />
<br />
== fsck and recovery ==<br />
<br />
In the event that the file system does not get properly unmounted before being powered down, one will usually have to run '''fsck''' on a JFS file system in order to be able to remount it. This procedure usually only takes a few seconds, unless the log has been damaged. If running fsck returns an unrecognized file system error, try running '''fsck.jfs''' on the target device. Normally, ''fsck'' is all that is needed.<br />
<br />
If the superblock on your file system gets destroyed, it may be possible to recover some parts of the file system. Currently, the only tool able to do this is a utility called '''jfsrec'''. JFSrec is currently available from the AUR using the {{AUR|jfsrec-svn}} package.<br />
<br />
There is also an AUR package called ''jfsrec'', but this is merely a placeholder for ''jfsrec-svn'' as JFSrec is currently only in its seventh SVN revision. Once installed, one simply need to type:<br />
<br />
# jfsrec<br />
<br />
to get a help menu explaining how to use this utility. <br />
<br />
{{Warning|As stated above, JFSrec is only in its seventh SVN revision; and it is not known how actively the project is maintained. So use JFSrec with caution.}}<br />
<br />
== Cautionary notes ==<br />
<br />
While JFS is very stable in its current stage of development, there are some cautionary notes on using this file system.<br />
<br />
=== JFS root mounts read only on startup ===<br />
<br />
Occasionally, a JFS root partition will be unable to mount in normal read-write mode. This is usually due to the fact that the JFS root file system fails its fsck after an unclean shutdown. It is rare that JFS fails out of fsck, and it's usually due to the JFS log itself being corrupted.<br />
<br />
All that is required in this scenario is to boot your machine with a relatively recent Arch Linux LiveCD. Booting an Arch Linux livecd will give you access to all the JFS utilities and will load a kernel that is able to recognize JFS file systems. After booting the CD simply run ''fsck'' (or possibly ''fsck.jfs'') on your JFS root and it should recover just fine (even though the fsck will probably take longer than normal due to the log probably being damaged). Once the ''fsck'' finishes, you should be able to boot your machine like normal.<br />
<br />
{{Note|This scenario happens less than 10% of the time in the case of an improper shutdown.}}<br />
<br />
=== JFS and secure deletions ===<br />
<br />
{{Note|This section applies to any journaled file system, not just JFS.}}<br />
<br />
The effectiveness of deleting files by overwriting their corresponding file system blocks with random data (i.e. using utilities like ''shred'') can not be assured [http://lists.kde.org/?l=kfm-devel&m=105770965822522&w=2]. Given the design of journaled file systems, maintenance issues, and performance liabilities; reliable shredding of files as a deletion method does not sit highly on the priority list for implementation on any journaled file system.<br />
<br />
=== Forced fsck on JFS root file system ===<br />
<br />
One may force a fsck file system check on the root file system by entering:<br />
touch /forcefsck<br />
and rebooting. On Arch linux systems with a JFS root on a partition under control of ''device-mapper'' (i.e. the root device is a ''lvm'' or a LUKS encrypted one), forcing an fsck can sometimes remove the ''/usr/man/man3'' directory. The reason for this issue is not clear, but the problem has been able to be replicated [https://bbs.archlinux.org/viewtopic.php?id=41261]. <br />
<br />
It is suggested to get a list of Arch Packages that use {{ic|/usr/man/man3}} by issuing a command similar to<br />
find /var/lib/pacman/local/ -name files | xargs fgrep /man/man3/ | cut -d: -f1 | sort -u | awk -F/ '{print $6}' > man3_pkg_list<br />
before attempting a forced fsck on a JFS root partition ([https://bbs.archlinux.org/viewtopic.php?id=41261] post #1). If {{ic|/usr/man/man3}} does indeed disappear, simply reinstall all the packages listed in ''man3_pkg_list''.<br />
<br />
{{Note|1=If this problem does indeed happen, reinstalling all the packages using ''/usr/man/man3'' does appear to fix the issue ([https://bbs.archlinux.org/viewtopic.php?id=41261] post #4).}}<br />
<br />
As stated above, the reason for this issue isn't clear at the moment; but it may have something to do with the fact that a forced fsck runs through higher phases of file system checks that only happen when a JFS log gets damaged in an improper dismounting of the partition.<br />
<br />
=== JFS losing files ===<br />
<br />
In JFS; journal writes are indefinitely postponed until there is another trigger such as memory pressure or an unmount operation. This infinite write delay limits reliability, as a crash can result in data loss even for data that was written minutes or hours before.[https://www.usenix.org/events/usenix05/tech/general/full_papers/prabhakaran/prabhakaran.pdf]<br />
<br />
== Benchmarks ==<br />
<br />
As benchmarks measuring file system performance tend to be focused at specific types of disk usage, it is difficult to decipher good general comparisons rating how well JFS performs against other files systems. As mentioned before, it has been noted that JFS has a tendency to use less CPU resources than other GNU/Linux file systems and (with the right optimizations) is faster than other GNU/Linux file systems for certain types of file operations. It has been noted that JFS slows down when working with many files, however[http://fsbench.netnation.com/][http://www.debian-administration.org/articles/388]. In the references are some links to benchmarks; but as always, it is best to test and see what works best for your own system and work load.<br />
<br />
== Conclusions ==<br />
<br />
JFS is a stable, feature-rich file system that hasn't been publicized as much as some of the other Linux file systems. With optimizations, JFS is stable, CPU efficient and fast. In particular, VMWare sessions stand to benefit enormously from a properly optimized and defragmented, underlying JFS file system.<br />
<br />
== See also ==<br />
<br />
* A more technical [http://jfs.sourceforge.net/project/pub/jfs.pdf overview] of JFS<br />
* [http://www.linux.com/feature/119025 30 days with JFS]<br />
* JFS [http://jfs.sourceforge.net/ Sourceforge] page<br />
* Note on [http://www.sabi.co.uk/blog/anno06-2nd.html#060422b defragmenting] JFS file systems<br />
* JFS Recovery [http://sourceforge.net/projects/jfsrec Sourceforge] page<br />
* [http://conferences.oreillynet.com/presentations/os2002/best_steve.pdf Presentation] on JFS given by Steve Best (pdf)<br />
* [http://www.debian-administration.org/articles/388 Debian file system comparison]<br />
* [[Wikipedia:JFS (file system)]]<br />
* Some [http://fsbench.netnation.com/ filesystem benchmarks]</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:JFS&diff=493480Talk:JFS2017-10-18T04:33:58Z<p>Triplc: add comment</p>
<hr />
<div>I have left out two points from the JFS wiki article:<br />
<br />
# Changing of virtual memory parameters to optimize file system access.<br />
# Claims of JFS 'losing' files.<br />
<br />
The reason that I have not included ways to optimize VM parameters is due to the fact that the JFS port itself has been optimized for the Linux kernel using default values for parameters like /proc/sys/vm/swappiness. Also, changing these parameters can adversely affect certain programs and machines with certain work loads. If people really want to know how to do this type of thing, I'll consider writing up a separate wiki article on that type of optimization for file systems.<br />
<br />
As for claims made about JFS loosing files, I have never experienced in the time I've been using JFS; and I am unable to find sources detailing this problem beyond that of hearsay in forum posts. My personal feeling is that these claims of JFS loosing files are probably the result of a badly written script, backup process or careless command execution. Personally, I have had files 'go missing' on me a few times only to realize that I had done something to erase them. This seems far more likely an explanation than JFS just up-and-remove files at random without the file system itself being damaged in some way. If someone does indeed have this problem, send me an email outlining all the details surrounding the lose and I will see about trying to replicate the problem. <br />
<br />
I have also seen a claim of JFS 'ruining' an 'expensive' hard drive with very valuable data. This person went on to say how he got a quote that said it would be 30k to recover the data, but that it was too expensive, etc. etc. I don't believe this story. How come this data wasn't backed up if it was so extremely valuable? I have accidentally deleted a JFS partition and I was still able to recover much of the data from that drive using jfsrec. Anyway, I am hoping these claims don't work their way into this JFS article without some proper citations to actual file systems tests whose results can be replicated.<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Regarding point two: [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing]<br />
Feel free to ask me for anything else that I didn't think of when posting that.<br />
:--[[User:Byte|byte]]<br />
<br />
<hr><br />
Byte, thanks for bringing that to my attention; I have noted the issue in the JFS article. However, as I noted in [https://bbs.archlinux.org/viewtopic.php?id=41261 JFS users needed for testing] this may very well be a problem due to the device mapper subsystem or a faulty package install. I was able to replicate the problem only on a system using the device mapper, and the issue was fixed by reinstalling all the packages that used the man3 directory. Anyway, thanks again for posting the details so that the problem could be replicated :).<br />
:--[[User:PDExperiment626|PDExperiment626]]<br />
<br />
<hr><br />
Shouldn't nodiratime be included with the noatime tip? Admittedly, it doesn't give as much of a performance increase as noatime, but, depending on what you're doing, it CAN still be a substantial enhancement.<br />
<br />
Also, what exactly do you mean by "more testers"? People to purposefully crash systems? I have also been using JFS on everything but /boot (and one oddball partition) for a few months now (3 large standalone partitions, and 4 in an LVM), have had a number of crashes, and, to my knowledge, at least, have never lost anything whatsoever.<br />
:--[[User:Grndrush|Grndrush]] 16:06, 25 March 2008 (EDT)<br />
<br />
== Link 7 ==<br />
<br />
Are we sure link 7 is relevent? According to: http://en.wikipedia.org/wiki/JFS_(file_system) HP-UX has another, different filesystem named JFS that is actually an OEM version of Veritas Software's VxFS. I think link 7 may be refering to the wrong JFS.<br />
<br />
== nodiratime ==<br />
<br />
Grndrush: enabling noatime also enables nodiratime.<br />
<br />
== JFS losing files. ==<br />
<br />
I've found some evidence of JFS losing files: https://www.usenix.org/events/usenix05/tech/general/full_papers/prabhakaran/prabhakaran.pdf<br />
<br />
Read the section on JFS from page 14 to 15.<br />
<br />
== JFS losing files. ==<br />
<br />
I've reproduced the incident of JFS losing files as described in that pdf, and have edited the wiki accordingly.<br />
<br />
== CPU Usage ==<br />
<br />
I have experienced much less CPU usage and faster reads with ext4 and the default I/O scheduler, than with JFS and the deadline I/O scheduler. I feel the claim that JFS uses less CPU may be slightly exaggerated, however I am hesitant to edit the Wiki based on my results alone. I have also had some problems with losing files.<br />
<br />
I have edited the Wiki to include it's noted slowdown when working with many files, as this is verified by at least two sources, one of which is in the references section. I added one more reference as well.<br />
<br />
== CPU Usage ==<br />
<br />
I use JFS for years and strongly believe that JFS use much less CPU, especially after long years usage. For SSD disks, the fragmented files are nolonger issue. I have not experienced file lost.<br />
<br />
:[[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 04:33, 18 October 2017 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Xmodmap&diff=472147Xmodmap2017-03-29T01:24:22Z<p>Triplc: </p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Keyboards]]<br />
[[Category:X server]]<br />
[[de:Xmodmap]]<br />
[[fr:Xmodmap]]<br />
[[ja:Xmodmap]]<br />
[[ru:Xmodmap]]<br />
[[zh-hans:Xmodmap]]<br />
{{Related articles start}}<br />
{{Related|Xorg}}<br />
{{Related|Extra keyboard keys}}<br />
{{Related|Extra keyboard keys in Xorg}}<br />
{{Related|Extra keyboard keys in console}}<br />
{{Related|Xbindkeys}}<br />
{{Related articles end}}<br />
<br />
''xmodmap'' is a utility for modifying keymaps and pointer button mappings in [[Xorg]].<br />
<br />
''xmodmap'' is not directly related to [[X KeyBoard extension]] (XKB), as it uses different (pre-XKB) ideas on how ''keycodes'' are processed within X. Generally, it is only recommended for the simplest tasks. See [[X KeyBoard extension]] for advanced layout configuration.<br />
<br />
{{Note|''xmodmap'' settings are reset by ''setxkbmap'', which not only alters the alphanumeric keys to the values given in the map, but also resets all other keys to the startup default. [http://wiki.linuxquestions.org/wiki/Configuring_keyboards]}}<br />
<br />
== Introduction == <br />
<br />
There are two types of keyboard values in [[Xorg]]: ''keycodes'' and ''keysyms''.<br />
<br />
; keycode <br />
: The ''keycode'' is the numeric representation received by the kernel when a key or a mouse button is pressed.<br />
; keysym<br />
: The ''keysym'' is the value assigned to the ''keycode''. For example, pressing {{ic|A}} generates the {{ic|keycode 73}}, which is mapped to the {{ic|keysym 0×61}}, which matches {{ic|A}} in the [[Wikipedia:ASCII|ASCII table]].<br />
: The ''keysyms'' are managed by [[Xorg]] in a table of ''keycodes'' defining the ''keycode''-''keysym'' relations, which is called the [[#Keymap table|keymap table]]. This can be shown by running {{ic|xmodmap}}.<br />
<br />
== Installation ==<br />
<br />
''xmodmap'' can be [[pacman|installed]] through the {{Pkg|xorg-xmodmap}} package from the [[official repositories]].<br />
<br />
Optionally, install {{Pkg|xkeycaps}}, which is a graphical front-end to ''xmodmap''.<br />
<br />
== Keymap table ==<br />
<br />
Print the current keymap table formatted into expressions:<br />
<br />
{{hc|$ xmodmap -pke|2=<br />
[...]<br />
keycode 57 = n N<br />
[...]<br />
}}<br />
<br />
Each ''keycode'' is followed by the ''keysym'' it is mapped to. The above example indicates that the ''keycode'' {{ic|57}} is mapped to the lowercase {{ic|n}}, while the uppercase {{ic|N}} is mapped to ''keycode'' {{ic|57}} plus {{ic|Shift}}.<br />
<br />
Each ''keysym'' column in the table corresponds to a particular combination of modifier keys:<br />
# {{ic|Key}}<br />
# {{ic|Shift+Key}}<br />
# {{ic|mode_switch+Key}}<br />
# {{ic|mode_switch+Shift+Key}}<br />
# {{ic|AltGr+Key}}<br />
# {{ic|AltGr+Shift+Key}}<br />
<br />
Not all ''keysyms'' have to be set, but to assign only a latter ''keysym'', use the {{ic|NoSymbol}} value.<br />
<br />
To see which ''keycode'' corresponds to a key, see [[Extra keyboard keys#In Xorg]] for details on the ''xev'' utility which will output relevant keycode/keysym information about a key when you press it.<br />
<br />
{{Tip|There are predefined descriptive ''keysyms'' for multimedia keys, e.g. {{ic|XF86AudioMute}} or {{ic|XF86Mail}}. These ''keysyms'' can be found in {{ic|/usr/include/X11/XF86keysym.h}}. Many multimedia programs are designed to work with these ''keysyms'' out-of-the-box, without the need to configure any third-party application.<br />
}}<br />
<br />
Note that xmodmap is influenced by xkbd settings, so all eight keysym are available for the us(intl) xkbd layout but not for the default us (it is missing the ralt_switch symbol defined in level3). To have all 8 keysyms available you should configure the ''(intl)'' variant of the keyboard from xorg.conf or add, using us layout as an example, {{ic|setxkbmap -layout 'us(intl)'}} before calling xmodmap.<br />
<br />
== Custom table ==<br />
<br />
To create a key map (i.e. {{ic|~/.Xmodmap}}):<br />
$ xmodmap -pke > ~/.Xmodmap<br />
<br />
To test the changes:<br />
$ xmodmap ~/.Xmodmap<br />
<br />
=== Activating the custom table ===<br />
<br />
With [[GDM]], [[XDM]], [[KDM]] or [[LightDM]] there is no need to source {{ic|~/.Xmodmap}}. For [[startx]], use:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
[[ -f ~/.Xmodmap ]] && xmodmap ~/.Xmodmap<br />
</nowiki>}}<br />
<br />
Alternatively, edit the global startup script {{ic|/etc/X11/xinit/xinitrc}}.<br />
<br />
=== Test changes ===<br />
<br />
To make temporary changes:<br />
$ xmodmap -e "keycode 46 = l L l L lstroke Lstroke lstroke"<br />
$ xmodmap -e "keysym a = e E"<br />
<br />
== Modifier keys ==<br />
<br />
''xmodmap'' can also be used to override [[Wikipedia:Modifier key|modifier keys]], e.g. to swap {{ic|Control}} and {{ic|Super}} (the [[Wikipedia:Windows key|Windows keys]]).<br />
<br />
Before assignment the modifier keys need to be empty. {{ic|!}} is a comment, so only the modifiers {{ic|Control}} and {{ic|Mod4}} get cleared in the following example. Then the ''keysyms'' {{ic|Control_L}}, {{ic|Control_R}}, {{ic|Super_L}} and {{ic|Super_R}} are assigned to the opposite modifier. Assigning both left and right to the same modifier means that both keys are treated the same way.<br />
<br />
{{hc|~/.Xmodmap|2=<br />
[...]<br />
!clear Shift<br />
!clear Lock<br />
clear Control<br />
!clear Mod1<br />
!clear Mod2<br />
!clear Mod3<br />
clear Mod4<br />
!clear Mod5<br />
!add Shift = Shift_L Shift_R<br />
!add Lock = Caps_Lock<br />
add Control = Super_L Super_R<br />
!add Mod1 = Alt_L Alt_R<br />
!add Mod2 = Mode_switch<br />
!add Mod3 =<br />
add Mod4 = Control_L Control_R<br />
!add Mod5 =<br />
}}<br />
<br />
{{Note|The example assumes that the {{ic|Control_L}} and {{ic|Control_R}} keysyms were assigned to the {{ic|Control}} modifier, and {{ic|Super_L}} and {{ic|Super_R}} keysyms to the {{ic|Mod4}} modifier. If you get the following error message {{ic|X Error of failed request: BadValue (integer parameter out of range for operation)}}, you will need to adapt accordingly. Running {{ic|xmodmap}} produces a list of modifiers and keys that are assigned to them.}}<br />
<br />
The following example modifies {{ic|CapsLock}} to {{ic|Control}}, and {{ic|Shift+CapsLock}} to {{ic|CapsLock}}:<br />
{{hc|~/.Xmodmap|2=<br />
clear lock<br />
clear control<br />
add control = Caps_Lock Control_L Control_R<br />
keycode 66 = Control_L Caps_Lock NoSymbol NoSymbol<br />
}}<br />
<br />
== Reverse scrolling ==<br />
<br />
{{Merge|Mouse buttons|xmodmap is not the only way to do this.}}<br />
<br />
The [http://who-t.blogspot.com/2011/09/natural-scrolling-in-synaptics-driver.html natural scrolling] feature available in OS X Lion (mimicking smartphone or tablet scrolling) can be [https://bbs.archlinux.org/viewtopic.php?id=126258 replicated] with ''xmodmap''. Since the synaptics driver uses the buttons 4/5/6/7 for up/down/left/right scrolling, you simply need to swap the order of how the buttons are declared in {{ic|~/.Xmodmap}}:<br />
<br />
{{hc|~/.Xmodmap|2=<br />
pointer = 1 2 3 '''5 4''' 7 6 8 9 10 11 12<br />
}}<br />
<br />
Then update ''xmodmap'':<br />
$ xmodmap ~/.Xmodmap<br />
<br />
== Swapping mouse buttons ==<br />
<br />
{{Merge|Mouse buttons|xmodmap is not the only way to do this.}}<br />
<br />
The left, middle and right mouse buttons correspond to buttons 1,2 and 3 respectively in the synaptics driver. To swap left and right mouse buttons, again simply reverse the order in which they are listed in your {{ic|~/.Xmodmap}}:<br />
<br />
{{hc|~/.Xmodmap|2=<br />
pointer = '''3 2 1'''<br />
}}<br />
<br />
This should suffice for a simple mouse setup. Again, update ''xmodmap'':<br />
$ xmodmap ~/.Xmodmap<br />
<br />
== Templates ==<br />
<br />
=== Spanish === <br />
<br />
{{hc|~/.Xmodmap|<br />
keycode 24 &#61; a A aacute Aacute ae AE ae<br />
keycode 26 &#61; e E eacute Eacute EuroSign cent EuroSign<br />
keycode 30 &#61; u U uacute Uacute downarrow uparrow downarrow<br />
keycode 31 &#61; i I iacute Iacute rightarrow idotless rightarrow<br />
keycode 32 &#61; o O oacute Oacute oslash Oslash oslash<br />
keycode 57 &#61; n N ntilde Ntilde n N n<br />
keycode 58 &#61; comma question comma questiondown dead_acute dead_doubleacute dead_acute<br />
keycode 61 &#61; exclam section exclamdown section dead_belowdot dead_abovedot dead_belowdot<br />
!Maps the Mode key to the Alt key<br />
keycode 64 &#61; Mode_switch<br />
}}<br />
<br />
=== Turn CapsLock into Control ===<br />
<br />
Simplest example of changing {{ic|CapsLock}} into {{ic|Control}}.<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
clear lock<br />
clear control<br />
keycode 66 = Control_L<br />
add control = Control_L Control_R<br />
</nowiki>}}<br />
<br />
=== Turn CapsLock into Control, and LeftControl into Hyper ===<br />
<br />
Laptop users may prefer having {{ic|CapsLock}} as {{ic|Control}}. The {{ic|Left Control}} key can be used as a {{ic|Hyper}} modifier (an additional modifier for emacs or openbox or i3).<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
clear lock <br />
clear control<br />
clear mod1<br />
clear mod2<br />
clear mod3<br />
clear mod4<br />
clear mod5<br />
keycode 37 = Hyper_L<br />
keycode 66 = Control_L<br />
add control = Control_L Control_R<br />
add mod1 = Alt_L Alt_R Meta_L<br />
add mod2 = Num_Lock<br />
add mod3 = Hyper_L<br />
add mod4 = Super_L Super_R<br />
add mod5 = Mode_switch ISO_Level3_Shift<br />
</nowiki>}}<br />
<br />
=== Switch every number key N with Shift-N and vice-versa, for Croatian layout ===<br />
<br />
Should work fine for layouts similar to Croatian as well.<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
keycode 10 = exclam 1 1 exclam asciitilde dead_tilde asciitilde<br />
keycode 11 = quotedbl 2 2 quotedbl dead_caron caron dead_caron<br />
keycode 12 = numbersign 3 3 numbersign asciicircum dead_circumflex asciicircum<br />
keycode 13 = dollar 4 4 dollar dead_breve breve dead_breve<br />
keycode 14 = percent 5 5 percent degree dead_abovering degree<br />
keycode 15 = ampersand 6 6 ampersand dead_ogonek ogonek dead_ogonek<br />
keycode 16 = slash 7 7 slash grave dead_grave grave<br />
keycode 17 = parenleft 8 8 parenleft dead_abovedot abovedot dead_abovedot<br />
keycode 18 = parenright 9 9 parenright dead_acute apostrophe dead_acute<br />
keycode 19 = equal 0 0 equal dead_doubleacute doubleacute dead_doubleacute<br />
</nowiki>}}<br />
<br />
== See also ==<br />
<br />
*[http://www.x.org/archive/current/doc/man/man1/xmodmap.1.xhtml Current man page] at X.Org Foundation<br />
*[http://cweiske.de/howto/xmodmap/allinone.html Multimediakeys with .Xmodmap HOWTO] by Christian Weiske<br />
*[http://dev-loki.blogspot.com/2006/04/mapping-unsupported-keys-with-xmodmap.html Mapping unsupported keys with xmodmap] by Pascal Bleser<br />
*[http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap List of Keysyms Recognised by Xmodmap] on [http://linuxquestions.org LinuxQuestions]</div>Triplchttps://wiki.archlinux.org/index.php?title=Xmodmap&diff=472145Xmodmap2017-03-29T01:23:23Z<p>Triplc: fix</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Keyboards]]<br />
[[Category:X server]]<br />
[[de:Xmodmap]]<br />
[[fr:Xmodmap]]<br />
[[ja:Xmodmap]]<br />
[[ru:Xmodmap]]<br />
[[zh-hans:Xmodmap]]<br />
{{Related articles start}}<br />
{{Related|Xorg}}<br />
{{Related|Extra keyboard keys}}<br />
{{Related|Extra keyboard keys in Xorg}}<br />
{{Related|Extra keyboard keys in console}}<br />
{{Related|Xbindkeys}}<br />
{{Related articles end}}<br />
<br />
''xmodmap'' is a utility for modifying keymaps and pointer button mappings in [[Xorg]].<br />
<br />
''xmodmap'' is not directly related to [[X KeyBoard extension]] (XKB), as it uses different (pre-XKB) ideas on how ''keycodes'' are processed within X. Generally, it is only recommended for the simplest tasks. See [[X KeyBoard extension]] for advanced layout configuration.<br />
<br />
{{Note|''xmodmap'' settings are reset by ''setxkbmap'', which not only alters the alphanumeric keys to the values given in the map, but also resets all other keys to the startup default. [http://wiki.linuxquestions.org/wiki/Configuring_keyboards]}}<br />
<br />
== Introduction == <br />
<br />
There are two types of keyboard values in [[Xorg]]: ''keycodes'' and ''keysyms''.<br />
<br />
; keycode <br />
: The ''keycode'' is the numeric representation received by the kernel when a key or a mouse button is pressed.<br />
; keysym<br />
: The ''keysym'' is the value assigned to the ''keycode''. For example, pressing {{ic|A}} generates the {{ic|keycode 73}}, which is mapped to the {{ic|keysym 0×61}}, which matches {{ic|A}} in the [[Wikipedia:ASCII|ASCII table]].<br />
: The ''keysyms'' are managed by [[Xorg]] in a table of ''keycodes'' defining the ''keycode''-''keysym'' relations, which is called the [[#Keymap table|keymap table]]. This can be shown by running {{ic|xmodmap}}.<br />
<br />
== Installation ==<br />
<br />
''xmodmap'' can be [[pacman|installed]] through the {{Pkg|xorg-xmodmap}} package from the [[official repositories]].<br />
<br />
Optionally, install {{Pkg|xkeycaps}}, which is a graphical front-end to ''xmodmap''.<br />
<br />
== Keymap table ==<br />
<br />
Print the current keymap table formatted into expressions:<br />
<br />
{{hc|$ xmodmap -pke|2=<br />
[...]<br />
keycode 57 = n N<br />
[...]<br />
}}<br />
<br />
Each ''keycode'' is followed by the ''keysym'' it is mapped to. The above example indicates that the ''keycode'' {{ic|57}} is mapped to the lowercase {{ic|n}}, while the uppercase {{ic|N}} is mapped to ''keycode'' {{ic|57}} plus {{ic|Shift}}.<br />
<br />
Each ''keysym'' column in the table corresponds to a particular combination of modifier keys:<br />
# {{ic|Key}}<br />
# {{ic|Shift+Key}}<br />
# {{ic|mode_switch+Key}}<br />
# {{ic|mode_switch+Shift+Key}}<br />
# {{ic|AltGr+Key}}<br />
# {{ic|AltGr+Shift+Key}}<br />
<br />
Not all ''keysyms'' have to be set, but to assign only a latter ''keysym'', use the {{ic|NoSymbol}} value.<br />
<br />
To see which ''keycode'' corresponds to a key, see [[Extra keyboard keys#In Xorg]] for details on the ''xev'' utility which will output relevant keycode/keysym information about a key when you press it.<br />
<br />
{{Tip|There are predefined descriptive ''keysyms'' for multimedia keys, e.g. {{ic|XF86AudioMute}} or {{ic|XF86Mail}}. These ''keysyms'' can be found in {{ic|/usr/include/X11/XF86keysym.h}}. Many multimedia programs are designed to work with these ''keysyms'' out-of-the-box, without the need to configure any third-party application.<br />
}}<br />
<br />
Note that xmodmap is influenced by xkbd settings, so all eight keysym are available for the us(intl) xkbd layout but not for the default us (it is missing the ralt_switch symbol defined in level3). To have all 8 keysyms available you should configure the ''(intl)'' variant of the keyboard from xorg.conf or add, using us layout as an example, {{ic|setxkbmap -layout 'us(intl)'}} before calling xmodmap.<br />
<br />
== Custom table ==<br />
<br />
To create a key map (i.e. {{ic|~/.Xmodmap}}):<br />
$ xmodmap -pke > ~/.Xmodmap<br />
<br />
To test the changes:<br />
$ xmodmap ~/.Xmodmap<br />
<br />
=== Activating the custom table ===<br />
<br />
With [[GDM]], [[XDM]], [[KDM]] or [[LightDM]] there is no need to source {{ic|~/.Xmodmap}}. For [[startx]], use:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
[[ -f ~/.Xmodmap ]] && xmodmap ~/.Xmodmap<br />
</nowiki>}}<br />
<br />
Alternatively, edit the global startup script {{ic|/etc/X11/xinit/xinitrc}}.<br />
<br />
=== Test changes ===<br />
<br />
To make temporary changes:<br />
$ xmodmap -e "keycode 46 = l L l L lstroke Lstroke lstroke"<br />
$ xmodmap -e "keysym a = e E"<br />
<br />
== Modifier keys ==<br />
<br />
''xmodmap'' can also be used to override [[Wikipedia:Modifier key|modifier keys]], e.g. to swap {{ic|Control}} and {{ic|Super}} (the [[Wikipedia:Windows key|Windows keys]]).<br />
<br />
Before assignment the modifier keys need to be empty. {{ic|!}} is a comment, so only the modifiers {{ic|Control}} and {{ic|Mod4}} get cleared in the following example. Then the ''keysyms'' {{ic|Control_L}}, {{ic|Control_R}}, {{ic|Super_L}} and {{ic|Super_R}} are assigned to the opposite modifier. Assigning both left and right to the same modifier means that both keys are treated the same way.<br />
<br />
{{hc|~/.Xmodmap|2=<br />
[...]<br />
!clear Shift<br />
!clear Lock<br />
clear Control<br />
!clear Mod1<br />
!clear Mod2<br />
!clear Mod3<br />
clear Mod4<br />
!clear Mod5<br />
!add Shift = Shift_L Shift_R<br />
!add Lock = Caps_Lock<br />
add Control = Super_L Super_R<br />
!add Mod1 = Alt_L Alt_R<br />
!add Mod2 = Mode_switch<br />
!add Mod3 =<br />
add Mod4 = Control_L Control_R<br />
!add Mod5 =<br />
}}<br />
<br />
{{Note|The example assumes that the {{ic|Control_L}} and {{ic|Control_R}} keysyms were assigned to the {{ic|Control}} modifier, and {{ic|Super_L}} and {{ic|Super_R}} keysyms to the {{ic|Mod4}} modifier. If you get the following error message {{ic|X Error of failed request: BadValue (integer parameter out of range for operation)}}, you will need to adapt accordingly. Running {{ic|xmodmap}} produces a list of modifiers and keys that are assigned to them.}}<br />
<br />
The following example modifies {{ic|CapsLock}} to {{ic|Control}}, and {{ic|Shift+CapsLock}} to {{ic|CapsLock}}:<br />
{{hc|~/.Xmodmap|2=<br />
clear lock<br />
clear control<br />
add control = Caps_Lock Control_L Control_R<br />
keycode 66 = Control_L Caps_Lock NoSymbol NoSymbol<br />
}}<br />
<br />
== Reverse scrolling ==<br />
<br />
{{Merge|Mouse buttons|xmodmap is not the only way to do this.}}<br />
<br />
The [http://who-t.blogspot.com/2011/09/natural-scrolling-in-synaptics-driver.html natural scrolling] feature available in OS X Lion (mimicking smartphone or tablet scrolling) can be [https://bbs.archlinux.org/viewtopic.php?id=126258 replicated] with ''xmodmap''. Since the synaptics driver uses the buttons 4/5/6/7 for up/down/left/right scrolling, you simply need to swap the order of how the buttons are declared in {{ic|~/.Xmodmap}}:<br />
<br />
{{hc|~/.Xmodmap|2=<br />
pointer = 1 2 3 '''5 4''' 7 6 8 9 10 11 12<br />
}}<br />
<br />
Then update ''xmodmap'':<br />
$ xmodmap ~/.Xmodmap<br />
<br />
== Swapping mouse buttons ==<br />
<br />
{{Merge|Mouse buttons|xmodmap is not the only way to do this.}}<br />
<br />
The left, middle and right mouse buttons correspond to buttons 1,2 and 3 respectively in the synaptics driver. To swap left and right mouse buttons, again simply reverse the order in which they are listed in your {{ic|~/.Xmodmap}}:<br />
<br />
{{hc|~/.Xmodmap|2=<br />
pointer = '''3 2 1'''<br />
}}<br />
<br />
This should suffice for a simple mouse setup. Again, update ''xmodmap'':<br />
$ xmodmap ~/.Xmodmap<br />
<br />
== Templates ==<br />
<br />
=== Spanish === <br />
<br />
{{hc|~/.Xmodmap|<br />
keycode 24 &#61; a A aacute Aacute ae AE ae<br />
keycode 26 &#61; e E eacute Eacute EuroSign cent EuroSign<br />
keycode 30 &#61; u U uacute Uacute downarrow uparrow downarrow<br />
keycode 31 &#61; i I iacute Iacute rightarrow idotless rightarrow<br />
keycode 32 &#61; o O oacute Oacute oslash Oslash oslash<br />
keycode 57 &#61; n N ntilde Ntilde n N n<br />
keycode 58 &#61; comma question comma questiondown dead_acute dead_doubleacute dead_acute<br />
keycode 61 &#61; exclam section exclamdown section dead_belowdot dead_abovedot dead_belowdot<br />
!Maps the Mode key to the Alt key<br />
keycode 64 &#61; Mode_switch<br />
}}<br />
<br />
=== Turn CapsLock into Control ===<br />
<br />
Simplest example of changing {{ic|CapsLock}} into {{ic|Control}}.<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
clear lock<br />
clear control<br />
keycode 66 = Control_L<br />
add control = Control_L Control_R<br />
</nowiki>}}<br />
<br />
=== Turn CapsLock into Control, and LeftControl into Hyper ===<br />
<br />
Laptop users may prefer having {{ic|CapsLock}} as {{ic|Control}}. The {{ic|Left Control}} key can be used as a {{ic|Hyper}} modifier (an additional modifier for emacs or window manager).<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
clear lock <br />
clear control<br />
clear mod1<br />
clear mod2<br />
clear mod3<br />
clear mod4<br />
clear mod5<br />
keycode 37 = Hyper_L<br />
keycode 66 = Control_L<br />
add control = Control_L Control_R<br />
add mod1 = Alt_L Alt_R Meta_L<br />
add mod2 = Num_Lock<br />
add mod3 = Hyper_L<br />
add mod4 = Super_L Super_R<br />
add mod5 = Mode_switch ISO_Level3_Shift<br />
</nowiki>}}<br />
<br />
=== Switch every number key N with Shift-N and vice-versa, for Croatian layout ===<br />
<br />
Should work fine for layouts similar to Croatian as well.<br />
<br />
{{hc|~/.Xmodmap|<nowiki><br />
keycode 10 = exclam 1 1 exclam asciitilde dead_tilde asciitilde<br />
keycode 11 = quotedbl 2 2 quotedbl dead_caron caron dead_caron<br />
keycode 12 = numbersign 3 3 numbersign asciicircum dead_circumflex asciicircum<br />
keycode 13 = dollar 4 4 dollar dead_breve breve dead_breve<br />
keycode 14 = percent 5 5 percent degree dead_abovering degree<br />
keycode 15 = ampersand 6 6 ampersand dead_ogonek ogonek dead_ogonek<br />
keycode 16 = slash 7 7 slash grave dead_grave grave<br />
keycode 17 = parenleft 8 8 parenleft dead_abovedot abovedot dead_abovedot<br />
keycode 18 = parenright 9 9 parenright dead_acute apostrophe dead_acute<br />
keycode 19 = equal 0 0 equal dead_doubleacute doubleacute dead_doubleacute<br />
</nowiki>}}<br />
<br />
== See also ==<br />
<br />
*[http://www.x.org/archive/current/doc/man/man1/xmodmap.1.xhtml Current man page] at X.Org Foundation<br />
*[http://cweiske.de/howto/xmodmap/allinone.html Multimediakeys with .Xmodmap HOWTO] by Christian Weiske<br />
*[http://dev-loki.blogspot.com/2006/04/mapping-unsupported-keys-with-xmodmap.html Mapping unsupported keys with xmodmap] by Pascal Bleser<br />
*[http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap List of Keysyms Recognised by Xmodmap] on [http://linuxquestions.org LinuxQuestions]</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431997Talk:Xinit2016-04-20T21:36:49Z<p>Triplc: /* propose to add to automatic startx */</p>
<hr />
<div>== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)<br />
<br />
== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login to console, it may come to infinite loop/crash if (a) ~/.xinitrc goes wrong somewhere, after editing; or (b) after pacman -Syyu and Xorg crash. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
## do nothing, start automatic console login<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
[[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 20:42, 20 April 2016 (UTC)<br />
<br />
:You might do that without the temporary file by simply looking at the age of the log file: {{bc|<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ ! -e ~/.local/share/xorg/Xorg.0.log || $(find ~/.local/share/xorg/Xorg.0.log -mmin +2) != "" ]]; then<br />
exec startx<br />
fi<br />
fi<br />
</nowiki>}}<br />
:Or even more simply, don't {{ic|exec startx}}, check its return code and drop to interactive shell on errors: {{bc|<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
startx && exit<br />
fi<br />
</nowiki>}} -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 21:10, 20 April 2016 (UTC)<br />
<br />
::Thanks Lahwaacz. But (a) so the age of a file is based on it's creation time, not update time. OK, i did not know that. (b) about the startx exit code, i am not sure that it will correctly set if i edit something wrong in ~/.xinitrc which make GUI session crash<br />
::: I just tried to change the resolution of X (xrandr...) and ~/.local/share/xorg/Xorg.0.log updated and get the new timestamp [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 21:36, 20 April 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431996Talk:Xinit2016-04-20T21:32:36Z<p>Triplc: propose to add to automatic startx</p>
<hr />
<div>== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)<br />
<br />
== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login to console, it may come to infinite loop/crash if (a) ~/.xinitrc goes wrong somewhere, after editing; or (b) after pacman -Syyu and Xorg crash. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
## do nothing, start automatic console login<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
[[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 20:42, 20 April 2016 (UTC)<br />
<br />
:You might do that without the temporary file by simply looking at the age of the log file: {{bc|<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ ! -e ~/.local/share/xorg/Xorg.0.log || $(find ~/.local/share/xorg/Xorg.0.log -mmin +2) != "" ]]; then<br />
exec startx<br />
fi<br />
fi<br />
</nowiki>}}<br />
:Or even more simply, don't {{ic|exec startx}}, check its return code and drop to interactive shell on errors: {{bc|<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
startx && exit<br />
fi<br />
</nowiki>}} -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 21:10, 20 April 2016 (UTC)<br />
<br />
::Thanks Lahwaacz. But (a) so the age of a file is based on it's creation time, not update time. OK, i did not know that. (b) about the startx exit code, i am not sure that it will correctly set if i edit something wrong in ~/.xinitrc which make GUI session crash</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431990Talk:Xinit2016-04-20T20:42:28Z<p>Triplc: propose to add to automatic startx</p>
<hr />
<div>== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)<br />
<br />
== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login to console, it may come to infinite loop/crash if (a) ~/.xinitrc goes wrong somewhere, after editing; or (b) after pacman -Syyu and Xorg crash. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
## do nothing, start automatic console login<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
[[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 20:42, 20 April 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431965Talk:Xinit2016-04-20T13:29:53Z<p>Triplc: </p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infinite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431964Talk:Xinit2016-04-20T13:29:06Z<p>Triplc: </p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infinite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/zlogin-check-startx.flag ]]; then<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431963Talk:Xinit2016-04-20T13:26:56Z<p>Triplc: </p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/zlogin-check-startx.flag ]]; then<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
</nowiki>}}<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431962Talk:Xinit2016-04-20T13:24:19Z<p>Triplc: </p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/zlogin-check-startx.flag ]]; then<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431961Talk:Xinit2016-04-20T13:23:57Z<p>Triplc: /* propose to add to automatic startx */</p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/zlogin-check-startx.flag ]]; then<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last <br />
GUI session did not last long!\n"<br />
else<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Xinit&diff=431960Talk:Xinit2016-04-20T13:22:43Z<p>Triplc: to avoid infite loop/crash</p>
<hr />
<div>== propose to add to automatic startx ==<br />
<br />
When combine automatic startx + automatic login, it may come to infite loop/crash if ~/.xinitrc goes wrong somewhere. I propose to check if the last GUI session (startx session) really last long before start a new one.<br />
<br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/zlogin-check-startx.flag ]]; then<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last <br />
GUI session did not last long!\n"<br />
else<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx<br />
fi<br />
fi<br />
<br />
== about "&" and "exec" in .xinitrc ==<br />
<br />
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43 (UTC)<br />
<br />
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)<br />
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)<br />
<br />
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)<br />
<br />
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)<br />
<br />
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)<br />
<br />
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)<br />
<br />
== Running "Notes" Section ==<br />
The two sets of notes at the bottom of [[xinitrc#Configuration]] should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)<br />
<br />
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki><br />
#!/bin/sh<br />
if [ -z "$XDG_VTNR" ]; then<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
else<br />
exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR<br />
fi<br />
</nowiki>}}<br />
:Now it contains only {{bc|<nowiki><br />
#!/bin/sh<br />
exec /usr/bin/X -nolisten tcp "$@"<br />
</nowiki>}}<br />
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.<br />
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 08:17, 26 July 2015 (UTC)<br />
<br />
::Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 13:01, 26 July 2015 (UTC)<br />
:::I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes [[User:Ziusudra|Ziusudra]] ([[User talk:Ziusudra|talk]]) 00:19, 11 February 2016 (UTC)</div>Triplchttps://wiki.archlinux.org/index.php?title=Xinit&diff=431951Xinit2016-04-20T12:25:48Z<p>Triplc: if last GUI startx did not last long, do not auto startx</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Desktop environments]]<br />
[[Category:X server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[ru:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Related articles start}}<br />
{{Related|Display manager}}<br />
{{Related|Xorg}}<br />
{{Related|xprofile}}<br />
{{Related|Xresources}}<br />
{{Related articles end}}<br />
<br />
The {{ic|~/.xinitrc}} file is a shell script read by ''xinit'' and by its front-end ''startx''. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The ''xinit'' program starts the [[X Window System]] server and works as first client program on systems that are not using a [[display manager]].<br />
<br />
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with ''startx'' or ''xinit'' programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.<br />
<br />
Most DMs also source the similar [[xprofile]] before xinit.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xorg-xinit}} package, which provides both ''xinit'',''startx'', and a default xinitrc configuration file.<br />
<br />
== Configuration ==<br />
<br />
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.<br />
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{ic|man 1 xinit}} for details.}}<br />
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in home directory:<br />
<br />
$ cp /etc/X11/xinit/xinitrc ~/.xinitrc<br />
<br />
The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from {{ic|/etc/X11/xinit/xinitrc.d}}. Scripts in this directory without {{ic|.sh}} extension are not sourced.<br />
<br />
Append desired commands and ''remove/comment the conflicting lines''. Remember, lines following {{ic|exec}} would be ignored. For example, to start [[Openbox#Standalone|openbox]]:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ] ; then<br />
for f in /etc/X11/xinit/xinitrc.d/'''?*.sh''' ; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# twm &<br />
# xclock -geometry 50x50-1+1 &<br />
# xterm -geometry 80x50+494+51 &<br />
# xterm -geometry 80x20+494-0 &<br />
# exec xterm -geometry 80x66+0+0 -name login<br />
<br />
## some applications that should be run in the background<br />
xscreensaver '''&'''<br />
xsetroot -cursor_name left_ptr '''&'''<br />
<br />
'''exec''' openbox-session<br />
}}<br />
<br />
{{Note|At the very least, ensure that the ''if block'' in the example above is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}} <br />
<br />
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.<br />
<br />
== Running ==<br />
<br />
To now run Xorg as a regular user, issue:<br />
<br />
$ startx<br />
<br />
or<br />
<br />
$ xinit -- :1 -nolisten tcp vt$XDG_VTNR<br />
<br />
Your window manager (or desktop environment) of choice should now start correctly.<br />
<br />
To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:<br />
<br />
$ pkill -15 Xorg<br />
<br />
{{Note|''pkill'' will kill all running X instances. To specifically kill the window manager on the current VT, use:<br />
<br />
{{bc|<nowiki><br />
WM_PID=$(xprop -id $(xprop -root _NET_SUPPORTING_WM_CHECK \<br />
| awk -F'#' '{ print $2 }') _NET_WM_PID \<br />
| awk -F' = ' '{ print $2 }')<br />
<br />
kill -15 $WM_PID</nowiki>}}<br />
<br />
The program {{ic|xprop}} is provided by the package {{Pkg|xorg-xprop}} in the [[official repositories]].<br />
}}<br />
<br />
{{Note|<br />
* The above commands run [[Xorg]] on the same virtual terminal the user is logged in to. [http://blog.falconindy.com/articles/back-to-basics-with-x-and-systemd.html] This maintains an authenticated session with {{ic|logind}}, and prevents bypassing the screen locker by switching terminals.<br />
* You have to specify {{ic|vt$XDG_VTNR}} as command line option for ''xinit'' in order to [[General troubleshooting#Session permissions|preserve session permissions]].<br />
* ''xinit'' does not handle multiple sessions when already logged-in into a different virtual terminal. For that you must specify the session by appending {{ic|-- :''session_no''}}. If X is already running, then you should start with :1 or more.<br />
* By default, due to permissions on console devices, the X display needs to be on the same tty where the login occurred. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}. See [[General troubleshooting#Session permissions]] for details.<br />
* If you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by {{ic|/usr/lib/systemd/systemd-multi-seat-x}}. For convenience, ''startx'' can be set up to use this wrapper by modifying your {{ic|~/.xserverrc}}.<br />
* If you choose to use ''xinit'' instead of ''startx'', you are responsible for passing {{ic|-nolisten tcp}} and ensuring the session does not break by starting X on a different tty.<br />
* If X terminates with error message "SocketCreateListener() failed", you may need to delete socket files in {{ic|/tmp/.X11-unix}}. This may happen if you have previously run Xorg as root (e.g. to generate an {{ic|xorg.conf}}, as below).<br />
}}<br />
<br />
== Autostart X at login ==<br />
<br />
{{Note|These solutions run X on the same tty used to login, which is required in order to maintain the login session.}}<br />
<br />
For [[Bash]], add the following to the bottom of {{ic|~/.bash_profile}}. If the file does not exist, copy a skeleton version from {{ic|/etc/skel/.bash_profile}}. For [[Zsh]], add it to {{ic|~/.zlogin}} (or {{ic|~/.zprofile}}) instead.<br />
<br />
{{bc|1=<nowiki><br />
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx<br />
</nowiki>}}<br />
<br />
{{Note|<br />
* You can replace the {{ic|-eq 1}} comparison with one like {{ic|-le 3}} (for vt1 to vt3) if you want to use graphical logins on more than one VT.<br />
* X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}.<br />
* {{ic|xinit}} may be faster than {{ic|startx}}, but needs additional parameter such as {{ic|-nolisten tcp}}.<br />
* If you would like to remain logged in when the X session ends, remove {{ic|exec}}.<br />
}}<br />
<br />
See also [[Fish#Start X at login]] and [[Systemd/User#Automatic login into Xorg without display manager]].<br />
<br />
=== Automatic login to the virtual console ===<br />
<br />
This method can be combined with [[automatic login to virtual console]].<br />
<br />
In that case, you may want to check weather the last GUI session really last long before actually start GUI. For example, you only start GUI if the last GUI session last more than 120 seconds, and just switch to "normal text" session if not:<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx <br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.<br />
<br />
== Tips and tricks ==<br />
<br />
=== Override xinitrc from command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE, you can run it by issuing ''startx'' followed by the path to the window manager:<br />
<br />
$ startx /full/path/to/window-manager<br />
<br />
If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of ''startx'':<br />
<br />
$ startx "/full/path/to/window-manager --key value"<br />
<br />
Note that the full path is '''required'''. Optionally, you can also override {{ic|/etc/X11/xinit/xserverrc}} file (which stores the default X server options) with custom options by appending them after {{ic|--}}, e.g.:<br />
<br />
$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
or<br />
<br />
$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
See also {{ic|man startx}}.<br />
<br />
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}<br />
<br />
=== Making a DE/WM choice ===<br />
<br />
If you are frequently switching between different DEs/WMs, it is recommended to either use a [[Display manager]] or add code to {{ic|.xinitrc}}. The code described next consists of a simple few lines, which will take the argument and load the desired desktop environment or window manager.<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular DE/WM with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
...<br />
<br />
# Here Xfce is kept as default<br />
session=${1:-xfce}<br />
<br />
case $session in<br />
awesome ) exec awesome;;<br />
bspwm ) exec bspwm;;<br />
catwm ) exec catwm;;<br />
cinnamon ) exec cinnamon-session;;<br />
dwm ) exec dwm;;<br />
enlightenment ) exec enlightenment_start;;<br />
ede ) exec startede;;<br />
fluxbox ) exec startfluxbox;;<br />
gnome ) exec gnome-session;;<br />
gnome-classic ) exec gnome-session --session=gnome-classic;;<br />
i3|i3wm ) exec i3;;<br />
icewm ) exec icewm-session;;<br />
jwm ) exec jwm;;<br />
kde ) exec startkde;;<br />
mate ) exec mate-session;;<br />
monster|monsterwm ) exec monsterwm;;<br />
notion ) exec notion;;<br />
openbox ) exec openbox-session;;<br />
unity ) exec unity;;<br />
xfce|xfce4 ) exec startxfce4;;<br />
xmonad ) exec xmonad;;<br />
# No known session, try to run it as command<br />
*) exec $1;;<br />
esac<br />
</nowiki>}}<br />
<br />
Then copy the {{ic|/etc/X11/xinit/xserverrc}} file to your home directory:<br />
<br />
$ cp /etc/X11/xinit/xserverrc ~/.xserverrc<br />
<br />
After that, you can easily start a particular DE/WM by passing an argument, e.g.:<br />
<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit wmaker<br />
<br />
or<br />
<br />
$ startx<br />
$ startx ~/.xinitrc gnome<br />
$ startx ~/.xinitrc kde<br />
$ startx ~/.xinitrc wmaker<br />
<br />
=== Starting applications without a window manager ===<br />
<br />
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
exec chromium<br />
}}<br />
<br />
With this method you need to set each application window's geometry through its own configuration files, if possible at all.<br />
<br />
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}<br />
<br />
See also [[Display manager#Starting applications without a window manager]].</div>Triplchttps://wiki.archlinux.org/index.php?title=Xinit&diff=431950Xinit2016-04-20T12:23:25Z<p>Triplc: if last GUI startx did not last long, do not auto startx</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Desktop environments]]<br />
[[Category:X server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[ru:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Related articles start}}<br />
{{Related|Display manager}}<br />
{{Related|Xorg}}<br />
{{Related|xprofile}}<br />
{{Related|Xresources}}<br />
{{Related articles end}}<br />
<br />
The {{ic|~/.xinitrc}} file is a shell script read by ''xinit'' and by its front-end ''startx''. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The ''xinit'' program starts the [[X Window System]] server and works as first client program on systems that are not using a [[display manager]].<br />
<br />
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with ''startx'' or ''xinit'' programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.<br />
<br />
Most DMs also source the similar [[xprofile]] before xinit.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xorg-xinit}} package, which provides both ''xinit'',''startx'', and a default xinitrc configuration file.<br />
<br />
== Configuration ==<br />
<br />
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.<br />
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{ic|man 1 xinit}} for details.}}<br />
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in home directory:<br />
<br />
$ cp /etc/X11/xinit/xinitrc ~/.xinitrc<br />
<br />
The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from {{ic|/etc/X11/xinit/xinitrc.d}}. Scripts in this directory without {{ic|.sh}} extension are not sourced.<br />
<br />
Append desired commands and ''remove/comment the conflicting lines''. Remember, lines following {{ic|exec}} would be ignored. For example, to start [[Openbox#Standalone|openbox]]:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ] ; then<br />
for f in /etc/X11/xinit/xinitrc.d/'''?*.sh''' ; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# twm &<br />
# xclock -geometry 50x50-1+1 &<br />
# xterm -geometry 80x50+494+51 &<br />
# xterm -geometry 80x20+494-0 &<br />
# exec xterm -geometry 80x66+0+0 -name login<br />
<br />
## some applications that should be run in the background<br />
xscreensaver '''&'''<br />
xsetroot -cursor_name left_ptr '''&'''<br />
<br />
'''exec''' openbox-session<br />
}}<br />
<br />
{{Note|At the very least, ensure that the ''if block'' in the example above is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}} <br />
<br />
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.<br />
<br />
== Running ==<br />
<br />
To now run Xorg as a regular user, issue:<br />
<br />
$ startx<br />
<br />
or<br />
<br />
$ xinit -- :1 -nolisten tcp vt$XDG_VTNR<br />
<br />
Your window manager (or desktop environment) of choice should now start correctly.<br />
<br />
To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:<br />
<br />
$ pkill -15 Xorg<br />
<br />
{{Note|''pkill'' will kill all running X instances. To specifically kill the window manager on the current VT, use:<br />
<br />
{{bc|<nowiki><br />
WM_PID=$(xprop -id $(xprop -root _NET_SUPPORTING_WM_CHECK \<br />
| awk -F'#' '{ print $2 }') _NET_WM_PID \<br />
| awk -F' = ' '{ print $2 }')<br />
<br />
kill -15 $WM_PID</nowiki>}}<br />
<br />
The program {{ic|xprop}} is provided by the package {{Pkg|xorg-xprop}} in the [[official repositories]].<br />
}}<br />
<br />
{{Note|<br />
* The above commands run [[Xorg]] on the same virtual terminal the user is logged in to. [http://blog.falconindy.com/articles/back-to-basics-with-x-and-systemd.html] This maintains an authenticated session with {{ic|logind}}, and prevents bypassing the screen locker by switching terminals.<br />
* You have to specify {{ic|vt$XDG_VTNR}} as command line option for ''xinit'' in order to [[General troubleshooting#Session permissions|preserve session permissions]].<br />
* ''xinit'' does not handle multiple sessions when already logged-in into a different virtual terminal. For that you must specify the session by appending {{ic|-- :''session_no''}}. If X is already running, then you should start with :1 or more.<br />
* By default, due to permissions on console devices, the X display needs to be on the same tty where the login occurred. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}. See [[General troubleshooting#Session permissions]] for details.<br />
* If you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by {{ic|/usr/lib/systemd/systemd-multi-seat-x}}. For convenience, ''startx'' can be set up to use this wrapper by modifying your {{ic|~/.xserverrc}}.<br />
* If you choose to use ''xinit'' instead of ''startx'', you are responsible for passing {{ic|-nolisten tcp}} and ensuring the session does not break by starting X on a different tty.<br />
* If X terminates with error message "SocketCreateListener() failed", you may need to delete socket files in {{ic|/tmp/.X11-unix}}. This may happen if you have previously run Xorg as root (e.g. to generate an {{ic|xorg.conf}}, as below).<br />
}}<br />
<br />
== Autostart X at login ==<br />
<br />
{{Note|These solutions run X on the same tty used to login, which is required in order to maintain the login session.}}<br />
<br />
For [[Bash]], add the following to the bottom of {{ic|~/.bash_profile}}. If the file does not exist, copy a skeleton version from {{ic|/etc/skel/.bash_profile}}. For [[Zsh]], add it to {{ic|~/.zlogin}} (or {{ic|~/.zprofile}}) instead.<br />
<br />
{{bc|1=<nowiki><br />
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx<br />
</nowiki>}}<br />
<br />
{{Note|<br />
* You can replace the {{ic|-eq 1}} comparison with one like {{ic|-le 3}} (for vt1 to vt3) if you want to use graphical logins on more than one VT.<br />
* X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}.<br />
* {{ic|xinit}} may be faster than {{ic|startx}}, but needs additional parameter such as {{ic|-nolisten tcp}}.<br />
* If you would like to remain logged in when the X session ends, remove {{ic|exec}}.<br />
}}<br />
<br />
See also [[Fish#Start X at login]] and [[Systemd/User#Automatic login into Xorg without display manager]].<br />
<br />
=== Automatic login to the virtual console ===<br />
<br />
This method can be combined with [[automatic login to virtual console]].<br />
<br />
In that case, you may want to check weather the last GUI session really last long before actually start GUI. For example, you only start GUI if the last GUI session last more than 120 seconds, and just switch to "normal text" session if not:<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ -f /tmp/login-check-startx.flag ]]; then<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
else<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx <br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
<br />
== Tips and tricks ==<br />
<br />
=== Override xinitrc from command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE, you can run it by issuing ''startx'' followed by the path to the window manager:<br />
<br />
$ startx /full/path/to/window-manager<br />
<br />
If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of ''startx'':<br />
<br />
$ startx "/full/path/to/window-manager --key value"<br />
<br />
Note that the full path is '''required'''. Optionally, you can also override {{ic|/etc/X11/xinit/xserverrc}} file (which stores the default X server options) with custom options by appending them after {{ic|--}}, e.g.:<br />
<br />
$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
or<br />
<br />
$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
See also {{ic|man startx}}.<br />
<br />
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}<br />
<br />
=== Making a DE/WM choice ===<br />
<br />
If you are frequently switching between different DEs/WMs, it is recommended to either use a [[Display manager]] or add code to {{ic|.xinitrc}}. The code described next consists of a simple few lines, which will take the argument and load the desired desktop environment or window manager.<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular DE/WM with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
...<br />
<br />
# Here Xfce is kept as default<br />
session=${1:-xfce}<br />
<br />
case $session in<br />
awesome ) exec awesome;;<br />
bspwm ) exec bspwm;;<br />
catwm ) exec catwm;;<br />
cinnamon ) exec cinnamon-session;;<br />
dwm ) exec dwm;;<br />
enlightenment ) exec enlightenment_start;;<br />
ede ) exec startede;;<br />
fluxbox ) exec startfluxbox;;<br />
gnome ) exec gnome-session;;<br />
gnome-classic ) exec gnome-session --session=gnome-classic;;<br />
i3|i3wm ) exec i3;;<br />
icewm ) exec icewm-session;;<br />
jwm ) exec jwm;;<br />
kde ) exec startkde;;<br />
mate ) exec mate-session;;<br />
monster|monsterwm ) exec monsterwm;;<br />
notion ) exec notion;;<br />
openbox ) exec openbox-session;;<br />
unity ) exec unity;;<br />
xfce|xfce4 ) exec startxfce4;;<br />
xmonad ) exec xmonad;;<br />
# No known session, try to run it as command<br />
*) exec $1;;<br />
esac<br />
</nowiki>}}<br />
<br />
Then copy the {{ic|/etc/X11/xinit/xserverrc}} file to your home directory:<br />
<br />
$ cp /etc/X11/xinit/xserverrc ~/.xserverrc<br />
<br />
After that, you can easily start a particular DE/WM by passing an argument, e.g.:<br />
<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit wmaker<br />
<br />
or<br />
<br />
$ startx<br />
$ startx ~/.xinitrc gnome<br />
$ startx ~/.xinitrc kde<br />
$ startx ~/.xinitrc wmaker<br />
<br />
=== Starting applications without a window manager ===<br />
<br />
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
exec chromium<br />
}}<br />
<br />
With this method you need to set each application window's geometry through its own configuration files, if possible at all.<br />
<br />
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}<br />
<br />
See also [[Display manager#Starting applications without a window manager]].</div>Triplchttps://wiki.archlinux.org/index.php?title=Xinit&diff=431949Xinit2016-04-20T12:22:11Z<p>Triplc: if last GUI startx did not last long, do not auto startx</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Desktop environments]]<br />
[[Category:X server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[ru:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Related articles start}}<br />
{{Related|Display manager}}<br />
{{Related|Xorg}}<br />
{{Related|xprofile}}<br />
{{Related|Xresources}}<br />
{{Related articles end}}<br />
<br />
The {{ic|~/.xinitrc}} file is a shell script read by ''xinit'' and by its front-end ''startx''. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The ''xinit'' program starts the [[X Window System]] server and works as first client program on systems that are not using a [[display manager]].<br />
<br />
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with ''startx'' or ''xinit'' programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.<br />
<br />
Most DMs also source the similar [[xprofile]] before xinit.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xorg-xinit}} package, which provides both ''xinit'',''startx'', and a default xinitrc configuration file.<br />
<br />
== Configuration ==<br />
<br />
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.<br />
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{ic|man 1 xinit}} for details.}}<br />
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in home directory:<br />
<br />
$ cp /etc/X11/xinit/xinitrc ~/.xinitrc<br />
<br />
The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from {{ic|/etc/X11/xinit/xinitrc.d}}. Scripts in this directory without {{ic|.sh}} extension are not sourced.<br />
<br />
Append desired commands and ''remove/comment the conflicting lines''. Remember, lines following {{ic|exec}} would be ignored. For example, to start [[Openbox#Standalone|openbox]]:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ] ; then<br />
for f in /etc/X11/xinit/xinitrc.d/'''?*.sh''' ; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# twm &<br />
# xclock -geometry 50x50-1+1 &<br />
# xterm -geometry 80x50+494+51 &<br />
# xterm -geometry 80x20+494-0 &<br />
# exec xterm -geometry 80x66+0+0 -name login<br />
<br />
## some applications that should be run in the background<br />
xscreensaver '''&'''<br />
xsetroot -cursor_name left_ptr '''&'''<br />
<br />
'''exec''' openbox-session<br />
}}<br />
<br />
{{Note|At the very least, ensure that the ''if block'' in the example above is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}} <br />
<br />
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.<br />
<br />
== Running ==<br />
<br />
To now run Xorg as a regular user, issue:<br />
<br />
$ startx<br />
<br />
or<br />
<br />
$ xinit -- :1 -nolisten tcp vt$XDG_VTNR<br />
<br />
Your window manager (or desktop environment) of choice should now start correctly.<br />
<br />
To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:<br />
<br />
$ pkill -15 Xorg<br />
<br />
{{Note|''pkill'' will kill all running X instances. To specifically kill the window manager on the current VT, use:<br />
<br />
{{bc|<nowiki><br />
WM_PID=$(xprop -id $(xprop -root _NET_SUPPORTING_WM_CHECK \<br />
| awk -F'#' '{ print $2 }') _NET_WM_PID \<br />
| awk -F' = ' '{ print $2 }')<br />
<br />
kill -15 $WM_PID</nowiki>}}<br />
<br />
The program {{ic|xprop}} is provided by the package {{Pkg|xorg-xprop}} in the [[official repositories]].<br />
}}<br />
<br />
{{Note|<br />
* The above commands run [[Xorg]] on the same virtual terminal the user is logged in to. [http://blog.falconindy.com/articles/back-to-basics-with-x-and-systemd.html] This maintains an authenticated session with {{ic|logind}}, and prevents bypassing the screen locker by switching terminals.<br />
* You have to specify {{ic|vt$XDG_VTNR}} as command line option for ''xinit'' in order to [[General troubleshooting#Session permissions|preserve session permissions]].<br />
* ''xinit'' does not handle multiple sessions when already logged-in into a different virtual terminal. For that you must specify the session by appending {{ic|-- :''session_no''}}. If X is already running, then you should start with :1 or more.<br />
* By default, due to permissions on console devices, the X display needs to be on the same tty where the login occurred. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}. See [[General troubleshooting#Session permissions]] for details.<br />
* If you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by {{ic|/usr/lib/systemd/systemd-multi-seat-x}}. For convenience, ''startx'' can be set up to use this wrapper by modifying your {{ic|~/.xserverrc}}.<br />
* If you choose to use ''xinit'' instead of ''startx'', you are responsible for passing {{ic|-nolisten tcp}} and ensuring the session does not break by starting X on a different tty.<br />
* If X terminates with error message "SocketCreateListener() failed", you may need to delete socket files in {{ic|/tmp/.X11-unix}}. This may happen if you have previously run Xorg as root (e.g. to generate an {{ic|xorg.conf}}, as below).<br />
}}<br />
<br />
== Autostart X at login ==<br />
<br />
{{Note|These solutions run X on the same tty used to login, which is required in order to maintain the login session.}}<br />
<br />
For [[Bash]], add the following to the bottom of {{ic|~/.bash_profile}}. If the file does not exist, copy a skeleton version from {{ic|/etc/skel/.bash_profile}}. For [[Zsh]], add it to {{ic|~/.zlogin}} (or {{ic|~/.zprofile}}) instead.<br />
<br />
{{bc|1=<nowiki><br />
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx<br />
</nowiki>}}<br />
<br />
{{Note|<br />
* You can replace the {{ic|-eq 1}} comparison with one like {{ic|-le 3}} (for vt1 to vt3) if you want to use graphical logins on more than one VT.<br />
* X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}.<br />
* {{ic|xinit}} may be faster than {{ic|startx}}, but needs additional parameter such as {{ic|-nolisten tcp}}.<br />
* If you would like to remain logged in when the X session ends, remove {{ic|exec}}.<br />
}}<br />
<br />
See also [[Fish#Start X at login]] and [[Systemd/User#Automatic login into Xorg without display manager]].<br />
<br />
=== Automatic login to the virtual console ===<br />
<br />
This method can be combined with [[automatic login to virtual console]].<br />
<br />
In that case, you may want to check weather the last GUI session really last long before actually start GUI. For example, you only start GUI if the last GUI session last more than 120 seconds, and just switch to "normal text" session if not:<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ ! -f /tmp/login-check-startx.flag ]]; then<br />
touch /tmp/login-check-startx.flag<br />
( sleep 120; rm /tmp/login-check-startx.flag ) &<br />
exec startx <br />
else<br />
rm /tmp/login-check-startx.flag<br />
echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
<br />
== Tips and tricks ==<br />
<br />
=== Override xinitrc from command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE, you can run it by issuing ''startx'' followed by the path to the window manager:<br />
<br />
$ startx /full/path/to/window-manager<br />
<br />
If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of ''startx'':<br />
<br />
$ startx "/full/path/to/window-manager --key value"<br />
<br />
Note that the full path is '''required'''. Optionally, you can also override {{ic|/etc/X11/xinit/xserverrc}} file (which stores the default X server options) with custom options by appending them after {{ic|--}}, e.g.:<br />
<br />
$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
or<br />
<br />
$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
See also {{ic|man startx}}.<br />
<br />
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}<br />
<br />
=== Making a DE/WM choice ===<br />
<br />
If you are frequently switching between different DEs/WMs, it is recommended to either use a [[Display manager]] or add code to {{ic|.xinitrc}}. The code described next consists of a simple few lines, which will take the argument and load the desired desktop environment or window manager.<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular DE/WM with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
...<br />
<br />
# Here Xfce is kept as default<br />
session=${1:-xfce}<br />
<br />
case $session in<br />
awesome ) exec awesome;;<br />
bspwm ) exec bspwm;;<br />
catwm ) exec catwm;;<br />
cinnamon ) exec cinnamon-session;;<br />
dwm ) exec dwm;;<br />
enlightenment ) exec enlightenment_start;;<br />
ede ) exec startede;;<br />
fluxbox ) exec startfluxbox;;<br />
gnome ) exec gnome-session;;<br />
gnome-classic ) exec gnome-session --session=gnome-classic;;<br />
i3|i3wm ) exec i3;;<br />
icewm ) exec icewm-session;;<br />
jwm ) exec jwm;;<br />
kde ) exec startkde;;<br />
mate ) exec mate-session;;<br />
monster|monsterwm ) exec monsterwm;;<br />
notion ) exec notion;;<br />
openbox ) exec openbox-session;;<br />
unity ) exec unity;;<br />
xfce|xfce4 ) exec startxfce4;;<br />
xmonad ) exec xmonad;;<br />
# No known session, try to run it as command<br />
*) exec $1;;<br />
esac<br />
</nowiki>}}<br />
<br />
Then copy the {{ic|/etc/X11/xinit/xserverrc}} file to your home directory:<br />
<br />
$ cp /etc/X11/xinit/xserverrc ~/.xserverrc<br />
<br />
After that, you can easily start a particular DE/WM by passing an argument, e.g.:<br />
<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit wmaker<br />
<br />
or<br />
<br />
$ startx<br />
$ startx ~/.xinitrc gnome<br />
$ startx ~/.xinitrc kde<br />
$ startx ~/.xinitrc wmaker<br />
<br />
=== Starting applications without a window manager ===<br />
<br />
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
exec chromium<br />
}}<br />
<br />
With this method you need to set each application window's geometry through its own configuration files, if possible at all.<br />
<br />
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}<br />
<br />
See also [[Display manager#Starting applications without a window manager]].</div>Triplchttps://wiki.archlinux.org/index.php?title=Xinit&diff=431948Xinit2016-04-20T12:20:31Z<p>Triplc: if last GUI startx did not last long, do not auto startx</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Desktop environments]]<br />
[[Category:X server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[ru:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Related articles start}}<br />
{{Related|Display manager}}<br />
{{Related|Xorg}}<br />
{{Related|xprofile}}<br />
{{Related|Xresources}}<br />
{{Related articles end}}<br />
<br />
The {{ic|~/.xinitrc}} file is a shell script read by ''xinit'' and by its front-end ''startx''. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The ''xinit'' program starts the [[X Window System]] server and works as first client program on systems that are not using a [[display manager]].<br />
<br />
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with ''startx'' or ''xinit'' programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.<br />
<br />
Most DMs also source the similar [[xprofile]] before xinit.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xorg-xinit}} package, which provides both ''xinit'',''startx'', and a default xinitrc configuration file.<br />
<br />
== Configuration ==<br />
<br />
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.<br />
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{ic|man 1 xinit}} for details.}}<br />
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in home directory:<br />
<br />
$ cp /etc/X11/xinit/xinitrc ~/.xinitrc<br />
<br />
The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from {{ic|/etc/X11/xinit/xinitrc.d}}. Scripts in this directory without {{ic|.sh}} extension are not sourced.<br />
<br />
Append desired commands and ''remove/comment the conflicting lines''. Remember, lines following {{ic|exec}} would be ignored. For example, to start [[Openbox#Standalone|openbox]]:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ] ; then<br />
for f in /etc/X11/xinit/xinitrc.d/'''?*.sh''' ; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# twm &<br />
# xclock -geometry 50x50-1+1 &<br />
# xterm -geometry 80x50+494+51 &<br />
# xterm -geometry 80x20+494-0 &<br />
# exec xterm -geometry 80x66+0+0 -name login<br />
<br />
## some applications that should be run in the background<br />
xscreensaver '''&'''<br />
xsetroot -cursor_name left_ptr '''&'''<br />
<br />
'''exec''' openbox-session<br />
}}<br />
<br />
{{Note|At the very least, ensure that the ''if block'' in the example above is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}} <br />
<br />
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.<br />
<br />
== Running ==<br />
<br />
To now run Xorg as a regular user, issue:<br />
<br />
$ startx<br />
<br />
or<br />
<br />
$ xinit -- :1 -nolisten tcp vt$XDG_VTNR<br />
<br />
Your window manager (or desktop environment) of choice should now start correctly.<br />
<br />
To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:<br />
<br />
$ pkill -15 Xorg<br />
<br />
{{Note|''pkill'' will kill all running X instances. To specifically kill the window manager on the current VT, use:<br />
<br />
{{bc|<nowiki><br />
WM_PID=$(xprop -id $(xprop -root _NET_SUPPORTING_WM_CHECK \<br />
| awk -F'#' '{ print $2 }') _NET_WM_PID \<br />
| awk -F' = ' '{ print $2 }')<br />
<br />
kill -15 $WM_PID</nowiki>}}<br />
<br />
The program {{ic|xprop}} is provided by the package {{Pkg|xorg-xprop}} in the [[official repositories]].<br />
}}<br />
<br />
{{Note|<br />
* The above commands run [[Xorg]] on the same virtual terminal the user is logged in to. [http://blog.falconindy.com/articles/back-to-basics-with-x-and-systemd.html] This maintains an authenticated session with {{ic|logind}}, and prevents bypassing the screen locker by switching terminals.<br />
* You have to specify {{ic|vt$XDG_VTNR}} as command line option for ''xinit'' in order to [[General troubleshooting#Session permissions|preserve session permissions]].<br />
* ''xinit'' does not handle multiple sessions when already logged-in into a different virtual terminal. For that you must specify the session by appending {{ic|-- :''session_no''}}. If X is already running, then you should start with :1 or more.<br />
* By default, due to permissions on console devices, the X display needs to be on the same tty where the login occurred. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}. See [[General troubleshooting#Session permissions]] for details.<br />
* If you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by {{ic|/usr/lib/systemd/systemd-multi-seat-x}}. For convenience, ''startx'' can be set up to use this wrapper by modifying your {{ic|~/.xserverrc}}.<br />
* If you choose to use ''xinit'' instead of ''startx'', you are responsible for passing {{ic|-nolisten tcp}} and ensuring the session does not break by starting X on a different tty.<br />
* If X terminates with error message "SocketCreateListener() failed", you may need to delete socket files in {{ic|/tmp/.X11-unix}}. This may happen if you have previously run Xorg as root (e.g. to generate an {{ic|xorg.conf}}, as below).<br />
}}<br />
<br />
== Autostart X at login ==<br />
<br />
{{Note|These solutions run X on the same tty used to login, which is required in order to maintain the login session.}}<br />
<br />
For [[Bash]], add the following to the bottom of {{ic|~/.bash_profile}}. If the file does not exist, copy a skeleton version from {{ic|/etc/skel/.bash_profile}}. For [[Zsh]], add it to {{ic|~/.zlogin}} (or {{ic|~/.zprofile}}) instead.<br />
<br />
{{bc|1=<nowiki><br />
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx<br />
</nowiki>}}<br />
<br />
{{Note|<br />
* You can replace the {{ic|-eq 1}} comparison with one like {{ic|-le 3}} (for vt1 to vt3) if you want to use graphical logins on more than one VT.<br />
* X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}.<br />
* {{ic|xinit}} may be faster than {{ic|startx}}, but needs additional parameter such as {{ic|-nolisten tcp}}.<br />
* If you would like to remain logged in when the X session ends, remove {{ic|exec}}.<br />
}}<br />
<br />
See also [[Fish#Start X at login]] and [[Systemd/User#Automatic login into Xorg without display manager]].<br />
<br />
=== Automatic login to the virtual console ===<br />
<br />
This method can be combined with [[automatic login to virtual console]].<br />
<br />
In that case, you may want to check weather the last GUI session really last long before actually start GUI. For example, you only start GUI if the last GUI session last more than 120 seconds, and just switch to "normal text" session if not:<br />
<br />
{{bc|1=<nowiki><br />
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then<br />
if [[ ! -f /tmp/zlogin-check-startx.flag ]]; then<br />
touch /tmp/zlogin-check-startx.flag<br />
( sleep 120; rm /tmp/zlogin-check-startx.flag ) &!<br />
exec startx <br />
else<br />
rm /tmp/zlogin-check-startx.flag<br />
echo -e "\nFile '/tmp/zlogin-check-startx.flag' found, maybe the last GUI session did not last long!\n"<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
<br />
== Tips and tricks ==<br />
<br />
=== Override xinitrc from command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE, you can run it by issuing ''startx'' followed by the path to the window manager:<br />
<br />
$ startx /full/path/to/window-manager<br />
<br />
If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of ''startx'':<br />
<br />
$ startx "/full/path/to/window-manager --key value"<br />
<br />
Note that the full path is '''required'''. Optionally, you can also override {{ic|/etc/X11/xinit/xserverrc}} file (which stores the default X server options) with custom options by appending them after {{ic|--}}, e.g.:<br />
<br />
$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
or<br />
<br />
$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR<br />
<br />
See also {{ic|man startx}}.<br />
<br />
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}<br />
<br />
=== Making a DE/WM choice ===<br />
<br />
If you are frequently switching between different DEs/WMs, it is recommended to either use a [[Display manager]] or add code to {{ic|.xinitrc}}. The code described next consists of a simple few lines, which will take the argument and load the desired desktop environment or window manager.<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular DE/WM with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
...<br />
<br />
# Here Xfce is kept as default<br />
session=${1:-xfce}<br />
<br />
case $session in<br />
awesome ) exec awesome;;<br />
bspwm ) exec bspwm;;<br />
catwm ) exec catwm;;<br />
cinnamon ) exec cinnamon-session;;<br />
dwm ) exec dwm;;<br />
enlightenment ) exec enlightenment_start;;<br />
ede ) exec startede;;<br />
fluxbox ) exec startfluxbox;;<br />
gnome ) exec gnome-session;;<br />
gnome-classic ) exec gnome-session --session=gnome-classic;;<br />
i3|i3wm ) exec i3;;<br />
icewm ) exec icewm-session;;<br />
jwm ) exec jwm;;<br />
kde ) exec startkde;;<br />
mate ) exec mate-session;;<br />
monster|monsterwm ) exec monsterwm;;<br />
notion ) exec notion;;<br />
openbox ) exec openbox-session;;<br />
unity ) exec unity;;<br />
xfce|xfce4 ) exec startxfce4;;<br />
xmonad ) exec xmonad;;<br />
# No known session, try to run it as command<br />
*) exec $1;;<br />
esac<br />
</nowiki>}}<br />
<br />
Then copy the {{ic|/etc/X11/xinit/xserverrc}} file to your home directory:<br />
<br />
$ cp /etc/X11/xinit/xserverrc ~/.xserverrc<br />
<br />
After that, you can easily start a particular DE/WM by passing an argument, e.g.:<br />
<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit wmaker<br />
<br />
or<br />
<br />
$ startx<br />
$ startx ~/.xinitrc gnome<br />
$ startx ~/.xinitrc kde<br />
$ startx ~/.xinitrc wmaker<br />
<br />
=== Starting applications without a window manager ===<br />
<br />
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
exec chromium<br />
}}<br />
<br />
With this method you need to set each application window's geometry through its own configuration files, if possible at all.<br />
<br />
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}<br />
<br />
See also [[Display manager#Starting applications without a window manager]].</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401725Talk:Master Boot Record2015-09-24T23:07:45Z<p>Triplc: why i add this session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)<br />
::>>Reason: Out of scope, see fdisk which does "erase" just fine<br />
::Well, in my case, I "dd" a window installation to that USB, which makes USB become "gpt" type. After that I do not know how to use fdisk to "erase" that. So I had to "dd" and then "cfdisk" to revive that USB. Anyway, maybe I am not so pro in Linux.<br />
::Anyway, whether "fdisk" or not, there should be some guide that tell how to reset the disk MBR. (Sep 22, 2015)<br />
:::The "guide" depends on your favourite [[Partitioning#Partitioning_tools|partitioning tool]]. All the linked pages explain how to create a new "partition table" (more general than just MBR). In all the ''*disk'' tools, this is done with the {{ic|o}} command. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 15:27, 24 September 2015 (UTC)<br />
::::Thanks for the clarifications. I think I understand your points. However: (1) I beleive that there should be some <i>practical</i> guide, not just links to other websites; in fact, I took me quite a time to read/try... just to solve that simple issue; (2) I really prefer cfdisk (or ncurses stuffs) to fdisk or gparted; fdisk is too hard to use, and gparted is not usable when there is no GUI. -- [[User:triplc|triplc]] Sep 23 2015</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401724Talk:Master Boot Record2015-09-24T23:07:22Z<p>Triplc: why i add this session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)<br />
::>>Reason: Out of scope, see fdisk which does "erase" just fine<br />
::Well, in my case, I "dd" a window installation to that USB, which makes USB become "gpt" type. After that I do not know how to use fdisk to "erase" that. So I had to "dd" and then "cfdisk" to revive that USB. Anyway, maybe I am not so pro in Linux.<br />
::Anyway, whether "fdisk" or not, there should be some guide that tell how to reset the disk MBR. (Sep 22, 2015)<br />
:::The "guide" depends on your favourite [[Partitioning#Partitioning_tools|partitioning tool]]. All the linked pages explain how to create a new "partition table" (more general than just MBR). In all the ''*disk'' tools, this is done with the {{ic|o}} command. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 15:27, 24 September 2015 (UTC)<br />
::::Thanks for the clarifications. I think I understand your points. However: (1) I think that there should be some <i>practical</i> guide, not just links to other websites; in fact, I took me quite a time to read/try... just to solve that simple issue; (2) I really prefer cfdisk (or ncurses stuffs) to fdisk or gparted; fdisk is too hard to use, and gparted is not usable when there is no GUI. -- [[User:triplc|triplc]] Sep 23 2015</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401723Talk:Master Boot Record2015-09-24T23:07:03Z<p>Triplc: why i add this session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)<br />
::>>Reason: Out of scope, see fdisk which does "erase" just fine<br />
::Well, in my case, I "dd" a window installation to that USB, which makes USB become "gpt" type. After that I do not know how to use fdisk to "erase" that. So I had to "dd" and then "cfdisk" to revive that USB. Anyway, maybe I am not so pro in Linux.<br />
::Anyway, whether "fdisk" or not, there should be some guide that tell how to reset the disk MBR. (Sep 22, 2015)<br />
:::The "guide" depends on your favourite [[Partitioning#Partitioning_tools|partitioning tool]]. All the linked pages explain how to create a new "partition table" (more general than just MBR). In all the ''*disk'' tools, this is done with the {{ic|o}} command. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 15:27, 24 September 2015 (UTC)<br />
:::Thanks for the clarifications. I think I understand your points. However: (1) I think that there should be some <b>practical</b> guide, not just links to other websites; in fact, I took me quite a time to read/try... just to solve that simple issue; (2) I really prefer cfdisk (or ncurses stuffs) to fdisk or gparted; fdisk is too hard to use, and gparted is not usable when there is no GUI. -- [[User:triplc|triplc]] Sep 23 2015</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401722Talk:Master Boot Record2015-09-24T23:03:39Z<p>Triplc: why i add this session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)<br />
::>>Reason: Out of scope, see fdisk which does "erase" just fine<br />
::Well, in my case, I "dd" a window installation to that USB, which makes USB become "gpt" type. After that I do not know how to use fdisk to "erase" that. So I had to "dd" and then "cfdisk" to revive that USB. Anyway, maybe I am not so pro in Linux.<br />
::Anyway, whether "fdisk" or not, there should be some guide that tell how to reset the disk MBR. (Sep 22, 2015)<br />
:::The "guide" depends on your favourite [[Partitioning#Partitioning_tools|partitioning tool]]. All the linked pages explain how to create a new "partition table" (more general than just MBR). In all the ''*disk'' tools, this is done with the {{ic|o}} command. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 15:27, 24 September 2015 (UTC)<br />
:::Thanks for the clarifications. I think I understand your points. However: (1) I think that there should be some guide, not just links to other websites; in fact, I took me quite a time to read/try... just to solve that simple issue; (2) I really prefer cfdisk (or ncurses stuffs) to fdisk or gparted; fdisk is too hard to use, and gparted is not usable when there is no GUI. -- [[User:triplc|triplc]] Sep 23 2015</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401668Talk:Master Boot Record2015-09-24T15:12:43Z<p>Triplc: why i add this session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)<br />
::>>Reason: Out of scope, see fdisk which does "erase" just fine<br />
::Well, in my case, I "dd" a window installation to that USB, which makes USB become "gpt" type. After that I do not know how to use fdisk to "erase" that. So I had to "dd" and then "cfdisk" to revive that USB. Anyway, maybe I am not so pro in Linux.<br />
::Anyway, whether "fdisk" or not, there should be some guide that tell how to reset the disk MBR. (Sep 22, 2015)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401628Talk:Master Boot Record2015-09-24T09:31:01Z<p>Triplc: why create new session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). Sorry for my English. (Sep 22, 2015)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401627Talk:Master Boot Record2015-09-24T09:29:43Z<p>Triplc: why create new session</p>
<hr />
<div>==Add session: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). (Sep 22, 2015)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401626Talk:Master Boot Record2015-09-24T09:29:21Z<p>Triplc: why create new session</p>
<hr />
<div>==Add: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like <b>ms-sys</b>, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). (Sep 22, 2015)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401625Talk:Master Boot Record2015-09-24T09:29:08Z<p>Triplc: why create new session</p>
<hr />
<div>==Add: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stops working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like ms-sys, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff). (Sep 22, 2015)</div>Triplchttps://wiki.archlinux.org/index.php?title=Talk:Master_Boot_Record&diff=401624Talk:Master Boot Record2015-09-24T09:28:00Z<p>Triplc: why create new session</p>
<hr />
<div>==Add: Create A New MBR for a USB stick==<br />
<br />
:I create this "guide" because I think it is needed.<br />
:My USB stop working and I need to recreate the MBR and so I followed the "guide" in this page with those AUR like ms-sys, but it did not work. At last I found that it is simple with cfdisk/mkfs.vfat (no need AUR stuff).</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401623Master Boot Record2015-09-24T09:24:37Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device by using <b>fdisk</b> ({{Pkg|util-linux}}):<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> ({{Pkg|util-linux}}) to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partition(s) as you need. You might need to set the [[Partitioning|partition]] type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> ({{Pkg|dosfstools}}) to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows (with the volume name set to MYUSB):<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401622Master Boot Record2015-09-24T09:21:44Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device by using <b>fdisk</b> ({{Pkg|util-linux}}):<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> ({{Pkg|util-linux}}) to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partitions as you need. You might need to set the [[Partitioning|partition]] type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> ({{Pkg|dosfstools}}) to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows (with the volume name set to MYUSB):<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401621Master Boot Record2015-09-24T09:21:00Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device by using <b>fdisk</b> ({{Pkg|util-linux}}):<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> ({{Pkg|util-linux}}) to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partitions as you need. You might need to set the [[Partitioning|partition]] type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> ({{Pkg|dosfstools}}) to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows:<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401620Master Boot Record2015-09-24T09:19:47Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device by using <b>fdisk</b> {{Pkg|util-linux}}:<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> {{Pkg|util-linux}} to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partitions as you need. You might need to set the [[Partitioning|partition]] type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> {{Pkg|dosfstools}} to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows:<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401619Master Boot Record2015-09-24T09:18:51Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device by using <b>fdisk</b> {{Pkg|util-linux}}:<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> {{Pkg|util-linux}} to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partitions as you need. You might need to set the partition type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> {{Pkg|dosfstools}} to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows:<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplchttps://wiki.archlinux.org/index.php?title=Master_Boot_Record&diff=401618Master Boot Record2015-09-24T09:13:38Z<p>Triplc: how to create new MBR for usb</p>
<hr />
<div>[[Category:Boot process]]<br />
[[Category:Mainboards and BIOS]]<br />
[[Category:System recovery]]<br />
[[es:Master Boot Record]]<br />
[[hu:Master Boot Record]]<br />
[[it:Master Boot Record]]<br />
[[ja:Master Boot Record]]<br />
[[ru:Master Boot Record]]<br />
[[zh-CN:Master Boot Record]]<br />
{{Related articles start}}<br />
{{Related|Arch boot process}}<br />
{{Related|GUID Partition Table}}<br />
{{Related|Partitioning}}<br />
{{Related|Unified Extensible Firmware Interface}}<br />
{{Related articles end}}<br />
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device's partition table.<br />
<br />
{{Note|As a newer partitioning scheme, the [[GUID Partition Table]] (part of the [[Unified Extensible Firmware Interface]] specification) can be used also on BIOS systems via a [[wikipedia:GUID_Partition_Table#Legacy_MBR_.28LBA_0.29|protective MBR]]. GPT solves some legacy problems with MBR but also may have compatibility problems. Read more on [[GUID Partition Table#About the Master Boot Record]].}}<br />
<br />
== Boot process ==<br />
<br />
Booting is a multi-stage process. Most PCs today initialize system devices with firmware called the [http://en.wikipedia.org/wiki/BIOS BIOS] (Basic Input/Output System), which is typically stored in a dedicated ROM chip on the system board. After system devices have been initialized, the BIOS looks for the bootloader on the MBR of the first recognized storage device (hard disk drive, solid state drive, CD/DVD drive, USB drive...) or the first partition of the device. It then executes that program. The bootloader reads the partition table, and is then capable of loading the operating system(s). Common GNU/Linux bootloaders include [[GRUB]] and [[Syslinux]].<br />
<br />
== History == <br />
<br />
The MBR consists of a short piece of assembly code (the initial bootloader &ndash; 446 bytes), a partition table for the 4 primary partitions (16 bytes each) and a ''sentinel'' (0xAA55).<br />
<br />
The "Conventional" Windows/DOS MBR bootloader code will check the partition table for one and only one ''active'' partition, read X sectors from this partition and then transfer control to the operating system. The Windows/DOS bootloader can ''not'' boot an Arch Linux partition because it is not designed to load the Linux kernel, and it can only cater for an ''active'', ''primary'' partition (which GRUB safely ignores).<br />
<br />
The [[GRUB|GRand Unified Bootloader (GRUB)]] is the de facto standard bootloader for GNU/Linux, and users are recommended to install it on the MBR to allow booting from ''any'' partition, whether it be primary or logical.<br />
<br />
== Backup and restoration ==<br />
<br />
Because the MBR is located on the disk it can be backed up and later recovered.<br />
<br />
To backup the MBR:<br />
<br />
# dd if=/dev/sda of=/path/mbr-backup bs=512 count=1<br />
<br />
Restore the MBR:<br />
<br />
# dd if=/path/mbr-backup of=/dev/sda bs=512 count=1<br />
<br />
{{Warning|Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see their respective pages as they also employ the [http://www.pixelbeat.org/docs/disk/ DOS compatibility region]: [[GRUB]] or [[Syslinux]].}}<br />
<br />
To erase the MBR (may be useful if you have to do a full reinstall of another operating system) only the first 446 bytes are zeroed because the rest of the data contains the partition table:<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=446 count=1<br />
<br />
== Restoring a Windows boot record ==<br />
<br />
By convention (and for ease of installation), Windows is usually installed on the first partition and installs its partition table and reference to its bootloader to the first sector of that partition. If you accidentally install a bootloader like GRUB to the Windows partition or damage the boot record in some other way, you will need to use a utility to repair it. Microsoft includes a boot sector fix utility {{Ic|FIXBOOT}} and an MBR fix utility called {{Ic|FIXMBR}} on their recovery discs, or sometimes on their install discs. Using this method, you can fix the reference on the boot sector of the first partition to the bootloader file and fix the reference on the MBR to the first partition, respectively. After doing this you will have to [[GRUB#Bootloader installation|reinstall GRUB]] to the MBR as was originally intended (that is, the GRUB bootloader can be assigned to chainload the Windows bootloader).<br />
<br />
If you wish to revert back to using Windows, you can use the {{Ic|FIXBOOT}} command which chains from the MBR to the boot sector of the first partition to restore normal, automatic loading of the Windows operating system.<br />
<br />
Of note, there is a Linux utility called {{Ic|ms-sys}} (package {{AUR|ms-sys}} in AUR) that can install MBR's. However, this utility is only currently capable of writing new MBRs (all OS's and file systems supported) and boot sectors (a.k.a. boot record; equivalent to using {{Ic|FIXBOOT}}) for FAT file systems. Most LiveCDs do not have this utility by default, so it will need to be installed first, or you can look at a rescue CD that does have it, such as [http://partedmagic.com/ Parted Magic].<br />
<br />
First, write the partition info (table) again by:<br />
<br />
# ms-sys --partition /dev/sda1<br />
<br />
Next, write a Windows 2000/XP/2003 MBR:<br />
<br />
# ms-sys --mbr /dev/sda # Read options for different versions<br />
<br />
Then, write the new boot sector (boot record):<br />
<br />
# ms-sys -(1-6) # Read options to discover the correct FAT record type<br />
<br />
{{Ic|ms-sys}} can also write Windows 98, ME, Vista, and 7 MBRs as well, see {{Ic|ms-sys -h}}.<br />
<br />
==TestDisk MBRCode==<br />
<br />
{{Pkg|testdisk}} from the [[official repositories]] can write the MBR with its own [http://www.cgsecurity.org/wiki/Menu_MBRCode code] (which should be able to boot Windows). The package is also included in the installation media.<br />
<br />
==Create A New MBR for a USB stick==<br />
<br />
You might need to create a new MBR for your USB stick (which is convenient to copy files between your Linux computer and your PC), maybe because of virus or something that make it unusable.<br />
<br />
1, Plug the USB stick in and check the name of device:<br />
<br />
# fdisk -l<br />
<br />
2, Erase the old MBR. For example, if your USB device is /dev/sdd, then erase the first 512 bytes of that device. IMPORTANT NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
# dd if=/dev/zero of=/dev/sdd bs=512 count=1<br />
<br />
3, Use the <b>cfdisk</b> {{package|cfdisk}} to create a new MBR (select "dos" when <b>cfdisk</b> asks you), and then make one (or some) partitions as you need. You might need to set the partition type as "c" - FAT32 (LBA).<br />
<br />
# cfdisk /dev/sdd<br />
<br />
4, Use <b>mkfs.vfat</b> {{package|dosfstools}} to create FAT partition that Windows computers can access. For example, earlier you used <b>cfdisk</b> to create partition /dev/sdd1 as type "c" (FAT32 LBA), then the command to format it is as follows:<br />
<br />
# mkfs.vfat -n MYUSB /dev/sdd1<br />
<br />
NOTE: MAKE SURE YOU SELECT THE CORRECT DEVICE.<br />
<br />
==See also==<br />
<br />
* Wikipedia article: [[wikipedia:Master boot record|Master boot record]]<br />
* [http://kb.iu.edu/data/aijw.html What is a Master Boot Record (MBR)?]</div>Triplc