[Workaround] Slow unrar on Rpi4

Get help, report and discuss bugs.
Post Reply
Krmit
Posts: 1
Joined: 27 Dec 2020, 14:51

[Workaround] Slow unrar on Rpi4

Post by Krmit » 27 Dec 2020, 15:13

Hi,

similar to others I encounter horrible decompression performance of unrar on Rpi4 (Raspbian) for both unrar-free and unrar-nonfree. (We talk about hours vs seconds here.) Also building from source or using prebuild binaries from rarlabs leads to no improvoment. The setup is an Rpi4 HDD NAS.

Here is one workaround that works reliably and gets you datarates one would expect:
7z(ip) has a) unrar (rar 5) support and b) seemingly performs orders of magnitudes better on Rpi4 than the original unrar.
Unfortunately, you cannot just set 7z for unrar in the nzbget settings. Hence we use a little script that translates unrar command line to 7z and translates output back into what unrar would print. The script below does the bare minimum to make nzbget happy. For example error messages are not translated. If it fails it fails. Passwords and progress are provided. Made some experiments, checked against nzbget source code. Works for me.

TL;DR:
- Install p7zip-full and the p7zip-rar packages
- Copy said script (below) somewhere (make sure it's readable by the user nzgbet runs as)
- In nzbget settings, replace unrar by '/bin/bash <absolute path to script>'
- Merry Christmas.

Code: Select all

#!/bin/bash
#
# This script simulates unrar for nzbget while it actually invokes 7z.
# 7z performs orders or magnitudes better on rpi4.
#

set -euo pipefail
#set -x

OUTDIR="${!#}"

while [ "$#" -gt 0 ]; do
    case "$1" in
        -p-)
            ;;
        -p*)
            PASSWORD="${1:2}"
            ;;
        *)
            ;;
    esac
    shift
done

if [ -z "${PASSWORD+x}" ]; then
    PASSWORD=""
else
    PASSWORD="-p${PASSWORD}"
fi

echo "UNRAR 5.61 beta 1 freeware      Copyright (c) 1993-2018 Alexander Roshal"

7z x -y -aoa -bsp1 -bse1 "${PASSWORD}" -o"${OUTDIR}" '*.rar' | \
    stdbuf -e0 -o0  tr -s '\b' '\n' | \
    while read line; do

        if echo "$line" | grep -q "Can not open encrypted archive. Wrong password?"; then
            echo "The specified password is incorrect."
            exit 1
        fi

        if echo "$line" | grep -q "Everything is Ok"; then
            echo "All OK"
        fi

        if echo "$line" | grep -q "Extracting archive: *"; then
            ARCHIVE=$(echo "$line" | awk '{print $3}')
            echo "Extracting from ${ARCHIVE}"
        fi

        if echo "$line" | grep -q "[[:space:]]*[0-9]*% -"; then
            PROGRESS=$(echo "$line" | awk '{print $1}')
            FILENAME=$(echo "$line" | cut -d' ' -f 3-)
            echo "Extracting ${FILENAME} ${PROGRESS}"
        fi

    done

exit 0

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests