ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Kharitonov A. Dmitry" <kharpost@rambler.ru>
To: ALT Linux Community general discussions <community@lists.altlinux.org>
Subject: Re: [Comm] Как понизить битрейт mp3?
Date: Sat, 04 Oct 2008 23:04:28 +0400
Message-ID: <48E7BE3C.6050307@rambler.ru> (raw)
In-Reply-To: <91dc8dbf0810041055qfabd198hcc794209978a305@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 292 bytes --]


> С понижением битрейта разобрался, достаточно просто lame... С ходу
> подумал, глядя на примеры, что он енкодит только wav и raw, оказалось,
> и mp3 тоже.
>
> Теперь теги
> По поводу тегов, думаю, услышу волшебное слово mp3info
>
>
>   
Ну с тегами всё совсем не просто...
Гляньте скрипт



[-- Attachment #2: encoder.sh --]
[-- Type: text/plain, Size: 7748 bytes --]

#!/bin/bash 

# ðÒÏ×ÅÒËÁ ÎÁÌÉÞÉÑ ÎÅÏÂÈÏÄÉÍÙÈ ÐÒÏÇÒÁÍÍ
ex=0;
if ! which madplay &> /dev/null; then echo "${0##*/}: madplay is not found"; ex=1; fi
if ! which id3v2 &> /dev/null; then echo "${0##*/}: id3v2 is not found"; ex=1; fi
if ! which normalize &> /dev/null; then echo "${0##*/}: normalize is not found"; ex=1; fi
if ! which mp3info &> /dev/null; then echo "${0##*/}: mp3info is not found"; ex=1; fi
if ! which lame &> /dev/null; then echo "${0##*/}: lame is not found"; ex=1; fi
if ((ex)); then exit 1; fi

# ðÏÌÕÞÅÎÉÅ ËÏÌÉÞÅÓÔ×Á ÐÒÏÃÅÓÓÏÒÏ× ÄÌÑ ÏÒÇÁÎÉÚÁÃÉÉ ÐÁÒÁÌÌÅÊÎÙÈ ×ÙÞÉÓÌÅÎÉÊ
NPROCS=`egrep -cs ^cpu[0-9]+ /proc/stat`
[ "$NPROCS" -gt 1 ] 2>/dev/null || NPROCS=1
((NPROCS=NPROCS*2))

n=1
PROCFILE="/tmp/${0##*/}-$n.proc"
while [ -f "$PROCFILE" ]; do ((n++)); PROCFILE="/tmp/${0##*/}-$n.proc"; done

r=$(echo -ne "\r")

OUTPUT=
INPUT=

MAXBITRATE=128
AVRBITRATE=112
RESAMPLE=
CRESAMPLE=
BOOK=
TAG3=

VALID_BITRATE=( 32 40 48 56 64 80 96 112 128 160 192 224 256 320 )
if (($#>=1)); then
	for opt in "$@"; do
		case "$opt" in
			--book=*)
			MAXBITRATE="$(echo "$opt" | cut -d '=' -f 2)"
			i=1; while ((${VALID_BITRATE[i]}<MAXBITRATE)); do ((i++));
				if((${VALID_BITRATE[i]}==320)); then break; fi
			done
			MAXBITRATE=${VALID_BITRATE[i]}
			if ((MAXBITRATE!=320)); then MAXBITRATE=${VALID_BITRATE[i+1]}; fi
			AVRBITRATE=${VALID_BITRATE[i-1]}
			BOOK="$opt"
			;;
			--resample=*)
			RESAMPLE="$(echo "$opt" | cut -d '=' -f 2)"
			CRESAMPLE="--resample $RESAMPLE"
			;;
	
			--proc=*)
			PROCFILE="$(echo "$opt" | cut -d '=' -f 2)"
			;;

			--base=*)
			BASE="$(echo "$opt" | cut -d '=' -f 2)"
			;;

			*)
			if [ -z "$INPUT"  ]; then INPUT="$opt";  continue; fi
			if [ -z "$OUTPUT" ]; then OUTPUT="$opt"; continue; fi
			;;
		esac
	done
fi
echo "$PROCFILE"
[ -f "$PROCFILE" ] || :>"$PROCFILE"

# exit 0

if [ -z "$BASE" ]; then BASE="$INPUT"; fi
if [ -z "$OUTPUT" ]; then OUTPUT="$INPUT"; fi
while [ "${OUTPUT:((${#OUTPUT}-1))}" == "/" ]; do OUTPUT="${OUTPUT:0:((${#OUTPUT}-1))}"; done
if [ -d "$INPUT" ]; then 
	cd "$INPUT"; 
	nest=1
	while [ "$INPUT" != "$(echo "$INPUT" | cut -d '/' -f -$nest)" ]; do
		diroutput=$(echo "$INPUT" | cut -d '/' -f -$nest)
		if [ "${diroutput:0:${#BASE}}" == "$BASE" ]; then
			diroutput=${diroutput/#$BASE} 
			if ! [ -d "$OUTPUT/$diroutput" ]; then mkdir "$OUTPUT/$diroutput" || exit 1; fi
		fi
		((nest++))
	done
        diroutput="$(echo "$INPUT" | cut -d '/' -f -$nest)"
	diroutput="${diroutput/#$BASE}"
	while [ "${diroutput:0:1}" == "/" ]; do diroutput="${diroutput:1}"; done
	if ! [ -d "$OUTPUT/$diroutput" ]; then mkdir -p "$OUTPUT/$diroutput" || exit 1; fi

	MASK='*'; 
fi
if [ -f "$INPUT" ]; then MASK="${INPUT##*/}"; INPUT="${INPUT%$MASK}"; fi
cd "$INPUT";
if [ -z "$MASK" ]; then exit 1; fi
[ "$MASK" == '*' ] && MASK=
ls -1b $MASK | {
while read file; do 
	if [ -d "$file" ]; then 
	"$0" "$INPUT/$file" "$OUTPUT" "--base=$BASE" "$BOOK" "$CRESAMPLE" "--proc=$PROCFILE"; 
	fi
	if [ -f "$file" ]; then
		case $(echo ${file##*\.} | tr A-Z a-z) in
			mp3) 
			OUTFILE="$OUTPUT/$diroutput/$file"; OUTFILE="${OUTFILE%.*}"

			# rm -f "$OUTPUT/tmp.id3"
			# ðÏÌÕÞÅÎÉÅ ÉÎÆÏÒÍÁÃÉÉ É ÕÄÁÌÅÎÉÅ ÓÉÍ×ÏÌÁ ×ÏÚ×ÒÁÔ ËÁÒÅÔËÉ
		        :>"$OUTFILE.mp3"
			id3v2 -l "$file" | sed -e "s/$r//g" | {
			while read sfield; do
				case ${sfield:0:4} in
				id3v | AENC | APIC | COMM | COMR | ENCR | EQUA | ETCO | \
				GEOB | GRID | IPLS | LINK | MCDI | MLLT | OWNE | PRIV | \
				PCNT | POPM | POSS | RBUF | RVAD | RVRB | SYLT | SYTC | \
				TALB | TBPM | TCOM | TCON | TCOP | TDAT | TDLY | TENC | \
				TEXT | TFLT | TIME | TIT1 | TIT2 | TIT3 | TKEY | TLAN | \
				TLEN | TMED | TOAL | TOFN | TOLY | TOPE | TORY | TOWN | \
				TPE1 | TPE2 | TPE3 | TPE4 | TPOS | TPUB | TRCK | TRDA | \
				TRSN | TRSO | TSIZ | TSRC | TSSE | TXXX | TYER | UFID | \
				USER | USLT | WCOM | WCOP | WOAF | WOAR | WOAS | WORS | \
				WPAY | WPUB | WXXX)
					echo -ne "\\n$sfield">>"$OUTFILE.mp3"
					;;
				*)
					echo -n "\\\\r\\\\n$sfield">>"$OUTFILE.mp3"
					;;
				esac
			done
			}
			TAG3="$(cat "$OUTFILE.mp3")"
			# id3v2 -l "$TEMPFILE";
			# cat "$OUTPUT/tmp.id3"
			
			if echo "$TAG3" | grep "id3v1 tag info for"> /dev/null; then 
				Track=$(mp3info -p "%n" "$INPUT/$file")
				Artist=$(mp3info -p "%a" "$INPUT/$file")
				Comment=$(mp3info -p "%c" "$INPUT/$file")
				Genre=$(mp3info -p "%G" "$INPUT/$file")
				Album=$(mp3info -p "%l" "$INPUT/$file")
				Title=$(mp3info -p "%t" "$INPUT/$file")
				Year=$(mp3info -p "%y" "$INPUT/$file")
			fi
			
			# ïÖÉÄÁÎÉÅ ÏÓ×ÏÂÏÖÄÅÎÉÑ ÓÌÏÔÁ ÐÒÏÃÅÓÓÏÒÁ
			NSLOT=
			while [ -z "$NSLOT" ]; do
				NSLOT=$(cat "$PROCFILE" | { while read proc; do
					if [ "${proc:0:4}" == "SLOT" ]; then
						proc=${proc:4};
						((NSLOT=${proc%%=*}+0))
						((proc=${proc##*=}+0))
						if ((NSLOT>0)) & ((NSLOT<=NPROCS)) & ( ! ps -p "$proc"> /dev/null 2>&1 ); then
							echo $NSLOT;
							break;
						fi
					fi
				done 
				[ -z "$NSLOT" ] && echo 0	
				})
				sleep 2
			done
			((NSLOT<1)) && NSLOT=1
			echo "$(date) SLOT#$NSLOT=$file"
			{ 
			madplay -o "wave:$OUTFILE.wav" "$INPUT/$file" > /dev/null 2>&1 # && echo -e "\nDecoding DONE"
			normalize --peak "$OUTFILE.wav" > /dev/null 2>&1
			lame $CRESAMPLE --abr $AVRBITRATE -B $MAXBITRATE -q 0 "$OUTFILE.wav" "$OUTFILE.mp3" > /dev/null 2>&1
			
			if echo "$TAG3" | grep "id3v1 tag info for"> /dev/null; then 
				mp3info -a "$Artist"  "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -c "$Comment" "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -g "$Genre"   "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -l "$Album"   "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -n "$Track"   "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -y "$Year"    "$OUTFILE.mp3" > /dev/null 2>&1
				mp3info -t "$Title"   "$OUTFILE.mp3" > /dev/null 2>&1
			fi
			
			id3v2=1
			echo "$TAG3" | {
			while read sfield; do
					if (( id3v2 )); then 
						if echo "$TAG3" | grep "id3v2 tag info for"> /dev/null; then id3v2=0; fi
						continue
					fi
				fieldname=${sfield:0:4}
				case $fieldname in
					TCON) fieldcont=" "$(echo "$sfield" | cut -d ':' -f 2- | cut -d '(' -f 2 | cut -d ')' -f 1) ;;
					WXXX | COMM) fieldcont=$(echo "$sfield" | cut -d ':' -f 3-) ;;
					*)    fieldcont=$(echo "$sfield" | cut -d ':' -f 2-) ;;
				esac
				
				while [ "${fieldcont:0:1}" == " " ]; do fieldcont=${fieldcont:1}; done
				[ -n "$fieldcont" ] && id3v2 --id3v2-only "--$fieldname" "$(echo -e "$fieldcont")" "$OUTFILE.mp3" > /dev/null 2>&1
			done
			}
				rm -f "$OUTFILE.wav" > /dev/null 2>&1
			echo "$(date) Stop#$NSLOT=$file"

			} &
			proc=$!
			:>"$PROCFILE.proc"
			for ((SLOT=1; SLOT<=NPROCS; SLOT++)); do
				SLOTproc=$(cat "$PROCFILE" | { while read proc; do
				if [ "${proc:0:4}" == "SLOT" ]; then
					proc=${proc:4};
					((NSLOT=${proc%%=*}+0))
					((proc=${proc##*=}+0))
					if ((NSLOT==SLOT)); then
						echo $proc;
						break;
					fi
				fi
				done })
				(( SLOTproc=SLOTproc+0 ))
				if ((NSLOT==SLOT)); then
					echo "SLOT$SLOT=$proc" >> "$PROCFILE.proc"
				else
					echo "SLOT$SLOT=$SLOTproc" >> "$PROCFILE.proc"
				fi
			done
			mv "$PROCFILE.proc" "$PROCFILE"
			;;
			*) cp -v "$INPUT/$file" "$OUTPUT/$diroutput/$file" ;;
		esac
	fi
done
}

if ! echo "$@" | grep -e "--proc="> /dev/null 2>&1; then
# ïÖÉÄÁÎÉÅ ÏÓ×ÏÂÏÖÄÅÎÉÑ ÐÒÏÃÅÓÓÏÒÁ
echo "Ending..."
SLOTWAIT=1
while [ -n "$SLOTWAIT" ]; do
	SLOTWAIT=$(cat "$PROCFILE" | { while read proc; do
		if [ "${proc:0:4}" == "SLOT" ]; then
			proc=${proc:4};
			((SLOT[${proc%%=*}]=${proc##*=}+0))
		fi
	done 
	for ((NSLOT=1; NSLOT<=NPROCS; NSLOT++)); do
	#	echo "SLOT[$NSLOT]=${SLOT[NSLOT]}"
		if ((${SLOT[NSLOT]})) && ps -p "${SLOT[NSLOT]}"> /dev/null 2>&1; then
			echo -n 1;
		fi
	done
	})
	[ -n "$SLOTWAIT" ] && sleep 2
done
rm -f "$PROCFILE"

fi
echo "Process fineshed at "`date`


  reply	other threads:[~2008-10-04 19:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-04 16:57 Ilis
2008-10-04 17:00 ` Andrey Rahmatullin
2008-10-04 17:55   ` Ilis
2008-10-04 19:04     ` Kharitonov A. Dmitry [this message]
2008-10-05  4:51       ` Ilis
2008-10-05  6:34         ` Kharitonov A. Dmitry
2008-10-05 18:11           ` Ilis
2008-10-05 18:13             ` Mikhail Gusarov
2008-10-06 19:43             ` Kharitonov A. Dmitry
2008-10-05  7:18 ` Vladimir A. Svyatoshenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48E7BE3C.6050307@rambler.ru \
    --to=kharpost@rambler.ru \
    --cc=community@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git