Announcement

Collapse
No announcement yet.

Announcement

Collapse
No announcement yet.

[Script] Auto frame rate for X96max ATV (and other clones)

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Script] Auto frame rate for X96max ATV (and other clones)

    Tricky try to automatically switch frame rate according to played video, on script only basis. Proof-of-concept, surely there are better approaches (not talking about digging kernel...).


    What it does:
    • Acts as a daemon, basically monitoring if some video is played, tries to get its framerate, and changes display mode accordingly.

    What's needed:
    • Root (Magisk)
    • Busybox (Magisk module)
    • 1080p or 2160p setup (only resolutions with 24/50/60 support)

    What to do:
    • Extract zip and copy 50afr to /data/adb/service.d (autostart place)
    • Give file exec perms from terminal:
      Code:
      chmod +x /data/adb/service.d/50afr
    • Either reboot device and let script work in the background, or launch script manually to see it at work. tip: -d switch shows some debug crap.

    Notes:
    • Startup resolution will be considered as default by script, the one it will go back to on video stop
    • Tested on most common players (VLC, MX Player...) and some free IPTVs. I didn't try Kodi though, but should work everywhere hardware video decoding is used anyway.
    • To update, just overwrite script. To remove, just delete script from where it is.
    • Of course, script can be autostarted via init.d too, as long as root and busybox are there.

    Advanced:

    Some variables can be adjusted on top of script:
    • SUPPORT_25_30 : 0 (disable) | 1 (enable) : Whether script can switch to 25hz and 30hz in addition to 24/50/60hz. Must be supported by TV. If disabled, 25/30fps will go to 50/60hz instead. Disabling also can save much useless blackouts (sync on double refresh rate barely hurts). Refresh rates such as 23.976, 29.97 and 59.94 are NOT supported and rounded to integer because only approximate fps can be caught.
    • DEFAULT_TIME : In seconds, how long to wait before going back to default display mode after video stop.
    • RETRIES : How many times script will look for current fps before considering it as reliable. Must be > 0 since video stop case checks 2 times if it's really stopped (1 try, 1 retry, at best). Recommended value is at least 2, depending on next option.
    • TRY_DELAY : In seconds, delay between each retry, can be decimal value. Know that app such as Youtube takes at least 3-4 seconds to stabilize. So, expected values are about RETRIES*TRY_DELAY=3 or 4. But it entirely depends on apps you're using, if streaming from network, your network speed and so on. Therefore trial and error can be a good way to find what suits you.
    I can only give you my best compromise for everyday use:
    Code:
    SUPPORT_25_30=1
    DEFAULT_TIME=3
    RETRIES=3
    TRY_DELAY=1
    Now it's up to you...


    Enjoy! (or not, and report, or not!)


    DOWNLOAD: afr_script.zip
    CHANGELOG:
    • 15/03/2019
      • Compatibility fixes, no functionality change, no need to update if script didn't stop to work
    • 01/03/2019
      • Fixed: Refresh rate change would cause box to go into deep sleep when HDMI-CEC enabled !!
      • Fixed: Preserve user defined scaling if any (Display -> Screen position)
    • 26/02/2019
      • Added custom delay for how long to wait before going back to default mode on video stop (DEFAULT_TIME)
      • Now aborting still active past thread(s). Dramatically reduces useless "switches in a row", especially between videos in sequence
    • 25/02/2019
      • More codecs detected, some older were obviously excluded (mpeg1/2...)
      • Better logging
    • 22/02/2019
      • Added (optional) 25/30hz support
      • Increased delays to prevent false positives
    • 21/02/2019
      • Added 24hz support
      • More reliable fps detection
    • 20/02/2019
      • Initial release
      • 50/60hz support
    Attached Files
    Last edited by zoelechat; 03-18-2019, 10:16.

    #2
    Good Job!
    Thanks for sharing!

    Neomode

    Comment


      #3
      hi zoelechat , nice work!

      Kodi 18 is woking on 4K and FHD. And it working better on 4K 60p 4:2:0 compared Amlogic AFR switcher script addon that can't switch 4K from 60/50p to 24p and showing black screen...

      I did some another.
      If reluctance to put magisk for 50afr (as I like for example)
      1. Installing from the play market Amlogic TV Box Tool and Busybox installer
      2. Install new Busybox with its symlinks from the application
      3. In Amlogic TV Box Tool, enable init.d support and Autostart
      4. Copy 50afr to the /etc/init.d folder and rename it to myscript.sh, give permission 755
      5. Restarting and enjoy...
      Last edited by A.S._id; 02-21-2019, 06:49.

      Comment


        #4
        Indeed Magisk is not mandatory, as long as busybox is available and that you can launch script as root in any way

        About 24hz, took me some time to figure it out, and it was worth to have a look at Amlogic sources. Actually chroma subsampling has to be set prior to display mode change: 4:4:4 will stay below 30hz range and 4:2:0 will stay above. e.g if you set 2160p60hz444 box will switch to 30p (=half), and in the opposite if you try to set 2160p24hz420 box will try to switch to... 48hz (=double, unsupported!) Hence black screen when blindly switching to 24hz from 50/60. Hope it's clear

        Custom kernel posted in other thread caused same black screen issue on 24hz (in addition to definitely break VP9 support...)

        Comment


          #5
          To be deleted
          Last edited by zoelechat; 02-21-2019, 17:49.

          Comment


            #6
            Yes, I'm know, I'm tried this custom kernel by anpaza from 4PDA But I don't understand why x96max or s905x2 can't support 4k2k 60p 4:4:4? I for laugh tried turn on NVidia Shield to my TV via the same hdmi cable and it working how to charm...

            Comment


              #7
              I'm not really expert in that components stuff, but I think it's gonna depend on several factors: HDMI version supported by box itself and TV (2.0, 2.1?), color bit depth (8, 10, 12bit?), HDR?
              Obviously 4k2k 60p 4:4:4 is supported, but only in 8-bit, and I guess everybody wants at least 10-bit/HDR. Also I wouldn't risk myself to compare these SoCs to 4x price Shield

              From source:
              Code:
              #    Please notice that 420 mode is valid for 2160p50/60hz
              #    and 2160p50/60hz 444/rgb mode only has 8bit deepcolor mode

              Comment


                #8
                Originally posted by zoelechat View Post
                I'm not really expert in that components stuff, but I think it's gonna depend on several factors: HDMI version supported by box itself and TV (2.0, 2.1?), color bit depth (8, 10, 12bit?), HDR?
                Obviously 4k2k 60p 4:4:4 is supported, but only in 8-bit, and I guess everybody wants at least 10-bit/HDR. Also I wouldn't risk myself to compare these SoCs to 4x price Shield

                From source:
                Code:
                # Please notice that 420 mode is valid for 2160p50/60hz
                # and 2160p50/60hz 444/rgb mode only has 8bit deepcolor mode
                Shield I gave as an example in order to eliminate possible inconsistencies of TV and cable. That is, if it (2160 60p 4:4:4 10bit) works on Shield, it means TV and cable support it.
                Now everything is clear

                Comment


                  #9
                  OK. I've read (translated!) comments on (living!) 4pda, and I tried to slightly improve script accordingly, in the limit of what's doable...

                  So, 25/30hz is now supported, it can be enabled setting SUPPORT_25_30=1 on top of script..
                  Overall delays have been increased to avoid too early switch, especially on video stop case (back to default). Should also prevent a bit of false positives, but no miracle expected

                  1st post attachment updated.
                  Last edited by zoelechat; 02-23-2019, 09:10.

                  Comment


                    #10
                    Added some tweaking documentation in "Advanced" section from 1st post. Attachment will be updated with "best compromise" values given at the bottom (previous ones obviously caused some troubles...). No other change.
                    Last edited by zoelechat; 02-22-2019, 23:42.

                    Comment


                      #11
                      Is it possible to add a mode for manual rate switching (like it's in script for kodi)?

                      Comment


                        #12
                        Originally posted by AlexBar View Post
                        Is it possible to add a mode for manual rate switching (like it's in script for kodi)?
                        You mean an automatic manual mode?
                        No need for any script for that, resolution change from terminal is already one liner.

                        Comment


                          #13
                          Originally posted by zoelechat View Post

                          You mean an automatic manual mode?
                          right

                          Originally posted by zoelechat View Post
                          No need for any script for that, resolution change from terminal is already one liner.
                          I can't do it if video is alredy started... The idea is like in Kodi script: you assign some keys on remote control, when video starts you can change the the rate to desiredvalue just by pressing one button.

                          Comment


                            #14
                            Ok, here's script:
                            Code:
                            echo 2160p50hz > /sys/class/display/mode
                            Done.

                            You can change 50hz to 60hz at will, and map it to some button the way you want

                            Comment


                              #15
                              But how I can map the button?

                              Comment

                              Working...
                              X