flat assembler
Message board for the users of flat assembler.

Index > Linux > [fasm2] mpv wrapper for VAAPI example

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 97
Location: Brazil
Jessé 04 Apr 2026, 22:06
This is a simple idea I had, based on a necessity, which I think many Linux users know beforehand: playing high resolution, high bit rate HEVC files on Linux kind of s..[k], if you know what I mean: you set it right, then in another hardware is broken, or came an update and it stops working at you favorite (most probably only option) player.
I've found a setting over mpv player, that keeps delivering it good across platforms I've tested, so, I decided to turn it into a simple application that sets everything properly and play the video using hardware decoding!

Code:
; mpv player wrapper for VAAPI mode
;
; Also ensures rotation disabled, and scale player down to 0.4
; at start
;
format ELF64 executable 3 at 1 shl 36

include 'fastcall_v1.inc'
include 'stdmacros.inc'
include 'stdio.inc'

_code   param:
            .hw.dec     db '--hwdec=vaapi', 0
            .vo.scale   db '--vo-vaapi-scaling=hq', 0
            .wnd.scale  db '--window-scale=0.4', 0
            .wnd.resize db '--auto-window-resize=no', 0
            .vid.rotate db '--video-rotate=0', 0
            .ply.mode   db '--player-operation-mode=pseudo-gui', 0

        align 4
        Start entry:    endbr64

                        ; Modify first parameter to 'mpv'
                        mov         r10, [rsp+8]
                        mov         [r10], dword 'mpv'

                        ; Count passed parameters
                        mov         ecx, 6 + 3 + 1  ; include extra rep to store NULL pointer
                        add         ecx, [rsp]      ; plus extra for 16-byte alignment

                        ; Calculate needed stack space
                        ; while preserving 16-byte align
                        shl         ecx, 3
                        and         cl, 0F0h

                        ; Save original external parameters'
                        ; pointer and alloc stack space
                        lea         rsi, [rsp+8]
                        sub         rsp, rcx

                        ; Create new argv[] with wrapper parameters
                        mov         rdi, rsp
                        mov         r11, rsp
                        movsq
                        lea         rax, [param.hw.dec]
                        stosq
                        lea         rax, [param.vo.scale]
                        stosq
                        lea         rax, [param.wnd.scale]
                        stosq
                        lea         rax, [param.wnd.resize]
                        stosq
                        lea         rax, [param.vid.rotate]
                        stosq
                        lea         rax, [param.ply.mode]
                        stosq
                        shr         ecx, 3
                        sub         ecx, 9
                        rep         movsq

                        ; Show full command line
                        printf(<27,"[1;94m","Wrapper command line: ",27,"[1;33m%s ",27,"[0;36m%s", \
                            " %s %s %s %s %s",27,"[0;32m ",0>, [r11], [r11+8], [r11+16], \
                            [r11+24], [r11+32], [r11+40], [r11+48]);

                        ; Parse and show user commands
                        lea         rbx, [rsp+56]
                @@      test        [rbx], qword -1
                        jz          @f
                        printf("%s ", [rbx]);
                        add         rbx, 8
                        jmp         @b

                        ; Append new line at the end, and reset cli colors
                @@      printf(<27,"[0m",10,0>);

                        ; Exchange place with mpv application with the new
                        ; command line
                        execvp("mpv", rsp);

                        ; If returned, something went wrong
                        perror("Error lauching mpv player");
                        exit(-1);
    


Of course, this needs mpv player installed on your system.
Also, I haven't included a mime type creator to this wrapper application ('cause I don't know how to do it yet), so, you'll probably need to do it by hand. Kind of easy to do on Plasma, by the way.
Another point is that it ensures no rotation on the output. Some players can play DJI or GoPro videos, but they play it upside down. Or with no sound. With this wrapper, sound is there, as well as correct video orientation.
And, finally, mpv command line is kind of buggy, so, the order of the parameters, if changed, may render them unapplied.

As mostly with my examples, all of those beautiful include files can be found here.

Not all people will find it useful, unless you have a GoPro or DJI camera file which seems to not be playable on Linux.
I also must mention that this modifier uses VAAPI, which is supported by either Intel or AMD GPUs, not Nvidia. So, if you have a 100% Nvidia GPU setup, you'll probably need to change it to VDPAU mode, which I haven't tested.
Intel GPUs need 'intel-media-driver' to be installed as well.

Cheers!


Description: Easily install it with:

sudo tar -xvzf mpv-vaapi.tar.gz -C /

Download
Filename: mpv-vaapi.tar.gz
Filesize: 1.04 KB
Downloaded: 26 Time(s)


_________________
jesse6
Post 04 Apr 2026, 22:06
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20937
Location: In your JS exploiting you and your system
revolution 04 Apr 2026, 22:42
Installing direct to root folder is risky. I couldn't do it without my manager entering the password for sudo. Does it really need root permission?

Am I right in thinking it does a similar action to this bash script?
Code:
#!/bin/bash
params="--hwdec=vaapi --vo-vaapi-scaling=hq --window-scale=0.4 --auto-window-resize=no --video-rotate=0 --player-operation-mode=pseudo-gui"
echo -e "\e[1;94mWrapper command line: \e[1;33mmpv \e[0;36m $params \e[0;32m $@ \e[0m"
mpv $params "$@"    
If the "Wrapper command line" output is not needed then it can be an alias.
Code:
alias mpv-vaapi='mpv --hwdec=vaapi --vo-vaapi-scaling=hq --window-scale=0.4 --auto-window-resize=no --video-rotate=0 --player-operation-mode=pseudo-gui'    
Post 04 Apr 2026, 22:42
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 97
Location: Brazil
Jessé 04 Apr 2026, 22:56
I have deleted the following section, because I think maybe this time people will understand the point. But, anyways, there it is:


--------------------------------------------------

FAQ for the unfocused ones, who can't find the real purpose of my posts yet:
Quote:

- Have you ever think of just create an alias for it instead of an application?
Yes.

- This is useless, you can just change the command line arguments on that mpv.desktop file!
For sure, but, will it be fun?

- And how about a /bin/sh shell script?
Same as above.

- Are you actually using this?
Yes!

- You're using root, this is DANGEROUS!
We must tell Linus to delete the 'root' account from all Linux's O.S.es, then.


Hope that I've answered their (dull) questions, let's go into the simple example:

-----------------------------------------------------------

Hope it helps.

Thanks.

Edit: just include your question on my FAQ statement...


Last edited by Jessé on 04 Apr 2026, 23:04; edited 1 time in total
Post 04 Apr 2026, 22:56
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 97
Location: Brazil
Jessé 04 Apr 2026, 23:00
Also, I must mention that most (if not all) of those 'great and/or friendly' O.S.es out there has a lot of "wrappers" (or something) to ease the end user experience.
And they're great because of this. Must mention BigLinux here, maybe Linux Mint as well.
People writing code for things that could be aliased, or typed in a terminal, or made in python/shell script, but not everyone wants to do it that way!
Post 04 Apr 2026, 23:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.