HydrogenAudio

Lossy Audio Compression => MPC => Topic started by: klonuo on 2012-02-26 09:30:25

Title: How to extract cover album art from mpc?
Post by: klonuo on 2012-02-26 09:30:25
If using foobar, data is added at the end of the file enclosed in APE tag.

How to extract this from terminal? mpcdec doesn't have much options
Title: How to extract cover album art from mpc?
Post by: skamp on 2012-02-26 10:17:40
There's Apetag (http://muth.org/Robert/Apetag/) for reading/writing APE tags, but I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine.
Title: How to extract cover album art from mpc?
Post by: klonuo on 2012-02-26 11:17:19
Here is brute force extractor for JPG files and size to 1MB (just in case):

Code: [Select]
x=`xxd -g0 "$1" | grep -im1 FFD8FFE0  | awk -F: '{print $1}'`
if [ -n "$x" ]; then
    y=`xxd -g0 "$1" | grep -im1 4150455441474558d0 | awk -F: '{print $1}'`
    if [ $((0x$y)) -gt $((0x$x)) ] && [ 1000000 -gt $((0x$y-0x$x)) ]; then
        dd ibs=1 count=$((0x$y-0x$x+2)) skip=$((0x$x+1)) if="$1" of=${1%.*}.jpg
    fi
fi


It expects mpc (or any other file with JPG inside) as argument
It's rather fragile, as can fail if searched signatures are wrapped by `xxd`, but it's better than no solution
Title: How to extract cover album art from mpc?
Post by: klonuo on 2012-02-26 11:33:20
There's Apetag (http://muth.org/Robert/Apetag/) for reading/writing APE tags, but I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine.


skamp, thanks for suggestion.
It dump cover simply with "./apetag -i input.mpc > out.dat" but has text at start and at the end, so "dd" has to be used again
Title: How to extract cover album art from mpc?
Post by: klonuo on 2012-02-26 13:40:21
Sorry for this, but if some mod can delete little script in post #3 it would be great. Thanks

I did lazy googling instead doing it myself, and that snippet is not accurate as it's just correct for my test sample. Problem is that byte offset (read by awk) is address of first byte in default 16 octet line where match is found
I corrected that, added 64 octets (max 256) to avoid more possible wrapping search signatures, and made search for closing APETAGEX offset from start signature position:

Code: [Select]
#!/bin/bash

start_pos=`xxd -g0 -c64 "$1" | grep -m1 ffd8ffe0`
offset=`echo $start_pos | cut -d: -f1`
correction=`echo $start_pos | cut -d' ' -f2 | sed 's/ffd8ffe0.*//'`
start_pos=$((0x$offset+${#correction}/2))

if [ $start_pos -gt 0 ]; then
    end_pos=`xxd -g0 -c64 -s 0x$(printf '%x\n' $start_pos) "$1" | grep -m1 4150455441474558d0`
    offset=`echo $end_pos | cut -d: -f1`
    correction=`echo $end_pos | cut -d' ' -f2 | sed 's/4150455441474558d0.*//'`
    end_pos=$((0x$offset+${#correction}/2))
    if [ $end_pos -gt $start_pos ] && [ 1000000 -gt $(($end_pos-$start_pos)) ]; then
        dd ibs=1 count=$(($end_pos-$start_pos)) skip=$start_pos if="$1" of="${1%.*}.jpg"
    fi
else
    echo 'No JPG cover found in APE tag'
fi


Sorry again for this gibberish, I didn't planed to do this

Cheers
Title: How to extract cover album art from mpc?
Post by: khushfehmi045 on 2014-12-12 07:33:15
I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine. ??