Improve video playback performance including YouTube (ytfzf) revisions

Go back to topic: Improve video playback performance including YouTube (ytfzf)

  1. v14 anchor; v14 full version
  2. v13 anchor; v13 full version
  3. v12 anchor; v12 full version
  4. v11 anchor; v11 full version
  5. v10 anchor; v10 full version
  6. v9 anchor; v9 full version
  7. v8 anchor; v8 full version
  8. v7 anchor; v7 full version
  9. v6 anchor; v6 full version
  10. v5 anchor; v5 full version
  11. v4 anchor; v4 full version
  12. v3 anchor; v3 full version
  13. v2 anchor; v2 full version

Revision #14

Edited on
2024-01-29
Edited by user
Bearillo
This guide will show you how to install the `mpv` player and use it with maximum performance (in own tests I saw video **performance improvements of up to 600%** !). It will assume that you are using debian-12 as a template (other templates should also work, however) and that you play videos in DVMs; I recommend looking into [this solution](https://forum.qubes-os.org/t/poor-mans-pre-loaded-dispvm-for-faster-start/13799) for caching disposables to decrease startup time. I also recommend looking into [one](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/) [of](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/2) [these](https://forum.qubes-os.org/t/opening-all-files-in-disposable-qube/4674) solutions to have files, including video files, always start in DVMs if you "open" them in your file manager. This guide will show you how to install the `mpv` player and use it with maximum performance (in own tests I saw video **performance improvements of up to 600%** !). It will assume that you are using debian-12 as a template (other templates should also work, however) and that you play videos in DVMs; I recommend looking into [this solution](https://forum.qubes-os.org/t/poor-mans-pre-loaded-dispvm-for-faster-start/13799) for caching disposables to decrease startup time (or [this much more elaborate take on it](https://gist.github.com/UndeadDevel/82e5f61c9a5065ab9fc5d23a74ae5045), verify cryptographically via [this repo](https://github.com/UndeadDevel/qubes-tools)). I also recommend looking into [one](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/) [of](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/2) [these](https://forum.qubes-os.org/t/opening-all-files-in-disposable-qube/4674) solutions to have files, including video files, always start in DVMs if you "open" them in your file manager.

Revision #13

Edited on
2024-01-24
Edited by user
Bearillo
Also available as a SaltStack simple receipy with didactic dom0 step-by-setp at: ( https://codeberg.org/brunoschroeder/qubes-salt-video-playback ) Also available as a simple SaltStack recipe with didactic dom0 step-by-step at: ( https://codeberg.org/brunoschroeder/qubes-salt-video-playback ).

Revision #12

Edited on
2024-01-24
Edited by user
bruno_schroeder
Also available as a SaltStack simple receipy with didactic dom0 step-by-setp at: ( https://codeberg.org/brunoschroeder/qubes-salt-video-playback )

Revision #11

Edited on
2023-11-10
Edited by user
Bearillo
This guide will show you how to install the `mpv` player and use it with maximum performance (in own tests I saw video **performance improvements of up to 600%** !). It will assume that you are using debian-12 as a template (other templates should also work, however) and that you play videos in DVMs; I recommend looking into [this solution](https://forum.qubes-os.org/t/poor-mans-pre-loaded-dispvm-for-faster-start/13799) for caching disposables to increase startup time. I also recommend looking into [one](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/) [of](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/2) [these](https://forum.qubes-os.org/t/opening-all-files-in-disposable-qube/4674) solutions to have files, including video files, always start in DVMs if you "open" them in your file manager. Since not everyone is interested in YouTube and the YouTube solution presented here is admittedly a bit unpolished due to bugs in `mpv` as well as insufficiently up-to-date packages in debian stable, I will present separately the necessary steps to set up `mpv` for local video playback only and `mpv` with [ytfzf](https://github.com/pystardust/ytfzf), which basically lets you search for videos on YouTube and then stream them without having to actually launch a browser and visit the bloated YT page. This guide will show you how to install the `mpv` player and use it with maximum performance (in own tests I saw video **performance improvements of up to 600%** !). It will assume that you are using debian-12 as a template (other templates should also work, however) and that you play videos in DVMs; I recommend looking into [this solution](https://forum.qubes-os.org/t/poor-mans-pre-loaded-dispvm-for-faster-start/13799) for caching disposables to decrease startup time. I also recommend looking into [one](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/) [of](https://forum.qubes-os.org/t/opening-urls-files-in-other-qubes/19026/2) [these](https://forum.qubes-os.org/t/opening-all-files-in-disposable-qube/4674) solutions to have files, including video files, always start in DVMs if you "open" them in your file manager. Since not everyone is interested in YouTube and the YouTube solution presented here is admittedly a bit unpolished due to bugs in `mpv` as well as insufficiently up-to-date packages in debian stable, I will present separately the necessary steps to set up `mpv` for local video playback only and `mpv` with [ytfzf](https://github.com/pystardust/ytfzf), which basically lets you search for YouTube videos using the Invidious API and then stream them without having to actually launch a browser; it's also compatible with Peertube and Odysee.
Into this file copy the following (copy this code into that VM's clipboard and then into Vim, e.g. by using your terminal's paste functionality, e.g. Edit - Paste in the Menu): Into this file copy the following (copy this code into that VM's clipboard and then into Vim, e.g. by using your terminal's paste functionality, e.g. Edit - Paste in the menu):
With the next version (presumably 2.6.2) there will also be the possibility of getting rid of the preview panel altogether by using the following alias instead of the one above: The next version (after 2.6.1) will allow getting rid of the preview panel altogether by using the following alias instead of the one above (that setting can also be put into `~/.config/ytfzf/conf.sh`):
To launch the ytfzf program even more quickly with less fuss about the thumbnails, use a cached, named, networked DVM; find out the size of the window such that the separate thumbnail still fully fits on screen (e.g. by launching `ytfzf -t -T mpv video` and positioning the thumbnail window next to the terminal window while resizing the terminal window and noting the size down); you may also have to go to the Window Manager Tweaks app of your QubesOS installation and in the tab "Placement" move the slider further left until the window manager automatically places the thumbnail window in the "free space" of the workspace. To launch the ytfzf program even more quickly with better configured thumbnails, use a cached, named, networked DVM; find out the size the terminal window should have such that the separate thumbnail still fully fits on screen (e.g. by launching `ytfzf -t -T mpv video` and positioning the thumbnail window next to the terminal window while resizing the terminal window and noting the final size down); you may also have to go to the Window Manager Tweaks app of your QubesOS installation and in the tab "Placement" move the slider further left until the window manager automatically places the thumbnail window in the "free space" of the workspace when created.
In this file put the following (replace the geometry values with your recorded values and either remove the --ytdl-pref option or customize it for your needs; the one you see there basically tries to pick the best video and audio combination available that does not exceed 1080p and that is not HDR, when you launch without `Alt+F`, e.g. with `Enter` or `Alt+E`; you may also want to change the options analogously as above for the aliases once the next ytfzf version - presumably 2.6.2 - is released): In this file put the following (replace the geometry values with your recorded values and either remove the --ytdl-pref option or customize it for your needs; the one you see there basically tries to pick the best video and audio combination available that does not exceed 1080p and that is not HDR when you launch without `Alt+F`, e.g. with `Enter` or `Alt+E`):

Revision #10

Edited on
2023-11-10
Edited by user
Bearillo
Since not everyone is interested in YouTube and the YouTube solution presented here is admittedly a bit unpolished due to bugs in `mpv` and lacking features in `ytfzf` as well as insufficiently up-to-date packages in debian stable, I will present separately the necessary steps to set up `mpv` for local video playback only and `mpv` with [ytfzf](https://github.com/pystardust/ytfzf), which basically lets you search for videos on YouTube and then stream them without having to actually launch a browser and visit the bloated YT page. Since not everyone is interested in YouTube and the YouTube solution presented here is admittedly a bit unpolished due to bugs in `mpv` as well as insufficiently up-to-date packages in debian stable, I will present separately the necessary steps to set up `mpv` for local video playback only and `mpv` with [ytfzf](https://github.com/pystardust/ytfzf), which basically lets you search for videos on YouTube and then stream them without having to actually launch a browser and visit the bloated YT page.
See the man page (`man ytfzf`) for more controls and options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself; the only way I've gotten them to work acceptably on my machine (and without installing additional packages) is by using: `-lt -T mpv --preview-side=down` as options and then usually I have to `Ctrl+P` once to fix misalignment of the infos. The thumbnail previews will open in a separate window, however, which I then drag to the bottom right and "toggle above" (Qubes Xfce Window Manager keyboard shortcut). One can automatically apply these options by setting an alias in the `.bashrc` file of the dvm template: See the man page (`man ytfzf`) for more controls and options, but note that good looking thumbnails (option `-t`) either need additional non-standard-repo packages to be installed so they can be displayed in the terminal itself or will be displayed in a separate window: the only way I've gotten them to work acceptably on my machine (and without installing additional packages) is by using: `-lt -T mpv --preview-side=down` as options and then usually I have to `Ctrl+P` once to fix misalignment of the infos (this bug has been fixed for the next version). One can automatically apply these options by setting an alias in the `.bashrc` file of the dvm template:
``` With the next version (presumably 2.6.2) there will also be the possibility of getting rid of the preview panel altogether by using the following alias instead of the one above: ``` alias ytfzf='preview_window_width=0% ytfzf -lt -T mpv'
In this file put the following (replace the geometry values with your recorded values and either remove the --ytdl-pref option or customize it for your needs; the one you see there basically tries to pick the best video and audio combination available that does not exceed 1080p and that is not HDR, when you launch without `Alt+F`, e.g. with `Enter` or `Alt+E`): In this file put the following (replace the geometry values with your recorded values and either remove the --ytdl-pref option or customize it for your needs; the one you see there basically tries to pick the best video and audio combination available that does not exceed 1080p and that is not HDR, when you launch without `Alt+F`, e.g. with `Enter` or `Alt+E`; you may also want to change the options analogously as above for the aliases once the next ytfzf version - presumably 2.6.2 - is released):
Exec=gnome-terminal --title=YTFzF --geometry=211x29 -- ytfzf -lts -T mpv --preview-side=bottom --ytdl-pref='ba+bv[height<=?1080][dynamic_range=?SDR]/b[height<=?1080][dynamic_range=?SDR]' %U Exec=gnome-terminal --title=YTFzF --geometry=211x29 -- ytfzf -lts -T mpv --preview-side=down --ytdl-pref='ba+bv[height<=?1080][dynamic_range=?SDR]/b[height<=?1080][dynamic_range=?SDR]' %U

Revision #9

Edited on
2023-11-10
Edited by user
Bearillo
<big>Bonus</big> To launch the ytfzf program even more quickly with less fuss about the thumbnails, use a cached, named, networked DVM; find out the size of the window such that the separate thumbnail still fully fits on screen (e.g. by launching `ytfzf -t -T mpv video` and positioning the thumbnail window next to the terminal window while resizing the terminal window and noting the size down); you may also have to go to the Window Manager Tweaks app of your QubesOS installation and in the tab "Placement" move the slider further left until the window manager automatically places the thumbnail window in the "free space" of the workspace. Then in your DVM's dvm template run: ``` sudo mkdir -p /usr/local/share/applications sudo vi /usr/local/share/applications/ytfzf.desktop ``` In this file put the following (replace the geometry values with your recorded values and either remove the --ytdl-pref option or customize it for your needs; the one you see there basically tries to pick the best video and audio combination available that does not exceed 1080p and that is not HDR, when you launch without `Alt+F`, e.g. with `Enter` or `Alt+E`): ``` [Desktop Entry] Type=Application Name=YouTube FzF Comment=Watch YouTube videos without a browser Icon=mpv Exec=gnome-terminal --title=YTFzF --geometry=211x29 -- ytfzf -lts -T mpv --preview-side=bottom --ytdl-pref='ba+bv[height<=?1080][dynamic_range=?SDR]/b[height<=?1080][dynamic_range=?SDR]' %U Terminal=true Categories=AudioVideo;Audio;Video;Player;TV; Keywords=youtube;ytfzf;yt-dlp; ``` Save and exit (`:x`) and shut down the dvm template. Now open your Qubes Manager and edit the settings of your named DVM based on that template: 1. Go to the "Applications" tab 2. Press "Refresh Applications" and wait for the process to complete 3. Find YouTube FzF in the left list at the bottom and push it over to the right list using the `>` button 4. Press OK Done! From now on you can instantly launch a YT search by pressing `Alt+F3` and typing `youtube` or `ytf` and hitting `Enter`; it will pop up the correctly sized terminal of your cached DVM with a search prompt ready; the thumbnail window will automatically be placed in a useful way and the videos you stream will have the format restrictions listed in the desktop file.

Revision #8

Edited on
2023-11-10
Edited by user
Bearillo
* `sudo apt install mpv` ``` sudo apt install mpv ```
Save your changes (press `Esc` and enter `:x` and press `Enter`) and shut down the template. This completes the guide for those who don't care about YouTube. Enjoy much improved video playback performance! Save your changes (press `Esc` and enter `:x` and press `Enter`) and shut down the template. **This completes the guide for those who don't care about YouTube.** Enjoy much improved video playback performance!
<big>Addendum</big> <big>Addendum: a short ytfzf tutorial</big>

Revision #7

Edited on
2023-11-10
Edited by user
Bearillo
You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. You can also press `Alt+D` to download the video instead (and then play it with `mpv video_file_name.webm`) or `Alt+F` to list available formats (e.g. 1080p) for that video; see the man page (`man ytfzf`) for more options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself. You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. Launching with the `-l` option is useful as `ytfzf` will return to the list of videos found after playing a video. Useful keyboard shortcuts: * `Alt+D` downloads the video instead of playing it (you can then play it with `mpv video_file_name.webm`) * `Alt+F` lists available formats (e.g. 1080p) for that video (you can then select a format and play it with `Enter`) * `Alt+E` launches the video in `mpv` as a detached process, which works best with the `-l` option as it retains the selection screen while the video is playing * `Ctrl+P` loads the next page of videos (the next 20 video titles by default) * `Ctrl+C` exits the program See the man page (`man ytfzf`) for more controls and options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself; the only way I've gotten them to work acceptably on my machine (and without installing additional packages) is by using: `-lt -T mpv --preview-side=down` as options and then usually I have to `Ctrl+P` once to fix misalignment of the infos. The thumbnail previews will open in a separate window, however, which I then drag to the bottom right and "toggle above" (Qubes Xfce Window Manager keyboard shortcut). One can automatically apply these options by setting an alias in the `.bashrc` file of the dvm template: ``` alias ytfzf='ytfzf -lt -T mpv --preview-side=down' ```

Revision #6

Edited on
2023-11-10
Edited by user
Bearillo

Revision #5

Edited on
2023-11-10
Edited by user
Bearillo
Add the following to the file (press 'i' to edit): Add the following to the file (press `i` to edit):
Save your changes (press `Esc` and enter ':x' + press `Enter`) and shut down the template. This completes the guide for those who don't care about YouTube. Enjoy much improved video playback performance! Save your changes (press `Esc` and enter `:x` and press `Enter`) and shut down the template. This completes the guide for those who don't care about YouTube. Enjoy much improved video playback performance!
First download the latest version of `yt-dlp` from [here](https://github.com/yt-dlp/yt-dlp/releases) in some Internet-connected DVM or AppVM (choose the `yt-dlp_linux` file and verify the checksum after downloading just in case); then copy this file to your `debian-12-dvm` using `qvm-copy`. First download the latest version of `yt-dlp` from [here](https://github.com/yt-dlp/yt-dlp/releases) in some Internet-connected DVM or AppVM (choose the `yt-dlp_linux` file and verify the checksum after downloading just in case; you can also verify the pgp signature on it if you want to be maximally secure; in that case you may want to create a separate dvm template to do the following in); then copy this file to your `debian-12-dvm` using `qvm-copy`.
vi .bashrc
In `bashrc` add the following line just in case: Then create a new file:
alias ytfzf='ytfzf --url-handler-opts="--vo=x11 --profile=sw-fast"' vi update-yt-dlp-and-ytfzf.sh
Save and exit and then create a new file: ``` vi install-update-yt-dlp-and-ytfzf.sh ```
cd Downloads rm -rf ytfzf cd ~/Downloads && rm -rf ytfzf &&
This will install the latest version of `ytfzf` as well as update `yt-dlp`. You should periodically run this script to update both `yt-dlp` and `ytfzf`. Run in the dvm-template for persistence or in the DVM itself on every start of that DVM. Make the script executable and run it once: ``` chmod +x update-yt-dlp-and-ytfzf.sh ./update-yt-dlp-and-ytfzf.sh ``` The above script will install the latest version of `ytfzf` as well as update `yt-dlp`. You should periodically run this script to update both `yt-dlp` and `ytfzf`. Run in the dvm-template for persistence or in the DVM itself on every start of that DVM.

Revision #4

Edited on
2023-11-09
Edited by user
Bearillo
Addendum: You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. You can also press `Alt+D` to download the video instead (and then play it with `mpv video_file_name.webm`); see the man page (`man ytfzf`) for more options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself. <big>Addendum</big> You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. You can also press `Alt+D` to download the video instead (and then play it with `mpv video_file_name.webm`) or `Alt+F` to list available formats (e.g. 1080p) for that video; see the man page (`man ytfzf`) for more options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself.

Revision #3

Edited on
2023-11-09
Edited by user
Bearillo
In both cases (YouTube or not) we proceed to set `mpv` to always run with additional options, which will drastically improve playback performance: In both cases (YouTube or not) we proceed to set `mpv` to use a certain configuration, which will drastically improve playback performance:
sudo vi /usr/share/applications/mpv.desktop sudo vi /etc/mpv/mpv.conf
Here edit the line beginning with `Exec=`, forming it into the following (press 'i' to edit): Add the following to the file (press 'i' to edit):
Exec=mpv --player-operation-mode=pseudo-gui --vo=x11 --profile=sw-fast -- %U vo=x11 profile=sw-fast

Revision #2

Edited on
2023-11-09
Edited by user
Bearillo
You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. You can also press `Alt+D` to download the video instead (and then play it with `mpv video_file_name.webm`); see the man page (`man ytfzf`) for more options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself.You can use `ytfzf` simply like this: `ytfzf videos I like to watch` (use a maximized terminal). Then select one of the titles with the up/down arrow keys and press `Enter` to play it. You can also press `Alt+D` to download the video instead (and then play it with `mpv video_file_name.webm`); see the man page (`man ytfzf`) for more options, but note that thumbnails (option `-t`) are buggy and need additional packages to be installed to be displayed in the terminal itself. Credits: @rustybird @tanky0u @balko for making me aware of mpv and ytfzf!