Sunday Mar 15, 2009

Converting flac encoded audio to mp3.

Solaris has the flac command which will happily decode flac encoded file and metaflac to read the flac meta data but you need to download lame either precompiled or from sourceforge and build it. Then it is a simple matter to convert your flac encoded files:

$ flac -c -d file.flac | lame - file.mp3

you can add various flags to change the data rates and put tags into the mp3. I feel sure someone should have written a script that would convert an entire library but I could not find one so here is the one I wrote to do this:

#!/bin/ksh93
umask 22
SRC="$1"
DST="$2"
BITRATE=128

export PATH=/opt/lame/bin:/usr/sbin:/usr/sfw/bin:/usr/bin

function flactags2lametags
{
        typeset IFS="$IFS ="
        typeset key value
        metaflac --export-tags /dev/fd/1 "$1" | while read key value
        do
                print typeset "${key}=\\"$(print $value| sed 's/["'\\'']/\\\\&/g')\\";"
        done
}

function cleanup
{
        if [[ "$FILE" != "" ]]
        then
                rm "$FILE"
        fi
}

function convert_file
{
        typeset -i ret=0
        typeset f="${1%.flac}"
        if [[ "$f" != "${1}" ]]
        then
                typeset out="${DST}/${f}.mp3"
                if ! [[ -f "${out}" ]] || [[ "$1" -nt "$out" ]]
                then
                        print $out

                        eval $(flactags2lametags "$1") 
                        FILE="$out"
                        flac --silent -c -d "$1" | \\
                                lame --quiet -b ${BITRATE} -h \\
                                ${ARTIST:+--ta }"${ARTIST}" \\
                                ${ALBUM:+--tl }"${ALBUM}" \\
                                ${TRACKNUMBER:+--tn }"${TRACKNUMBER}" \\
                                ${DATE:+--ty }"${DATE%%-\*}" \\
                                - "${out}"
                        ret=$?
                        FILE=""
                fi
        elif [[ $1 != "${1%.jpg}" ]]
        then
                [[ -f "${DST}/${1}" ]] || cp "$1" "${DST}"
        fi
        return ${ret}
}

function do_dir
{
        typeset i
        for i in "$1"/\*
        do
                if [[ -f "$i" ]]
                then
                        convert_file "$i" || return 1
                elif [[ -d "$i" ]]
                then
                        if test -d "${DST}/$i" || mkdir "${DST}/$i"
                        then
                                do_dir "$i" || return 1
                        fi
                fi
        done
        return 0
}

function usage
{
        print USAGE: $1 src_dir dest_dist >&2
        exit 1
}

trap cleanup EXIT

(( $# == 2 )) || usage $0
if test -d "${DST}/$1" || mkdir "${DST}/$1"
then
        do_dir "$1"
fi
exit $?

Sunday Mar 08, 2009

AV codecs for Solaris

One of the big complaints about using OpenSolaris and Solaris is multi media support. The lack of codecs to allow you to play "common" if not "open" formats is irritatings.

I've been using the Fluendo mp3 codecs for a while as they have a compelling price point, being free. Fluendo also have a bundle of other codecs that they supply for OpenSolaris containing codecs for a number of other popular formats. I decided the €28 was would be worth it and have now installed the codecs on my home server. I now have gstreamer support for:

: pearson FSS 1 $; gst-inspect | grep -i flue
fluasf:  flurtspwms: Fluendo WMS RTSP Extension
fluasf:  fluasfcmdparse: Fluendo ASF Command Parser
fluasf:  fluasfdemux: Fluendo ASF Demuxer
fluwmvdec:  fluwmvdec: Fluendo WMV Decoder
fluaacdec:  fluaacdec: Fluendo AAC Decoder
flumms:  flummssrc: Fluendo MMS source
fludivx3dec:  fludivx3dec: Fluendo DivX 3.11 Decoder
flulpcm:  flulpcmdec: Fluendo LPCM decoder
fluwma:  fluwmsdec: Fluendo WMS Decoder
fluwma:  fluwmadec: Fluendo WMA Decoder (STD + PRO + LSL + WMS)
fluh264dec:  fluh264dec: Fluendo H264 Decoder
flumpeg4vdec:  flumpeg4vdec: Fluendo MPEG-4 ASP Video Decoder
flumpeg2vdec:  flumpeg2vdec: Fluendo MPEG-2 Video Decoder
flump3dec:  flump3dec: Fluendo MP3 Decoder (C build)
: pearson FSS 2 $; 

Alas on the Sun Rays the video performance is still less than great but on the console it is faultless and I am seeing the Totem is not quite as useless as I had previously thought.

It would be really cool if you could get OpenSolaris codecs via IPS repository.

The next thing I want is to be able to edit video.

About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today