Help - Search - Members - Calendar
Full Version: Re-encode FLAC while keeping tags?
Hydrogenaudio Forums > Lossless Audio Compression > FLAC
ShockValue
Is it possible to re-encode flac files (say, from -1 to -8 hypothetical) while still keeping all of the tag information in tact? I am using linux, so so-far I've only been able to find the flac command line executable for doing operations like this.

Going from flac(-1) to .wav to flac(-8) obviously looses all of it's tagging info, but I can't figure out how to go from flac to flac.

If the solution is not currently possible from linux, I also have access to a windows machine (although I would rather keep it linux if possible.)

Thanks in advance for any advice :woot:

ShockValue
Amadablam
This is part of a transcoding script I use to, among other things, recompress FLAC files to --best.

CODE
flac -d -c song.flac | flac --best - -o transcoded/song.flac && metaflac --no-utf8-convert --export-vc-to=/tmp/tag.tmp song.flac && metaflac --import-vc-from=/tmp/tag.tmp transcoded/song.flac


I'm actually decoding one flac file to stdout and encoding a new flac in a separate directory ("transcoded" in this example) and using metaflac to copy the tag info. My script is a bit of a hack overall, but if you're interested in the whole thing let me know.
user
foobar2000 does it for windows. here's a guide: *

MOD:* no links or names of sharing group guides please.
ShockValue
Amadablam: Yes I am very interested smile.gif

user: your link is dead.


I fired up foobar2000 just to take a peak. It seems I need to configure the diskwriter output, but all it gives me is WAV settings... Hmmm.
Amadablam
This script will work on a directory of FLAC files or a tree of subdirectories of FLAC files. Using the script is easy, just make sure you're in the directory (or in the parent directory of the group of subdirectories) of the files you want to transcode and run the script with one option - "flac", "vorbis", or "mp3":

CODE
transcode flac


There's also a test mode for verifying FLAC files and writing errors to a logfile, and during transcoding EAC logs are copied and written to with the new audio format and quality settings. Other options are contained in the script itself, such as where you want the transcoded files to go and the quality settings for encoding. I'm not really a programmer so there are some real hacks here, but it works. Enjoy!

CODE
########################################################################
# transcode
#
# A "front-end" script for transcoding from FLAC to either
# FLAC, Ogg Vorbis, or MP3
#
########################################################################

#!/bin/bash

########################################################################
# User-Defined Variables:

# Where do you want your transcoded files to go?

TRANSCODED_DIR=~/music/transcoded

# FLAC command-line options

FLAC_OPS="--best"

# Ogg Vorbis (oggenc) command-line options

VORBIS_OPS="-q 6"

# MP3 (lame) command-line options (quality only; ID3 tag options are below)

LAME_OPS="--alt-preset standard"

########################################################################
# Non-User-Defined Variables:

# This part sorts out the copying of subdirectories in the tree
TOP_WORKING_DIR=`pwd`
TOP_WORKING_DIR_LENGTH=`expr length "$TOP_WORKING_DIR"`
let "PATH_CUT_LENGTH=$TOP_WORKING_DIR_LENGTH+2"

TODAY=`date -I`

# This variable is set at the command line - flac, vorbis, mp3, or test
OUTPUT_TYPE=$1

########################################################################
# The transcoding functions

# Function for transcoding FLAC to FLAC (useful for increasing compression)

flac2flac ()
{
EAC_LOG=`basename "$1" .log`
if [ "$1" == "$EAC_LOG" ]
then
 echo "Transcoding "$1" to $OUTPUT_TYPE"
 CURRENT_WORKING_DIR=`pwd`
 MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-`
 TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH"
 mkdir -p "$TOTAL_PATH"
 flac -d -c "$1" | flac "$FLAC_OPS" - -o "$TOTAL_PATH/$1" && metaflac --no-utf8-convert --export-vc-to=/tmp/tag.tmp "$1" && metaflac --import-vc-from=/tmp/tag.tmp "$TOTAL_PATH/$1"
else
 cp "$1" "$TOTAL_PATH/.."
 echo "" >> "$TOTAL_PATH/../$1"
 echo "**********"  >> "$TOTAL_PATH/../$1"
 echo "$TODAY - Transcoded album to flac $FLAC_OPS" >> "$TOTAL_PATH/../$1"
fi
return 0
}

# Function for transcoding FLAC to Ogg Vorbis using oggenc

flac2vorbis ()
{
EAC_LOG=`basename "$1" .log`
if [ "$1" == "$EAC_LOG" ]
then
 echo "Transcoding "$1" to $OUTPUT_TYPE"
 CURRENT_WORKING_DIR=`pwd`
 MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-`
 TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH"
 mkdir -p "$TOTAL_PATH"
 newname="`basename "$1" .flac`.ogg"
#  flac -d -c "$1" | oggenc "$VORBIS_OPS" - -o "$TOTAL_PATH/$newname" && metaflac --no-utf8-convert --export-vc-to=/tmp/tag.tmp "$1" && vorbiscomment --raw -w "$TOTAL_PATH/$newname" -c /tmp/tag.tmp && rm /tmp/tag.tmp
 oggenc "$VORBIS_OPS" "$1" -o "$TOTAL_PATH/$newname"
else
 cp "$1" "$TOTAL_PATH/.."
 echo "" >> "$TOTAL_PATH/../$1"
 echo "**********" >> "$TOTAL_PATH/../$1"
 echo "$TODAY - Transcoded album to Ogg Vorbis $VORBIS_OPS" >> "$TOTAL_PATH/../$1"
fi
return 0
}

# Function for transcoding FLAC to MP3 using the LAME encoder

flac2mp3 ()
{
EAC_LOG=`basename "$1" .log`
if [ "$1" == "$EAC_LOG" ]
then
 echo "Transcoding "$1" to $OUTPUT_TYPE"
 CURRENT_WORKING_DIR=`pwd`
 MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-`
 TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH"
 mkdir -p "$TOTAL_PATH"
 newname="`basename "$1" .flac`.mp3"
 TITLE=`metaflac --show-vc-field=TITLE "$1" | cut -b 7-`
 ARTIST=`metaflac --show-vc-field=ARTIST "$1" | cut -b 8-`
 ALBUM=`metaflac --show-vc-field=ALBUM "$1" | cut -b 7-`
 TRACK=`metaflac --show-vc-field=TRACKNUMBER "$1" | cut -b 13-`
 YEAR=`metaflac --show-vc-field=DATE "$1" | cut -b 6-9`
 GENRE=`metaflac --show-vc-field=GENRE "$1" | cut -b 7-`
 COMMENT=`metaflac --show-vc-field=COMMENT "$1" | cut -b 8`
 flac -d -c "$1" | lame-ha $LAME_OPS --add-id3v2 --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" --tn "$TRACK" --ty "$YEAR" --tg "$GENRE" --tc "$COMMENT" - "$TOTAL_PATH/$newname"
else
 cp "$1" "$TOTAL_PATH/.."
 echo "" >> "$TOTAL_PATH/../$1"
 echo "**********" >> "$TOTAL_PATH/../$1"
 echo "$TODAY - Transcoded album to LAME mp3 $LAME_OPS" >> "$TOTAL_PATH/../$1"
fi
return 0
}

flactest ()
{
EAC_LOG=`basename "$1" .log`
if [ "$1" == "$EAC_LOG" ]
then
  echo "Testing $1 and silently writing log"
  flac -t -s "$1" 2>> "$TRANSCODED_DIR/flactest.log"
fi
return 0
}

########################################################################

# Function for finding files recursively

recursive ()
{
for i in *
do
 if [ -d "$i" ]
 then
  cd "$i"
  recursive
  cd ..
 else

  if [ "flac" == "$OUTPUT_TYPE" ]
  then
   flac2flac "$i"
  elif [ "vorbis" == "$OUTPUT_TYPE" ]
  then
   flac2vorbis "$i"
  elif [ "mp3" == "$OUTPUT_TYPE" ]
  then
   flac2mp3 "$i"
  elif [ "test" == "$OUTPUT_TYPE" ]
  then
   flactest "$i"
  else
   echo "Output type not recognized - please specify \"flac\", \"vorbis\", \"mp3\", or \"test\""
  fi

 fi
done
}

########################################################################

# The main body of the script...all it does is call the recursive function
recursive

########################################################################
# End of script
########################################################################
ShockValue
Thanks man! I think that is just what I need (plus a couple of changes for my system.)

When I run it, I am getting this error:

____________________________________
options: -P 4096 -b 4608 -m -l 8 -q 0 -r 3,3
10,000 Maniacs - MTV Unplugged - 04 - I'm Not The Man.flac: done
-: wrote 23345414 bytes, ratio=0.585
/tmp/tag.tmp: ERROR: line too long, aborting
____________________________________

The net result is that no tag info is written in the new file.

tag.tmp file:

_______________________________
bash-2.05b$ cat tag.tmp
artist=10,000 Maniacs
album=MTV Unplugged
tracknumber=4
title=I'm Not The Man
genre=20
DATE=1993
year=1993
comment=
_______________________________
user
hm, the link works here ? * or browse via * tutorial *

MOD:* no links or names of sharing group guides please.
Amadablam
http://www.hydrogenaudio.org/forums/index....indpost&p=33649

I've used that script on many files and never seen an error with the tags. The lines are obviously not too long, unless you have some information in your original tags that wasn't shown in your post. Or, for some strange reason, you didn't get the script copied right. Be real careful with the long lines - a few wrapped when I pasted into my post and now look like two lines when they're actually one. The line that does all the work, starting with "flac -d" and ending with "&& metaflac --import-vc-from" is all one line!

If that still doesn't work, check out the above post - it's where I got the tag copying idea from in the first place. Josh Coalson (the creator of FLAC) has his own way of copying tags through stdout and stdin, which would bypass the whole temp file altogether.
ShockValue
user: link works now. Weird, first time I tried I got an angelfire error stating the page couldn't be displayed. I will read through that information.

Amadablam:

I will tinker with that script to see if I can get it working. I think it may have something to do with the --no-utf-8 stuff (not sure of syntax, I'm at work.) . I'll let you know how things go smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.