Fix audible m4a files

Based on https://rentry.co/n4ost
This commit is contained in:
Nemo 2021-07-21 14:56:45 +05:30
parent 6632edd96c
commit 99ddefeb6b
4 changed files with 33 additions and 1 deletions

View File

@ -109,4 +109,5 @@ This lives in my `~/projects/scripts` directory and is added to my `$PATH`. Not
| yubilock.sh | Lock my screen when I remove my device. Runs using udev triggers |
| ec | script to edit common configuration |
| get-nav | Get NAV of a mutual fund from the Kuvera API |
| audiobook2video | Generates a video for a music file, with a background |
| audiobook2video | Generates a video for a music file, with a background |
| fix-audible-m4a | Third-party. Fixes audible m4a fiels with incorrect Audio Object Type Specific Config bit. Source: https://rentry.co/n4ost |

View File

@ -4,3 +4,4 @@ IFS=$'\n\t'
# PODMAN FTW!
podman run -v $(pwd):/data ryanfb/inaudible@sha256:b66738d235be1007797e3a0a0ead115fa227e81e2ab5b7befb97d43f7712fac5
for i in "*.m4a"; do fix-audible-m4a "$i";done

0
ec Normal file → Executable file
View File

30
fix-audible-m4a Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
# Source: https://rentry.co/n4ost
f="$1"
t=$(mktemp)
mp4extract-bento4 moov/trak/mdia/minf/stbl/stsd/mp4a/esds \
"$f" /dev/stdout | xxd -p | tr -d '\n' > $t
magic=$(sed -re 's/^.*0580808002(....).*$/\1/' $t)
if [ "$magic" != "1212" ]; then
echo "no need to fix"
rm "$t"
exit 0
fi
t2=`mktemp`
new=$(sed -re 's/05808080021212/05808080021210/' $t | xxd -r -p >$t2)
rm $t
old="${f}.pre-fix"
mv -v "$f" "$old"
mp4edit --replace \
moov/trak/mdia/minf/stbl/stsd/mp4a/esds:"$t2" \
"$old" \
"$f"
rm "$old"