IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
How to extract cover album art from mpc?, on Linux terminal
klonuo
post Feb 26 2012, 10:30
Post #1





Group: Members
Posts: 258
Joined: 29-April 10
Member No.: 80274



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
Go to the top of the page
+Quote Post
skamp
post Feb 26 2012, 11:17
Post #2





Group: Developer
Posts: 1430
Joined: 4-May 04
From: France
Member No.: 13875



There's 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.

This post has been edited by skamp: Feb 26 2012, 11:18


--------------------
See my profile for measurements, tools and recommendations.
Go to the top of the page
+Quote Post
klonuo
post Feb 26 2012, 12:17
Post #3





Group: Members
Posts: 258
Joined: 29-April 10
Member No.: 80274



Here is brute force extractor for JPG files and size to 1MB (just in case):

CODE
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

This post has been edited by klonuo: Feb 26 2012, 12:19
Go to the top of the page
+Quote Post
klonuo
post Feb 26 2012, 12:33
Post #4





Group: Members
Posts: 258
Joined: 29-April 10
Member No.: 80274



QUOTE (skamp @ Feb 26 2012, 12:17) *
There's 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
Go to the top of the page
+Quote Post
klonuo
post Feb 26 2012, 14:40
Post #5





Group: Members
Posts: 258
Joined: 29-April 10
Member No.: 80274



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
#!/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

This post has been edited by klonuo: Feb 26 2012, 14:41
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 2nd September 2014 - 16:29