HydrogenAudio

Lossless Audio Compression => FLAC => Topic started by: gottkaiser on 2006-12-14 09:49:01

Title: FLAC re-encoding
Post by: gottkaiser on 2006-12-14 09:49:01
Hey,

I want to re-encode my FLAC files with "FLAC Frontend". If I'll give a FLAC file as input, I get a Wave file decoded. Then I would need to encode it again. Because the programm tells me that I can just use Wave file as input to encode to FLAC.
If I do it like that I need lot's of time and I would lose all Tags.

Now I would like to know if there is a command line option to re-encode FLAC files with the "flac.exe", that I could keep my Tags.
Or is ther a good freeware program? (I would prefere the comand line option)


Thanks in advance.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2006-12-14 10:13:56
Now I would like to know if there is a command line option to re-encode FLAC files with the "flac.exe", that I could keep my Tags.
Yes.  FLAC 1.1.3 will accept FLAC files as input and will transfer tags.

Code: [Select]
FLAC.EXE -8 -V -o new.flac old.flac
Title: FLAC re-encoding
Post by: sshd on 2006-12-14 12:10:16
flac -f filename.flac
Title: FLAC re-encoding
Post by: Synthetic Soul on 2006-12-14 13:10:31
flac -f filename.flac
If you use this method it may be worth reading this thread (http://www.hydrogenaudio.org/forums/index.php?showtopic=50920).  I'm never keen on overwriting or deleting files before I'm sure that the conversion is successful.
Title: FLAC re-encoding
Post by: LotharZ on 2006-12-26 11:13:20
There is some way to automatize all this process?

Some kind of frontend that supports flac2flac or a batch file?

thx
Title: FLAC re-encoding
Post by: Martin F. on 2006-12-26 13:10:27
for /r %i in (*.flac) do start /low /wait flac --best --force "%i"
or
for /r %i in (*.flac) do start /low /wait flac -A "tukey(0,5)" (http://flac.sourceforge.net/documentation_bugs.html#bugs) --best --force "%i"
Title: FLAC re-encoding
Post by: LotharZ on 2006-12-26 18:41:43
first thx Martin F.

and by the other way, I modified your command to create another file with the new encode, this could be usefull to someone and if its wrong probably someone can fix my command's sintaxis (Im not exactly an expert with flac  )

Code: [Select]
for /r %i in (*.flac) do start /low /wait flac --best --force -V "%i" --output-name="%i_"
Title: FLAC re-encoding
Post by: Synthetic Soul on 2006-12-26 19:06:56
I would have thought "%i_" would leave you with "<name>.flac_"?

A better solution may be:

Code: [Select]
for /r %i in (*.flac) do start /low /wait flac --best --force -V "%i" --output-name="%~dpni.new.flac"

This should convert "<name>.flac" to "<name>.new.flac".
Title: FLAC re-encoding
Post by: Jebus on 2006-12-26 19:18:39
Omni Encoder will also do this, no weird command-line twiddling involved.
Title: FLAC re-encoding
Post by: agentk7 on 2006-12-29 04:09:55
I would have thought "%i_" would leave you with "<name>.flac_"?

A better solution may be:

Code: [Select]
for /r %i in (*.flac) do start /low /wait flac --best --force -V "%i" --output-name="%~dpni.new.flac"

This should convert "<name>.flac" to "<name>.new.flac".


Is this the exact command line to use?  I must be missing something because when I try it I get this error "ERROR: -o/--output-name cannot be used with multiple files".
Title: FLAC re-encoding
Post by: LotharZ on 2006-12-29 08:35:35
@agentk7

It's only a whole line.
Title: FLAC re-encoding
Post by: krabapple on 2007-01-04 22:55:45
I can get foobar2k v0.9.4.2 to transcode from flac 1.1.0 to 1.1.3, and transfer all the tags, using flac.exe as a custom commandline encoder, but I can't figure out how to get it to delete the old flac file  (or overwrite it).  I've tried -delete-input-file, or -f (where output directory = input dir), and nothing I've tried works. (ps, also tried --delete-input-file, and that does nothing)

some of the parameters I've tried:

-8 -delete-input-file - -o %d

-8 -delete-input-file %s -o %d

-8 -f - -o %d

-8 -f %s -o %d
Title: FLAC re-encoding
Post by: collector on 2007-01-04 23:40:39
[quote name='krabapple' date='Jan 4 2007, 14:55' post='461910']
(ps, also tried --delete-input-file, and that does nothing)

It certainly is --delete-input-file  (--)  The helpfiles say it only deletes files when no errors occurred.

I'm not familiar with foobar, but I use the (dos)commandline with a program called glob.exe. Don't know where I got it from, sorry.  Search the net for it ?

The syntax from the batchfile I use is "glob.exe -c flac.exe -6 --force --delete-input-file -S- *.flac"
Without the quotes.  Maybe its syntax is overcomplete but this works for me. And also works for  *.wav
Title: FLAC re-encoding
Post by: Egor on 2007-01-05 20:42:40
Regarding deletion of source files in foobar2000: [a href='index.php?showtopic=51598']fb2k's converter cannot delete the original file[/a].
Title: FLAC re-encoding
Post by: krabapple on 2007-01-06 02:13:35
I notice that  flac-to-flac transcodes (using command line flac.exe and, I guess, metaflac.exe) automatically transfer many of the metadata tags from old file to new -- all the standards as well as COMPOSER and COMMENTS -- which is great.  However it does not seem to transfer the old replaygain values to the new.  Is that even possible?  If it requires a -T NAME=VALUE  in the command line as per vorbis comments  what are the VALUE variables for replaygain track peak, track gain, album peak, album gain?  For that matter, I'm not even sure how the NAME should be written -- e.g. with underscores?

-T replaygain_track_gain="  ? "
Title: FLAC re-encoding
Post by: krabapple on 2007-01-06 06:06:47
Now I would like to know if there is a command line option to re-encode FLAC files with the "flac.exe", that I could keep my Tags.
Yes.  FLAC 1.1.3 will accept FLAC files as input and will transfer tags.

Code: [Select]
FLAC.EXE -8 -V -o new.flac old.flac




When I run that , it first warns me my input file is not a WAV file and will be treated as a raw file, then throws an error because I have not specified --endian, --sign, etc.  So no file is output.

Does this command actually work for you, to reencode from flac to flac?  So far none of the command lines or batch scripts posted here work for me, using flac 1.1.0 or 1.1.2 files as input,and hoping for a smaller flac 1.1.3 file as output.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-06 07:10:09
Are you sure that you are testing with FLAC 1.1.3?

It works fine here:

Code: [Select]
C:\Documents and Settings\Neil\Desktop>flac112 test.wav

flac 1.1.2, Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

options: -P 4096 -b 4608 -m -l 8 -q 0 -r 3,3
test.wav: wrote 197077 bytes, ratio=0.464

C:\Documents and Settings\Neil\Desktop>flac -o new.flac test.flac

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

test.flac: wrote 195137 bytes, ratio=0.990

Edit: If I use 1.1.2 to try to re-encode I get:

Code: [Select]
C:\Documents and Settings\Neil\Desktop>flac112 -o new2.flac test.flac

flac 1.1.2, Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

options: -P 4096 -b 4608 -m -l 8 -q 0 -r 3,3
ERROR: for encoding a raw file you must specify a value for --endian, --sign, --
channels, --bps, and --sample-rate
Type "flac" for a usage summary or "flac --help" for all options
Title: FLAC re-encoding
Post by: collector on 2007-01-06 11:53:28
However it does not seem to transfer the old replaygain values to the new.  Is that even possible?

Tested the transcode from v1.1.0 to v1.1.3 and all values were copied. Replaygain values also.

You are sure you overwrote all older versions with the new 1.1.3 ones ?
Title: FLAC re-encoding
Post by: krabapple on 2007-01-06 21:36:25
Are you sure that you are testing with FLAC 1.1.3?


Yes. I've uninstalled, downloaded  and run  flac113b  installer twice now.  flac -v from the command line shows

flac 1.1.3


but I think I've found my error. I've been putting -V 8  in the command line instead of  -V -8  -- in other words a stupid typo on my part, probably me half-instinctively reverting to LAME  command line syntax for EAC. Flac-to-flac using flac.exe in a terminal window is working now,old file is ovewritten, and  replaygain values are transferred. I'm going to go slap myself with a wet fish when I'm done.

The flac batch commands I've copied from threads here still aren't working for me though.
Title: FLAC re-encoding
Post by: krabapple on 2007-01-06 23:10:12
This seems to work; I adapted it from one of Synthetic Soul's batch scripts on another thread; obviously it's very much like yours Martin --  except that with only one flac encoder in my system it seems smart enough not to need an explicit encoder statement

Code: [Select]
@ECHO OFF
FOR /R %1 %%G IN (*.flac) DO FLAC.EXE --best -V --force "%%G"



all is bliss!

and for even more compressed bliss, this substitutes a much slower but more aggressive  encode  I got from a post by JWolf

Code: [Select]
@ECHO OFF
FOR /R %1 %%G IN (*.flac) DO FLAC.EXE -8 -A tukey(0.25) -A gauss(0.1875) -b 4096 -V --force "%%G"




Bjork Homogenic directory --  size/size on disc, as reported by Windows

flac 1.1.0 probably set at -8
294 MB (308,537,323 bytes)/294 MB (308,559,872 bytes)

flac 1.1.3  --best
293 MB (307,439,199 bytes)/293 MB (307,462,144 bytes)

flac1.1.3  -8 -A tukey(0.25) -A gauss(0.1875) -b 4096
292 MB (307,129,792 bytes)/292 MB (307,150,848 bytes)
Title: FLAC re-encoding
Post by: Martin H on 2007-01-07 00:46:17
Nice to hear that you have gotten it sorted out now 

I added the %encoder% variable to the script in case you haden't flac.exe located somewhere within your PATH environment variable and so as to avoid you having to move it there for getting the script to work. Also your change to use %%G instead of %%F was also a good change, since i have just read that even though all letters can be used, then %%G are recommended to be used as e.g. using %%F and also some other letters could actually make some problems and also break a FOR script on NT4 systems.

Anyway, Nice work on making a functioning script and i'm happy that you've gotten it sorted out eventually

CU, Martin.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-07 10:45:32
I have created a batch file (http://www.synthetic-soul.co.uk/files/flac-113.bat) to convert to FLAC 1.1.3.

If you drag a file or folder onto the batch file it will process all FLAC files within (including subfolders).

It will first use -t to test the source file, and only if the test is successful will then re-encode the file using -fto force an overwrite .  Edit:  Version 1.1.0 now encodes to a new file, and if the encode was successful will then overwrite the source with the new file (MOVE /Y <new file> <old file>). This should now ensure that the souce is only ever overwritten if the process has been 100% successful.*

If any files do fail testing or re-encoding they will be listed once all processing has finished.

To use the batch file you need to first open it in Notepad and amend the lines:

Code: [Select]
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
... to suit.  You really only need quotes around pathToFLAC if the path contains spaces.  The switches -V -f are hardcoded into the command line already.
 
Hopefully some people will find this useful.

[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]* DISCLAIMER: But, of course, it may.  Don't blame me.  Test before you run it on anything precious.[/size]
Title: FLAC re-encoding
Post by: edwardar on 2007-01-07 11:26:48
Thanks for the batch file - just what I was looking for. Unfortunately it's not working properly (using 1.0.0 or 1.1.0).

My directory structure is:

I:\albums\artist1 - year1 - album1\artist1 - year1 - album1.flac
I:\albums\artist2 - year2 - album2\artist2 - year2 - album2.flac
etc...

and when I drag the albums folder onto the batch file it keeps rencoding "artist1 - year1 - album1.flac" and doesn't move on to the next one. Could you have a look at that?

Cheers,

Ed
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-07 13:04:22
Here's my test (1.1.0 used):

Code: [Select]
Checking: "L:\albums"

Testing: "L:\albums\artist1 - year1 - album1\artist1 - year1 - album1.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist1 - year1 - album1.flac: ok

Encoding: "L:\albums\artist1 - year1 - album1\artist1 - year1 - album1.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist1 - year1 - album1.flac: Verify OK, wrote 256863 bytes, ratio=1.000


Testing: "L:\albums\artist2 - year2 - album2\artist2 - year2 - album2.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist2 - year2 - album2.flac: ok

Encoding: "L:\albums\artist2 - year2 - album2\artist2 - year2 - album2.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist2 - year2 - album2.flac: Verify OK, wrote 256863 bytes, ratio=1.000


2 file(s) processed.
2 file(s) encoded.
0 file(s) returned an error.

Press any key to exit
Bear in mind that FLAC first tests the file, and then re-encodes the file.  Are you sure you are not seeing the test and then the re-encode?
Title: FLAC re-encoding
Post by: edwardar on 2007-01-07 15:50:03
Yeah, I'm pretty sure, here's my output:

Code: [Select]
Checking: "I:\Albums"

Testing: "I:\Albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Rose
s - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: ok

Encoding: "I:\Albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Ros
es - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.993
Guns N' Roses - 1987 - Appetite For Destruction.flac: 100% complete, ratio=0.992
Guns N' Roses - 1987 - Appetite For Destruction.flac: Verify OK, wrote 403736967
bytes, ratio=0.992


Testing: "I:\Albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Rose
s - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: ok

Encoding: "I:\Albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Ros
es - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: 1% complete, ratio=0.907

Ed
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-07 19:26:42
Sorry, I have no idea.  If I use that setup with my previous test I get:

Code: [Select]
Processing: "L:\albums"

Testing: "L:\albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Rose
s - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: ok

Encoding: "L:\albums\Guns N' Roses - 1987 - Appetite For Destruction\Guns N' Ros
es - 1987 - Appetite For Destruction.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Guns N' Roses - 1987 - Appetite For Destruction.flac: Verify OK, wrote 256863 by
tes, ratio=1.000


Testing: "L:\albums\Hartist2 - year2 - album2\artist2 - year2 - album2.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist2 - year2 - album2.flac: ok

Encoding: "L:\albums\Hartist2 - year2 - album2\artist2 - year2 - album2.flac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

artist2 - year2 - album2.flac: Verify OK, wrote 256863 bytes, ratio=1.000


________________________________________________________________________

2 file(s) processed.
2 file(s) encoded.
0 file(s) returned an error.

Press any key to exit
I cannot think at all why that would be happening to you.  Can you try with a test folder with a different filename to see if that makes any difference?  Use a smaller file to make the test a little easier; I have just used the Windows Startup sounds as a small test wave.

Also, perhaps you could save the following to a file called "test.bat".  Drag your "Albums" folder onto the batch file and then paste the contents of "test.txt" (created by test.bat) here.

Code: [Select]
@ECHO OFF
FOR /R %1 %%G IN (*.flac) DO CALL :ListFiles "%%G"
GOTO:EOF
:ListFiles
ECHO %1>>"%~dp0test.txt"
GOTO:EOF
Edit: Sorry, just tested on XP and I get the same as you!  I can only think that, as the files are changing, they are being entered back into the collection of FLAC files to be processed.  This does not happen on Win2K.  I'll have to have a think.  NB: test.bat works as expected, which is why I think it is to do with the files changing.  It would be a lot easier to do if the script encoded to new files (new path).

Thanks for the info. Sorry to have wasted your time.  I will upload a script that works on XP...
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-07 20:39:30
OK, the batch file (http://www.synthetic-soul.co.uk/files/flac-113.bat) has been updated.

To resolve the XP issue it now first creates a list of the files to process in a temporary file.  It then processes each line of that file as per previously (testing, encoding to new file and then overwriting source).

I hope this helps.  Sorry for the previous problems.
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-07 21:29:35
This batch file doesn't recursively process directories, does it?

I *need* to learn to do batch files myself one day.

Thank you for the work.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-07 21:57:19
Yes, it does work recursively.
Title: FLAC re-encoding
Post by: krabapple on 2007-01-08 16:23:43
Nice to hear that you have gotten it sorted out now 

I added the %encoder% variable to the script in case you haden't flac.exe located somewhere within your PATH environment variable and so as to avoid you having to move it there for getting the script to work. Also your change to use %%G instead of %%F was also a good change, since i have just read that even though all letters can be used, then %%G are recommended to be used as e.g. using %%F and also some other letters could actually make some problems and also break a FOR script on NT4 systems.

Anyway, Nice work on making a functioning script and i'm happy that you've gotten it sorted out eventually

CU, Martin.


And thank you for your input.

I certainly can't  take credit for anyting in the script -- it was almost entirely a cut an past of this (http://www.hydrogenaudio.org/forums/index.php?showtopic=33277&st=0&p=290743&#)
script by Synthetic Soul.  My only 'addition' was to elaborate the flac parameters -- and even those were copied! 

Syntehtic Soul,
Thanks go to you too.
I haven't tried your new batch file yet -- my 'older' one has now been running for two days and probably has that many more to go, so I could halt it and launch the rest of the files into the new batch.  I had thought that the -V option would prevent overwriting of original files by any 'failed' re-encodes, but is that perhaps not true?  Does --force trump -V?
Title: FLAC re-encoding
Post by: LotharZ on 2007-01-08 17:14:18
Found this problem, Its a re-encoder error but Im posting it here due to the batch file dont manage it correctly.

Its saying that the file is encoded correctly when obviously there is an error.

Code: [Select]
Testing: "E:\MP3\Depeche Mode\Playing The Angel\Depeche Mode - Damaged People.fl
ac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Depeche Mode - Damaged People.flac: ok

Encoding: "E:\MP3\Depeche Mode\Playing The Angel\Depeche Mode - Damaged People.f
lac"
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

WARNING: E:\MP3\Depeche Mode\Playing The Angel\Depeche Mode - Damaged People.fla
c is not a WAVE file; treating as a raw file
ERROR: for encoding a raw file you must specify a value for --endian, --sign, --
channels, --bps, and --sample-rate
Type "flac" for a usage summary or "flac --help" for all options
The system cannot find the file specified.


1 file(s) processed.
1 file(s) encoded.
0 file(s) returned an error.

Press any key to exit
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-08 17:19:03
I'm afraid FLAC must still be returning the exit code of zero, even though there was a problem.

Not sure why it would do that!  Not something I can fix I'm afraid.

It looks like you are seeing the same problem that krabapple reported in post #16 (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=50993&view=findpost&p=462230).  I wonder why FLAC doesn't like those FLAC files?  Any idea why that file may be different, so I can simulate and test?

Edit: I've just tested by putting a PAUSE in between the test and encode, and manually corrupting the file before letting encoding continue.  This results in:

Code: [Select]
test.flac: ERROR got FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC while decoding FLAC input
test.flac: ERROR got FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC while decoding FLAC input
test.flac: 8% complete, ratio=1.169

... and still an exit code of zero, which normally signifies a successful operation (I thought).

If FLAC will not return a non-zero code on errors I'm afraid there's nothing I can do.  Please note that the previous test should catch most errors though.  That does return a non-zero code on error (tested).
Title: FLAC re-encoding
Post by: krabapple on 2007-01-08 18:37:49
I'm afraid FLAC must still be returning the exit code of zero, even though there was a problem.

Not sure why it would do that!  Not something I can fix I'm afraid.

It looks like you are seeing the same problem that krabapple reported in post #16 (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=50993&view=findpost&p=462230).  I wonder why FLAC doesn't like those FLAC files?  Any idea why that file may be different, so I can simulate and test?


It appears from cursory glance that the main difference between your more intricate batch file and your  two-line one is the level of error checking (and logging) .  Since the simple one definitely works in XP (two days and running, knock wood!), the issue for me again comes down to , is -V (--verify) insufficient to prevent a bad encode from overwriting a good one (with --force also in effect)?  I notice from watching the directory as files are being reencoded, that with the simple script, a tmp file is created , then deleted, for every file as it's reencoded. So I would hope that if -V finds a problem, the old file is not overwritten.

Also, I notice a peculiar thing, that even though the reencoded files have definitely been modified (shrunk) by the simple script, the modification date does not change!  I'd rather it did, if only to check for failed re-encodes.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-08 18:59:18
I don't believe that I have written a 2 line solution, which may explain why it works.  I'm glad the solution's working for you though.

Yes, I noticed about the dates not changing also.  I assume this is a feature.  I had a quick look to see if there was a switch to change this behaviour, but couldn't see one.
Title: FLAC re-encoding
Post by: krabapple on 2007-01-08 19:31:06
I don't believe that I have written a 2 line solution, which may explain why it works.


Thanks, but the 'solution' I posted is copied almost directly from one of yours...I linked to your original a few posts back.  It's post  #6 in this thread, from April 2005.  It's actually one line!

http://www.hydrogenaudio.org/forums/index....;p=290743&# (http://www.hydrogenaudio.org/forums/index.php?showtopic=33277&st=0&p=290743&#)

Don't be modest, take a bow! 
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-08 20:39:56
Just want to say THANKS! for the batch script, it seems to be working great for me.

I added --replay-gain as one of the SET flacOptions parameters to (re)calculate gain in case any files were missing it.


edit:

is there a way to run the encoding as 'idle' or 'lowest' priority, so I can run it in the background without making foreground apps run slower?
Title: FLAC re-encoding
Post by: krabapple on 2007-01-08 20:51:41
With some trepidation, I have made two versions of the 'simple' .bat file available for FTP, one using  --best and the other using the more extreme compression setting.  If interested, download this README first, as it contains the links to the two .bat files.

http://www.m-ideas.com/public_html/sullivan/flac/README.txt (http://www.m-ideas.com/sullivan/flac/README.txt)
Title: FLAC re-encoding
Post by: Marino13 on 2007-01-08 21:50:43
Yes, it does work recursively.


SS,

How would I add a command line to embed a jpeg of the album cover into the new flac file?  My folder structure is F:\Artist\Album\tracknumber - title.flac.  I have a folder.jpg of each covert art inside the Albums folder.  So it is basically F:\Artist\Album\folder.jpg.  Any way to do this?  I have about 27,000 flac files and would not be able to do hese individually.
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-08 21:52:59
@LotharZ, can you host the FLAC file that's causing the problem?  or at least the first 100k of it?  also, if you test it with 'flac -tF' does it say?

...the issue for me again comes down to , is -V (--verify) insufficient to prevent a bad encode from overwriting a good one (with --force also in effect)?  I notice from watching the directory as files are being reencoded, that with the simple script, a tmp file is created , then deleted, for every file as it's reencoded. So I would hope that if -V finds a problem, the old file is not overwritten.

yep, that's how it's supposed to work.  an alternative (if you have the disk space) is to use --output-prefix to send recodes to another dir, then test afterward and replace.  then you won't need --force either.

Also, I notice a peculiar thing, that even though the reencoded files have definitely been modified (shrunk) by the simple script, the modification date does not change!  I'd rather it did, if only to check for failed re-encodes.

yes, by default flac keeps the modtime and permissions (like gzip, compress, etc).  metaflac has --preserve-modtime which flac maybe should also have, but if you want the modtime you can "touch" the file after recoding.

Josh
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-08 21:59:25
How would I add a command line to embed a jpeg of the album cover into the new flac file? My folder structure is F:\Artist\Album\tracknumber - title.flac. I have a folder.jpg of each covert art inside the Albums folder. So it is basically F:\Artist\Album\folder.jpg. Any way to do this? I have about 27,000 flac files and would not be able to do hese individually.
I'm not really up on the --picture switch syntax, and I don't really want to get into this too much, but you would reference the file using:

"%~dp1folder.jpg"

So, you would change the encoding command line to something like (not sure if syntax is correct):

Code: [Select]
%pathToFLAC% %flacOptions% --picture="|image/jpeg|||%~dp1folder.jpg" -V -o "%~dpn1-flac-113.flac" %1

Edit: Hmmm... looks like it may be worth looking at this thread (http://www.hydrogenaudio.org/forums/index.php?showtopic=51326).  It seems you can't use --picture when the source is a FLAC. 
 
 
Just  want to say THANKS! for the batch script, it seems to be working great  for me.
  ...
  is there a way to run the encoding as 'idle' or 'lowest' priority, so I  can run it in the background without making foreground apps run slower?
Glad it's helping.  I would do this by calling the batch file from the command line, e.g.:

Code: [Select]
START /LOW /B FLAC-113 "path\to\folder"

I believe that this would make all calls to FLAC in low priority (as a child process).  I'm not sure though, I don't really use this.  I tend to start a script and leave the PC well alone.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-08 22:12:08
@Josh,

Are you able to shed any light on FLAC.EXE still returning 0 when an error occurs?  Am I wrong in my understanding?

If this is the case, would you consider amending the behavior so that batch files, or other scripts, could act accordingly?
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-08 22:44:52
yes, it's not supposed to return 0 in this case, I'm hoping with the file I can debug what's wrong.
Title: FLAC re-encoding
Post by: LotharZ on 2007-01-09 00:13:57
@LotharZ, can you host the FLAC file that's causing the problem?  or at least the first 100k of it?  also, if you test it with 'flac -tF' does it say?


This is the result of 'flac -tF' command.

Code: [Select]
C:\Program Files\BeLight>flac -tF "Depeche Mode - Damaged People.flac"

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Depeche Mode - Damaged People.flac: ok


but every command trying to reencode the file gives "WAV Error". (I can decode without problems).

Already uploaded one of the files here: Moderation: link removed

If you have some problem downloading, let me know a place that works for you and i'll reupload tomorrow.

G'nite.
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-09 01:45:11
got the file... the problem is the id3v2 tag on the front of it.

Josh
Title: FLAC re-encoding
Post by: LotharZ on 2007-01-09 08:42:57
Perfect, removing all tags from files let me reencode them without problems. (I'm not sure how the hell ended an id3v2 tag there, hehe)

thx
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-09 10:04:22
I have updated my batch file (http://www.synthetic-soul.co.uk/files/flac-113.bat) to use an alternative syntax for getting the exit code, and it appears to work... properly!

I have tested with my corrupted files and LotharZ's dodgy file, and both types are picked up - mine on testing ([T]) and his on encoding ([E]).

Code: [Select]
9 file(s) processed.
6 file(s) encoded.
3 file(s) returned an error.

Files that failed:

  "C:\Documents and Settings\Neil\Desktop\Media\bad.flac" [T]
  "C:\Documents and Settings\Neil\Desktop\Media\bad2.flac" [T]
  "C:\Documents and Settings\Neil\Desktop\Media\Depeche Mode - Damaged People.flac" [E]

I appear to be behind a proxy so downloading got me version 2.0.0.  Ensure that you have version 2.1.0 (version number can be found near the top and in the version history at the bottom).

NB: I have kept both stages in, and in the original order.  I tried removing the initial test (-t), but the corrupted files (bad.flac and bad2.flac) got through the encoding verification.  I also cannot encode then test, as once encoded, even if the recode was not 100% accurate (e.g.: bad.flac is converted from 195KB to 9KB) the result is a valid file (it seems) so the file passes the test.  Testing then verifying the encode seems to be the best method.

Hopefully I'm done with this now.  I wish I'd never bothered to be honest!
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-09 16:31:05
Hopefully I'm done with this now.  I wish I'd never bothered to be honest!



 

I was thinking of something, duno if your interested (doesn't look like now hah), or feasible..

- option to skip files that are already 1.1.3 encodes.

This would make it super easy to drag an entire library on it and only re-encode new files that aren't 1.1.3 versions.

Thanks again for the script!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-09 16:39:13
I guess that could be achieved using this tool (http://www.hydrogenaudio.org/forums/index.php?showtopic=51084&hl=).

I didn't actually realise that this tool comes with some bacth files that pretty much do what mine does. 

Ah well, in for a penny...
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-09 17:02:12
OK, version 2.2.0.

If FlacGetV.exe (http://www.hydrogenaudio.org/forums/index.php?showtopic=51084) (and libFLAC.dll and libmmd.dll) is in the same directory as the batch file it will be used to check the vendor string, and skip 1.1.3 files.

If FlacGetV.exe is not present it will act as per 2.1.0.

Code: [Select]
9 file(s) processed.
8 file(s) skipped (already 1.1.3).
0 file(s) encoded.
1 file(s) returned an error.

Files that failed:

  "C:\Documents and Settings\Neil\Desktop\Media\Depeche Mode - Damaged People.flac" [E]
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-09 17:25:40
Haha great work, thanks again! 
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-09 20:21:59
Thank you.
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-09 22:17:12
One issue I have noted with this batch file is that occasionally I'll try to process some FLAC that gives me an error about not being a WAV file... and how I need to enter a flag to process it. The batch craps out. I know FLAC is more than just a compressed WAV, but I am not any more knowledgeable. Any way you know of to quickly find such non-WAV-based FLAC files in my library?
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-10 06:13:49
Any have ideas what this is and how to fix it?

Code: [Select]
state = FLAC__STREAM_DECODER_READ_FRAME
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-10 07:47:27
One issue I have noted with this batch file is that occasionally I'll try to process some FLAC that gives me an error about not being a WAV file... and how I need to enter a flag to process it. The batch craps out. I know FLAC is more than just a compressed WAV, but I am not any more knowledgeable. Any way you know of to quickly find such non-WAV-based FLAC files in my library?
Are you talking about the message reported in post #31?  By "crap out" do you mean that the batch file terminates immediately? This response from FLAC shouldn't cause the batch file to terminate.  Perhaps you could post more info?

The easiest way to simply look for files that fail testing is to navigate to your root FLAC folder and use the command:

Code: [Select]
FOR /R %G IN (*.flac) DO (FLAC -t "%G" || ECHO "%G">>failed.txt)

This will create a text file called failed.txt in the same folder with the path of any files that failed testing.

Edit: Actually, if this is the same issue as post #31 then a test won't find them.  The re-encoding stage highlights these files. You could try running the following command in the root FLAC folder:

Code: [Select]
FOR /R %G IN (*.flac) DO (FLAC -f -o tmp.flac "%G" || ECHO "%G">>failed.txt) & DEL tmp.flac

This will re-encode all files to a file called "tmp.flac", and if an error occurs write the file in question to failed.txt (and finally delete "tmp.flac").

Any have ideas what this is and how to fix it?

Code: [Select]
state = FLAC__STREAM_DECODER_READ_FRAME
When do you receive this message?  Are you running my batch file, and if so: is it during the test phase, and does it result in the file not being encoded?
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-10 10:26:03
2.2.1. Added two new variables.

Set retainListOfFailedFiles to 1 if you want to keep the list of files that failed (flac-113-failed.txt will be created in the same folder as the batch file).

Set retainListOfProcessedFiles to 1 if you want to keep the list of files that were processed by the script (flac-113-processed.txt will be created in the same folder as the batch file).

Both will delete any file of the same name before processing starts, so if you plan to run this on a folder, and then run it again, and want to keep past logs, please move or rename them after the first process.

Code: [Select]
REM ######################################################
SET pathToFLAC="C:\My\Path\To\FLAC.EXE"
SET flacOptions=-8 -A "tukey(0.5)" -A flattop
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
REM ######################################################
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-10 13:51:52
Any have ideas what this is and how to fix it?

Code: [Select]
state = FLAC__STREAM_DECODER_READ_FRAME
When do you receive this message?  Are you running my batch file, and if so: is it during the test phase, and does it result in the file not being encoded?


yes it was with your batch file (2.2), I believe it happened during the 'test' and the file was skipped. It's currently still processsing (I fed it my entire music folder after testing it several times on various folders/files).

Once it finishes I'll try again to get the exact text (I happened to saw which files it was), and I'll also try your updated version.

Cheers
Title: FLAC re-encoding
Post by: collector on 2007-01-10 14:01:39
One issue I have noted with this batch file is that occasionally I'll try to process some FLAC that gives me an error about not being a WAV file... and how I need to enter a flag to process it. The batch craps out.

Same happened here yesterday while 're-flac-ing' with my own batchfile. 
I use "glob.exe -c flac.exe -6 --force --delete-input-file -V *.flac" which works well most of the time.
Action didn't damage the faulty flac's
While viewing the problem files with an hex-editor, I noticed these begin with ID3 not fLaC
Didn't make the flacs myself but got them from the net.. Some are v1.1.0 and some are v1.1.2
After decoding them manually to wav they could be encoded to flac v1.1.3

Remark. For this encoding I sometimes use the Flac frontend v1.7 by speek which uses Tag by Case.
The newly compiled version 2.0.48 also annoyingly writes Db instead of dB. In an earlier version of tag.exe I managed to change that but in the latest version I failed.
So, Synthetic Soul can you change this before compiling it again in the future someday ?
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-10 14:14:07
I don't have the files handy anymore as I have since converted them to WavPack, then back to FLAC, to get rid of the problem. A test of the files reveals no problem, yet the batch file pops up some message about needing to reprocess based on a revised input flag. I remember some error verbiage about "--endian" and that FLAC.exe thought the files weren't WAVs, which I think they were.

I had previously used FLACTester to check out these files, and all of them passed.

I will find one of the files again on the Net and post a download site (here) for it soon for you to check out a sample of these problematic FLACs.

Thank you.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-10 14:38:31
yes it was with your batch file (2.2), I believe it happened during the 'test' and the file was skipped. It's currently still processsing (I fed it my entire music folder after testing it several times on various folders/files).

Once it finishes I'll try again to get the exact text (I happened to saw which files it was), and I'll also try your updated version.
Hmm.  Unfortunately it sounds like the file is slightly corrupt.  You may have to use --decode-through-errors (http://flac.sourceforge.net/documentation_tools_flac.html#flac_options_decode_through_errors) when decoding this file in order to reclaim it.  Josh, or a more proficient FLAC user, may be able to deny or add to this. NB: Once the script has finished it should list any files that failed (the major (only?) benefit of this batch file over a one line solution!).

Remark. For this encoding I sometimes use the Flac frontend v1.7 by speek which uses Tag by Case.
The newly compiled version 2.0.48 also annoyingly writes Db instead of dB. In an earlier version of tag.exe I managed to change that but in the latest version I failed.
So, Synthetic Soul can you change this before compiling it again in the future someday ?
I haven't changed the setup for compiling Tag, so if you could compile it before you should be able to compile it now.  That said, I can look into changing "Db" to "dB"... if I can find where the change needs to be made.  NB: Latest is 2.0.49 (TAK support added).

I don't have the files handy anymore as I have since converted them to WavPack, then back to FLAC, to get rid of the problem. A test of the files reveals no problem, yet the batch file pops up some message about needing to reprocess based on a revised input flag. I remember some error verbiage about "Indian" and that FLAC.exe thought the files weren't WAVs, which I think they were.
Quote
flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

WARNING: E:\MP3\Depeche Mode\Playing The Angel\Depeche Mode - Damaged People.fla
c is not a WAVE file; treating as a raw file
ERROR: for encoding a raw file you must specify a value for --endian, --sign, --
channels, --bps, and --sample-rate
Type "flac" for a usage summary or "flac --help" for all options
In the case above, and in collector's experience, this occurs as the file has ID3v2 tags at the beginning.  These files do past the test (-t) as the audio data is fine, but when used as input for encoding FLAC barfs.
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-10 14:54:09
Quote
________________________________________________________________________

flac 1.1.3, Copyright © 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

-wumpscut- - 1997 - Embryodead (back-is-front edition) - 09 - Angel.flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC


-wumpscut- - 1997 - Embryodead (back-is-front edition) - 09 - Angel.flac: ERROR while decoding data
                                                                          state = FLAC__STREAM_DECODER_READ_FRAME

File failed testing.


I'll test the affected files shortly and see if they are playable.
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-10 14:58:17
>> In the case above, and in collector's experience, this occurs as the file has ID3v2 tags at the beginning.
>> These files do past the test (-t) as the audio data is fine, but when used as input for encoding FLAC barfs.

Perhaps so. I am still trying to find a file to post.
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-10 15:15:41
Thanks for any advice.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-10 15:31:51
Thanks for a sample of your file.  The file has ID3v2 tags at the beginning, as suspected.  It looks like EAC added them (as one of the tags seems to be "Exact Audio Copy  (Secure mode)".

AFAIK FLAC will accommodate ID3v1 at the end of the file (http://flac.sourceforge.net/faq.html#general__tagging), but ID3v2 are totally non-standard.

Edit:  I have just tested, and it seems to have worked, but you may do best to test yourself.  Tag showed me that your file has ID3v1, ID3v2 and FLAC tags.  I used the command:

Code: [Select]
TAG.EXE --remove --force FLAC myfile.flac

... and that appears to have successfully removed the ID3 tags and left the FLAC (or copied any ID3 tags to the FLAC tags).

Actually, just remembered that you used WavPack to resolve this...  Forget me.

Edit 2: On the assumption that the file provided was pre 1.1.3 there is something I should note.  After using Tag 2.0.49, which is compiled with libFLAC 1.1.3, the file then presented itself as 1.1.3.  I renamed FlacGetV.exe to FlacGetV.exe.bak and dragged the file onto flac-113.bat to get it to re-encode irrespective of vendor string...
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-10 15:51:09
I have verified the ID3 tags as well are the issue here. Thanks for your work.

God, wouldn't it be nice just to have a single tagging format for once to have to deal with?
Title: FLAC re-encoding
Post by: collector on 2007-01-10 16:26:13
The file has ID3v2 tags at the beginning, as suspected.

And I can't get this removed, neither by Tagscanner, Tag&Rename nor Tag

Code: [Select]
TAG.EXE --remove --force FLAC myfile.flac

Doesn't remove the id3 tag for me    I can decode the flac first, and then encode the wav to flac again. That's not the problem. But batchprocessing lots of files was just that easy now that flac113 can use flacs as input. Maybe any future flac.exe can ignore these tags and proceed with flac-to-flac
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-10 16:42:12
Strange that it appears to work for me (after running Tag the file provided could be re-encoded using FLAC.EXE).  I guess it depends on the tagger used to get the tags on there in the first place.  ID3v2 seem to be a pain. 

With the file that philaphonic provided I was able to remove the ID3v2 tag in a hex editor; I just deleted all the bytes before the "fLaC" header which was easy to find due to the padding in the ID3v2 tag.

The only other option I can think of is Tag's --fromfile switch.  That would involve re-encoding to a new file and then using Tag to copy the tags from the old to the new... I've no idea how well that would work in your situation, and whether the --force switch would be required...

Josh will probably have a better idea of how to remove these unwanted bytes. It's frustrating that the audio data is perfectly fine, but you can't get to it!
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-10 16:42:47
Update for me:

The 'error' files would indeed play (in mediamonkey, didn't try anything else) with no apparent errors.

I tried 'cleaning' the tags with MM, and again with metaflac --remove-all and didn't help.

I ended up re-encoding them with mediamonkey flac to flac (1.1.2) and then I was able to successfully use the batch.

I'd recommend anyone having problem files try re-encoding them first with mediamonkey (tools > convert audio format > select FLAC and replace existing or specify an alternate file mask/filename), then run thru batch again.

BTW, From 190ish gigs of FLAC's, this script and 1.1.3 saved me ~2 gigs just from what explorer reported free space before/after. (I forgot to get exact size before starting it)

So thanks to the FLAC dev's and thanks Synthetic Soul for making it super easy to take advantage of re-encoding.
Title: FLAC re-encoding
Post by: Junon on 2007-01-10 16:53:51
God, wouldn't it be nice just to have a single tagging format for once to have to deal with?


Yup. I really wouldn't mind if the world of audio tagging consisted just of either Vorbis comments or APEv2.

Begone, evil ID3! Begone, naughty ASF/WMA! Ohhhhhm! *breaks into some kind of ritual chant that summons up a greater demon to destroy all kinds of annoying metadata*
Title: FLAC re-encoding
Post by: pepoluan on 2007-01-10 16:56:45
So thanks to the FLAC dev's and thanks Synthetic Soul for making it super easy to take advantage of re-encoding.
And don't forget to thank MediaMonkey developers for making a player capable of skipping the ID3v2 tags and play the FLAC's however nonstandard they are!
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-10 17:13:59
So thanks to the FLAC dev's and thanks Synthetic Soul for making it super easy to take advantage of re-encoding.
And don't forget to thank MediaMonkey developers for making a player capable of skipping the ID3v2 tags and play the FLAC's however nonstandard they are!



Always much love for the monkey and it's dev's! 
Title: FLAC re-encoding
Post by: collector on 2007-01-10 17:55:00
I was able to remove the ID3v2 tag in a hex editor; I just deleted all the bytes before the "fLaC" header which was easy to find due to the padding in the ID3v2 tag.

I could do so too, but then it's easier for me to decode the file to wav and re-encode again. But, up till flac113 I never transcoded flac-to-flac. The 1.1.0 and 1.1.2 play fine with or without those id3v2 tags.

Quote
Josh will probably have a better idea of how to remove these unwanted bytes. It's frustrating that the audio data is perfectly fine, but you can't get to it!

Unwanted when transcoding flac-to-flac that is.
Title: FLAC re-encoding
Post by: philaphonic on 2007-01-10 18:28:29
I guess my final suggestion is to transcode problem files to WavPack, then back to FLAC. That strips the ID2 tags and keeps all the good FLAC tags.

I use Foobar 0.9.4.2 to do all this and it works a treat.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-10 21:56:05
Just use the Programm "Mp3tag" to save your Tag's in the Flac file. It removes ID3-Tags automatically.
Title: FLAC re-encoding
Post by: agentk7 on 2007-01-11 03:15:10
OK, version 2.2.0.

If FlacGetV.exe (http://www.hydrogenaudio.org/forums/index.php?showtopic=51084) (and libFLAC.dll and libmmd.dll) is in the same directory as the batch file it will be used to check the vendor string, and skip 1.1.3 files.

If FlacGetV.exe is not present it will act as per 2.1.0.

Code: [Select]
9 file(s) processed.
8 file(s) skipped (already 1.1.3).
0 file(s) encoded.
1 file(s) returned an error.

Files that failed:

  "C:\Documents and Settings\Neil\Desktop\Media\Depeche Mode - Damaged People.flac" [E]


Hi SS,

The batch file is awesome, very helpful.  I noticed it even preserves the original file date which is a big plus in my book.  That allows me to track what hardware I used during the original rip.... besides the fact I'm a big date sentimentalist

Anyway, about the FlacGetV.exe, if tag.exe was used to create the FLAC tags then it overwrites the Flac version with an older one.  This is true if you use the flac113b.exe windows package and the tag.exe version that comes with that.  Here is the thread about that problem:
http://www.hydrogenaudio.org/forums/index....showtopic=38232 (http://www.hydrogenaudio.org/forums/index.php?showtopic=38232)

That problem threw me for a loop when I encountered it after upgrading to Flac 1.1.3.  Then I noticed all my old Flac 1.1.2 files encoded using the previous windows package had tags with the Flac 1.1.0 version string as a result of this problem.

I'm pointing this out in case people wonder why they might be seeing unnecessary reencodes.  Although after the reencode they would at least have the correct version.

I just thought I'd mention it in case anyone ran into that problem and didn't see the other thread.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-11 07:51:41
The batch file is awesome, very helpful. I noticed it even preserves the original file date which is a big plus in my book. That allows me to track what hardware I used during the original rip.... besides the fact I'm a big date sentimentalist
I'm glad it's been of use.  I can't take credit for the date preservation, that's an inbuilt FLAC thing.

Anyway, about the FlacGetV.exe, if tag.exe was used to create the FLAC tags then it overwrites the Flac version with an older one. This is true if you use the flac113b.exe windows package and the tag.exe version that comes with that. Here is the thread about that problem:
http://www.hydrogenaudio.org/forums/index....showtopic=38232 (http://www.hydrogenaudio.org/forums/index....showtopic=38232)

That problem threw me for a loop when I encountered it after upgrading to Flac 1.1.3. Then I noticed all my old Flac 1.1.2 files encoded using the previous windows package had tags with the Flac 1.1.0 version string as a result of this problem.
Yes, I mentioned the opposite end of this a little further up this thread (post #63).

If you use my latest release of Tag, which has been compiled with libFLAC 1.1.3, on a pre-1.1.3 file, it will change the vendor string to 1.1.3. If you then use my batch file with FlacGetV.exe it will skip all those files.

The FLAC package uses Case's last release, 2.0.39, which was built with libFLAC 1.1.0.  So, as you say, if you use that to tag your 1.1.3 files the vendor string will be changed to 1.1.0, and my batch file will re-encode them unnecessarily.

I actually rebuilt Tag with libFLAC 1.1.3 because of that thread that you quote (glad to see you were the member who thanked me BTW ).  I don't really understand the vendor string, but it seems odd to me that simply tagging a file can change the perceived version of FLAC used to encode the file.  If the person that builds the installer continues to ignore my releases, or simply recompile the version 2.0.39 code with the latest libFLAC themselves, then I'm afraid you're stuck with having to overwrite the included version with mine, if you want the vendor string to reflect the encode version.

Thanks for the heads up.
Title: FLAC re-encoding
Post by: collector on 2007-01-11 10:04:01
If you use my latest release of Tag, which has been compiled with libFLAC 1.1.3, on a pre-1.1.3 file, it will change the vendor string to 1.1.3.

Which is incorrect also, since Tag only changes tags, right ? When checking my flacs I'd get the impression all or many seperately tagged ones are v.113 

Quote
I don't really understand the vendor string, but it seems odd to me that simply tagging a file can change the perceived version of FLAC used to encode the file.

For me it's the reason to avoid Tag and Tag&Rename, because they get the credits while only adding/changing the tags. Those credits, imho, should go to the encoding flacversion  Maybe the taggers could be mentioned in a comment string. But that's for Josh to decide.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-11 11:43:03
Which is incorrect also, since Tag only changes tags, right ? When checking my flacs I'd get the impression all or many seperately tagged ones are v.113
Yes.  Well, not 'incorrect' (see below), but confusing and/or illogical.  Sorry, I didn't mean to sound like it was a recommendation, but that it was an equal problem to that mentioned by agentk7.

For me it's the reason to avoid Tag and Tag&Rename, because they get the credits while only adding/changing the tags. Those credits, imho, should go to the encoding flacversion smile.gif Maybe the taggers could be mentioned in a comment string. But that's for Josh to decide.
I haven't touched Case's tagging code; however, I very much doubt that either of these apps are purposefully changing the vendor string.  I suspect it is libFLAC, used to tag the files, which does.  Therefore these apps are not acting 'incorrectly'.

However, as stated above, I do agree that the vendor string changing simply because you add an artist field seems very strange.  The idea of a string to distinguish the version of codec used to encode the file is great, but having it change with a simple tag update is bizarre.  I can only assume that I misunderstand the purpose of the vendor string.

Edit: Hmm.. that said, using the latest metaflac on a file encoded with 1.1.0 does not change the vendor string, so maybe these apps are doing something wrong to not stop the vendor string being amended... hopefully Josh can shed some light.  Edit2: I've just looked at the Tag code (tagwrite.cpp, WriteFLACTag()) and, although I have no idea what is going on, I can't see anywhere where the vendor string is being specified.  There may be some method to stop the default behaviour of updating the vendor string that has not been implemented.  It would be great is a competent C++ programmer could provide a patch...
Title: FLAC re-encoding
Post by: collector on 2007-01-11 17:28:14
Well, not 'incorrect' (see below), but confusing and/or illogical.

OK. Incorrect in a way that, without any tags at all, my flacs are still the old streams.

Quote
Edit2: I've just looked at the Tag code (tagwrite.cpp, WriteFLACTag()) and, although I have no idea what is going on, I can't see anywhere where the vendor string is being specified.  There may be some method to stop the default behaviour of updating the vendor string that has not been implemented.

There are programs that have the 'honour' to be mentioned in the vendor string. Tag and Tag&Rename are some of them. As part of the flac-packet it seems logical to me that metaflac is doing its job allright.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-11 17:39:06
There are programs that have the 'honour' to be mentioned in the vendor string. Tag and Tag&Rename are some of them. As part of the flac-packet it seems logical to me that metaflac is doing its job allright.
Yes, but i was testing whether amending the vendor string was actually the norm (metaflac behaviour).  As I say, Tag uses FLAC's libFLAC, compiled from the source distributed by Josh.  So, is it libFLAC's normal behaviour to change the vendor string?  It appears so, given that the Tag code doesn't specifically change the string; inferring that, by using libFLAC, any tagging (or any tagging app) will amend the vendor string.

I don't have enough experience with other taggers to know which use libFLAC and which amend the vendor string, and I don't have enough knowledge to pursue this further.

I suppose we're getting off-topic, but I had hoped that we may resolve something with this... well, not 'we', but someone with more knowledge taking an interest...
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-11 18:39:53
what happens with the vendor string depends on how the metadata was edited.  the vendor string should always be preserved unless during the process of editing, the whole original VORBIS_COMMENT metadata block is deleted by the app (or if there was none in the first place, more unlikely) and a new one created.

but there may be a bug about that; if you can give me specific info about how it is calling libFLAC I can take a look.

Josh
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-11 18:57:36
but there may be a bug about that; if you can give me specific info about how it is calling libFLAC I can take a look.
I'm afraid I can't be specific as such, as I don't really understand the code. 

I have uploaded the cpp file in question, here (http://www.synthetic-soul.co.uk/temp/tagwrite.cpp), and the specific function is below:

Code: [Select]
int WriteFLACTag ( const char* filename, FileInfo* Info )
{
    const char* Items_OggApe[] = {
        "TITLE=",          APE_TAG_FIELD_TITLE,
        "VERSION=",        APE_TAG_FIELD_SUBTITLE,
        "ARTIST=",          APE_TAG_FIELD_ARTIST,
        "ALBUM=",          APE_TAG_FIELD_ALBUM,
        "TRACKNUMBER=",    APE_TAG_FIELD_TRACK,
        //"ORGANIZATION=",    APE_TAG_FIELD_PUBLISHER,
        //"DESCRIPTION=",    APE_TAG_FIELD_COMMENT,
        "GENRE=",          APE_TAG_FIELD_GENRE,
        "DATE=",            APE_TAG_FIELD_YEAR,
        //"LOCATION=",        APE_TAG_FIELD_RECORDLOCATION,
        //"COPYRIGHT=",      APE_TAG_FIELD_COPYRIGHT,
        //"ISRC=",            APE_TAG_FIELD_ISRC
    };

    char*              item;
    char*              value;
    char*              p;
    size_t              item_len;
    size_t              i, j;
    int                tag_written = 0;
    int                needs_new_block = 1;

    struct FLAC__Metadata_SimpleIterator*      si;

    si = FLAC__metadata_simple_iterator_new ();
    if ( !FLAC__metadata_simple_iterator_init ( si, filename, 0, 0 ) ) {
        FLAC__metadata_simple_iterator_delete ( si );
        return 1;
    }
    if ( !FLAC__metadata_simple_iterator_is_writable ( si ) ) {
        FLAC__metadata_simple_iterator_delete ( si );
        return 1;
    }

    do {
        FLAC__MetadataType  type = FLAC__metadata_simple_iterator_get_block_type ( si );

        if ( type == FLAC__METADATA_TYPE_VORBIS_COMMENT || type == FLAC__METADATA_TYPE_PADDING ) {
            needs_new_block = 0;
            break;
        }
    } while ( FLAC__metadata_simple_iterator_next ( si ) );

    if ( !needs_new_block ) {
        FLAC__metadata_simple_iterator_delete ( si );

        si = FLAC__metadata_simple_iterator_new ();
        if ( !FLAC__metadata_simple_iterator_init ( si, filename, 0, 0 ) ) {
            FLAC__metadata_simple_iterator_delete ( si );
            return 1;
        }
        if ( !FLAC__metadata_simple_iterator_is_writable ( si ) ) {
            FLAC__metadata_simple_iterator_delete ( si );
            return 1;
        }
    }

    do {
        FLAC__MetadataType  type = FLAC__metadata_simple_iterator_get_block_type ( si );

        // Vorbis comment block or padding block
        if ( needs_new_block || (type == FLAC__METADATA_TYPE_VORBIS_COMMENT || type == FLAC__METADATA_TYPE_PADDING) ) {
            if ( !tag_written ) {
                FLAC__StreamMetadata*                      data;
                FLAC__StreamMetadata_VorbisComment_Entry    entry;
                size_t  comments = 0;

                if ( (data = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_VORBIS_COMMENT )) == NULL ) {
                    fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
                    FLAC__metadata_simple_iterator_delete ( si );
                    return 1;
                }

                for ( i = 0; i < Info->TagItemCount; i++ ) {
                    if ( Info->TagItems[i].Item[0] != '\0' && Info->TagItems[i].ValueU[0] != '\0' )
                        comments++;
                }

                if ( !FLAC__metadata_object_vorbiscomment_resize_comments ( data, comments ) ) {
                    fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
                    FLAC__metadata_object_delete ( data );
                    FLAC__metadata_simple_iterator_delete ( si );
                    return 1;
                }

                comments = 0;

                for ( i = 0; i < Info->TagItemCount; i++ ) {
                    int replaced_item = 0;
                    if ( Info->TagItems[i].Item[0] == '\0' || Info->TagItems[i].ValueU[0] == '\0' )
                        continue;

                    for ( j = 0; j < (sizeof (Items_OggApe) / sizeof (*Items_OggApe)) / 2; j++ ) {
                        if ( stricmp ( (char *)Info->TagItems[i].Item, (char *)Items_OggApe[j*2+1] ) == 0 ) {
                            replaced_item = 1;
                            item_len = strlen ((char *)Items_OggApe[j*2]) - 1;
                            if ( (item  = (char *)malloc ( item_len + 1 )) == NULL ) {
                                fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
                                exit (1);
                            }
                            strncpy ( item, Items_OggApe[j*2], item_len );
                            item[item_len] = '\0';
                            break;
                        }
                    }

                    if ( !replaced_item ) {
                        item_len = Info->TagItems[i].ItemSize;
                        if ( (item  = (char *)malloc ( item_len + 1 )) == NULL ) {
                            fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
                            exit (1);
                        }
                        strcpy ( (char *)item, (char *)Info->TagItems[i].Item );
                    }

                    p = item;
                    while ( *p != '\0' ) {
                        int ch = *p;
                        if ( ch == '=' || ch < 0x20 || ch > 0x7D ) ch = '_';
                        *p++ = ch;
                    }

                    entry.length = strlen (item) + 1 + Info->TagItems[i].ValueUSize;
                    if ( (value = (char *)malloc ( entry.length + 1 )) == NULL ) {
                        fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
                        exit (1);
                    }
                    sprintf ( value, "%s=%s", item, Info->TagItems[i].ValueU );
                    entry.entry = (unsigned char *)value;

                    if ( !FLAC__metadata_object_vorbiscomment_set_comment ( data, comments++, entry, 1 ) ) {
                        fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
                        FLAC__metadata_object_delete ( data );
                        FLAC__metadata_simple_iterator_delete ( si );
                        return 1;
                    }

                    free ( item );
                    free ( value );
                }

                //FLAC__metadata_object_vorbiscomment_set_vendor_string ( data, entry, 1 );
                /*
                FLAC__metadata_object_vorbiscomment_resize_comments ( FLAC__StreamMetadata *object, unsigned new_num_comments);
                FLAC__metadata_object_vorbiscomment_set_comment ( FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
                FLAC__metadata_object_vorbiscomment_insert_comment (FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
                FLAC__metadata_object_vorbiscomment_delete_comment (FLAC__StreamMetadata *object, unsigned comment_num);
                */

                if ( !needs_new_block ) {
                    if ( !FLAC__metadata_simple_iterator_set_block ( si, data, 1 ) ) {  // 1 = use padding
                        fprintf ( Options.output, "Failed to write FLAC metadata block.\n" );
                        FLAC__metadata_object_delete ( data );
                        FLAC__metadata_simple_iterator_delete ( si );
                        return 1;
                    }
                } else {
                    if ( !FLAC__metadata_simple_iterator_insert_block_after ( si, data, 1 ) ) {  // 1 = use padding
                        fprintf ( Options.output, "Failed to write FLAC metadata block.\n" );
                        FLAC__metadata_object_delete ( data );
                        FLAC__metadata_simple_iterator_delete ( si );
                        return 1;
                    }
                }

                FLAC__metadata_object_delete ( data );

                tag_written = 1;
            } else if ( type == FLAC__METADATA_TYPE_VORBIS_COMMENT ) {
                if ( !FLAC__metadata_simple_iterator_delete_block ( si, 0 ) ) {    // 0 = no padding
                    fprintf ( Options.output, "Failed to remove FLAC metadata block.\n" );
                    FLAC__metadata_simple_iterator_delete ( si );
                    return 1;
                }
            }
        }
    } while ( FLAC__metadata_simple_iterator_next ( si ) );

    FLAC__metadata_simple_iterator_delete ( si );

    fprintf ( Options.output, "FLAC tag written.\n" );

    return 0;
}
Unfortunately, if you, or another developer familiar with the FLAC library, are not prepared to look at the code then we're stuck.  Perhaps, if you could help resolve this for version 2.0.50, it could be distributed with the FLAC Windows installer, and Windows FLAC users can sleep easy...

That said, I don't expect you to resolve this.  I was mainly querying whether this was standard for the library or not.  As you say it is not then I must put it down to the specific code and forget about it, until someone with the proper skills takes on the mantle.
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-11 19:48:58
ok, I can see in that loop is prepending it's own created VORBIS_COMMENT, then deleting any other it finds afterward.  so it will get the vendor string of the current library in the created VORBIS_COMMENT.

2 ways to fix: update existing VORBIS_COMMENT instead of delete and replace, or copy vendor string into new comment.

Josh
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-11 20:02:45
Thanks for the confirmation Josh.

If only I knew my arse from my elbow...

Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-11 23:34:01
@Synthetic Soul

does you'r batch file support future flac versions? I mean if you use FlacGetV.exe.
For example if the flac.exe is for example v1.1.4. Does it just re-encode files lower 1.1.4?
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-12 07:11:24
It didn't, but it does now.  Version 2.2.2 (http://www.synthetic-soul.co.uk/files/flac-113.bat).

It's a very simple change but to make it easier I have turned it into a variable so the user can set it at the top with all the others.

Code: [Select]
REM ######################################################
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
SET retainListOfFailedFiles=0
SET retainListOfProcessedFiles=0
SET flacVersion=113
REM ######################################################

Change 113 to 114 to skip files that are 1.1.4.

Of course, the batch file name may be a little confusing...
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-12 08:07:33
thanks :-)
Title: FLAC re-encoding
Post by: JJZolx on 2007-01-15 01:14:27
I'm running into problems re-encoding a set of Flac files that were encoded using Flac 1.1.1.  I can run Flac 1.1.3 using -d and it decodes the file to wav without a problem.  Is this a known issue?

Here's the output I get on one of the files when using Flac 1.1.3 to either re-encode or to verify the file.  It's dbPowerAMP's Windows Explorer extension that tells me it was encoded by Flac 1.1.1.

Code: [Select]
C:\temp\test>flac -f test.flac

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

WARNING: test.flac is not a WAVE file; treating as a raw file
ERROR: for encoding a raw file you must specify a value for --endian, --sign, --channels, --bps, and --sample-rate
Type "flac" for a usage summary or "flac --help" for all options


Edit: My bad.  I meant to run a test in the second example.  The file tests fine, but it won't re-encode.

Code: [Select]
C:\temp\test>flac -t test.flac

flac 1.1.3, Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

test.flac: ok
Title: FLAC re-encoding
Post by: JJZolx on 2007-01-15 03:17:43
I'm running into problems re-encoding a set of Flac files that were encoded using Flac 1.1.1.  I can run Flac 1.1.3 using -d and it decodes the file to wav without a problem.  Is this a known issue?

Ok. I went back and read through this entire thread.  Looking at the file in a hex editor I can see that it does indeed have an ID3v2.3.0 tag in the beginning.

My only question is - Why is Flac able to decode this file without a hitch, but it not _re_encode it?  That doesn't really make sene to me.  It means that using this method of re-encoding is of limited use.  You need to test the file somehow, then the old method of first decoding to WAV if it fails.  May as well just use the older method to be safe until this can be fixed.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-15 06:26:50
Not really.  If you have 1000 FLAC files and 2 with ID3v2 tags at the start it's well worth getting 998 converted with tags and then only having to deal with the 2 you know need special attention.

NB: This is not a FLAC issue.  FLAC never has supported ID3v2 tags, so should not be expected to deal with files that have them.  It is a user/EAC issue.
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-15 16:36:03
My only question is - Why is Flac able to decode this file without a hitch, but it not _re_encode it?  That doesn't really make sene to me.

yeah, the reason for this is that the actual decoder can skip id3v2 if it already knows it's a FLAC file.

but the flac program itself does not yet know for sure the file type.  it does not go by just the extension (some platforms do not have it and some users can mess this up believe it or not), so it reads the beginning of the file to try and figure out what it is.

but, in order to support pipes properly it has to buffer all that lookahead because it can't seek the input back to the beginning after figuring out the file.  but with id3v2 that could be a lot and you can't really know how long except with multiple reads, so I punt in this case.

there are three possible fixes, but all seem like more than acceptable than to just reject invalid files:

1) add another option like --force-flac-format
2) split the filetype detection code to work for seekable input, then the bug will only be with pipes
3) make the detection code more complicated to buffer the whole id3 tag

in the meantime I've at least fixed the code to notice the id3 tag and give a better error.  I guess I could also just trust every input file whose names start with .flac.  but this will not fix it on platforms like (I think) BeOS where there is no extension.

Josh
Title: FLAC re-encoding
Post by: JJZolx on 2007-01-16 00:36:10
but, in order to support pipes properly it has to buffer all that lookahead because it can't seek the input back to the beginning after figuring out the file.  but with id3v2 that could be a lot and you can't really know how long except with multiple reads, so I punt in this case.

Thanks Josh.  It makes a lot more sense now.  Clarifying the error message is a good start and may be sufficient.

I've been able to work around this in my script by first trying the native re-encoding and if Flac throws a non-zero exit code, then I fall back to the old method of decoding first to wav and encoding again, passing all the tags along.
Title: FLAC re-encoding
Post by: HydroFred on 2007-01-16 14:06:20
I use the following batch file to convert my old flac files to 1.1.3

Code: [Select]
@echo off
pause
for /r %%i in (*.flac) do start /low /wait flac -f -8 -A "tukey(0,5)" "%%i"


But unfortunately, the batch never stops. If for example I run it in a directory with 2 flac files named 1.flac and 2.flac, it will keep alternating between the two. It seems the FOR somehow recognizes that a file has changed and therefor adds it to the list of files to be processed...?

Any way to stop this? If I encode to another file with -o "%%i.new" or something it works perfect, but I see no easy way to delete the old files afterwards and rename all the .flac.new to .flac
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-16 14:18:35
Yes, that happened to my early version.  As you say, I think XP (it doesn't happen on 2K) dynamically alters the collection of files, seeing the amended file as new.

I resolved this in mine by creating a list of files using that syntax, and then using that list as the source files.  You can see my code here (http://www.synthetic-soul.co.uk/files/flac-113.bat).

Edit:  Here's a cut-down version:

Code: [Select]
FOR /R %%G IN (*.flac) DO ECHO "%%G">>list.txt
FOR /F "tokens=* delims=" %%H IN (list.txt) DO START /LOW /WAIT FLAC.EXE -f -8 -A "tukey(0,5)" %%H
DEL list.txt
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-16 14:20:26
I use the following batch file to convert my old flac files to 1.1.3

Code: [Select]
@echo off
pause
for /r %%i in (*.flac) do start /low /wait flac -f -8 -A "tukey(0,5)" "%%i"


But unfortunately, the batch never stops. If for example I run it in a directory with 2 flac files named 1.flac and 2.flac, it will keep alternating between the two. It seems the FOR somehow recognizes that a file has changed and therefor adds it to the list of files to be processed...?

Any way to stop this? If I encode to another file with -o "%%i.new" or something it works perfect, but I see no easy way to delete the old files afterwards and rename all the .flac.new to .flac



Wy don't you use this batch file (http://www.synthetic-soul.co.uk/files/flac-113.bat)?
It's really helpfull!


Oh someone was faster :-)
Title: FLAC re-encoding
Post by: HydroFred on 2007-01-16 14:31:44
Thanks, I'll just use your batch file instead of worrying too much to find my own solution.

I took the liberty of modifying line #12
Code: [Select]
SET flacOptions=-8 -A "tukey(0,5)"


Again, thanks for providing the batch file. Works like a charm.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-16 15:12:27
You could also just use the flac.exe version from http://www.rarewares.org/lossless.html (http://www.rarewares.org/lossless.html).  (You need to copy the libmmd.dll in the "Windows" folder, You find it on the same page)
This is new compile of the official release + the comma bugfix.

Then you don't need -A "tukey(0,5)"
Title: FLAC re-encoding
Post by: HydroFred on 2007-01-16 15:24:18
You could also just use the flac.exe version from http://www.rarewares.org/lossless.html (http://www.rarewares.org/lossless.html).
This is new compile of the official release + the comma bugfix.
"MSVC6 compile"... wow... are people still using that old compiler piece of crap?

It does not work however: "Die Anwendung konnte nicht gestartet werden, weil libmmd.dll nicht gefunden wurde. Neuinstallation der Anwendung könnte das Problem beheben."

I'll stay with the official version and the tukey(0,5)

EDIT: Hooray, managed to shrink an 4825 MB directory down to 4770 MB
Title: FLAC re-encoding
Post by: collector on 2007-01-18 01:56:44
The file has ID3v2 tags at the beginning, as suspected.  It looks like EAC added them
FLAC will accommodate ID3v1 at the end of the file, but ID3v2 are totally non-standard.

Sorry, for jumping back in time. I don't know if it's an id3version two tag, but tonight I noticed that eac adds that horrible id3tag when I tick [v] add id3 tag at the compression options tab/page.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-18 02:19:24
@Synthetic Soul

I have another suggestion for the batch file.
You write all the added files in the beginning to the text file for the processed files.
Maybe you could just add them when they are really successful processed. So you could read all processed files. In the case you abort the transcoding in the middle.

And maybe you could include a option to pursue an old log file.


What do you think?  :-)
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-18 07:54:04
The processed list has to contain all files, as this is the list that is used to detirmine which files to process.  However, as well as writing all failed files to a log I could also easily write all successful files to a log (and add another config flag to specify whether it is kept or not).

I'm a little confused by your other request, but two interesting actions spring to mind.

Firstly, and most easily, I could allow the user to drag a log file onto the batch file to start, rather than a file or folder.  The script would then use all files in the log as the process list, rather than create it's own.  This may be useful to re-process the "flac-113-failed.txt" log, once the user has made some changes to the files (like removing ID3v2 tags).

          Secondly, but more difficultly, the script could somehow restart processing a folder and its subfolders, by using the newly suggested "flac-113-successful.txt" and "flac-113-processed.txt" to restart the list, skipping any files that exist in "flac-113-successful.txt".  Presumably this would be initiated by dragging "flac-113-processed.txt" onto the batch file, and having "flac-113-successful.txt" exist in the same folder as flac-113.bat.  Or something.

Anyway, thanks for the ideas.  I'll see what I can do.  I'm a little busy at the moment.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-21 12:36:59
Sounds like a good idea. Thanks
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-29 07:26:11
Following gotkaiser's suggestion, and a hassling PM (  ), I have made some amends to the script:

1. Added retainListOfSuccessfulFiles flag, to create flac-113-successful.txt, a list of successfully converted files.  Set it to 1 to keep, 0 to delete after processing.

REM ######################################################
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8 -A "tukey(0.5)"
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
SET retainListOfSuccessfulFiles=0
SET flacVersion=113
REM ######################################################

2. Drag a txt file onto the batch file, instead of a FLAC file or folder, and the script will assume that it contains a list of files to process - using this list instead of creating its own from a folder.  Possibly useful to resubmit failed files, by dragging on flac-113-failed.txt - make sure it's not still in the same folder as flac-113.bat though, otherwise it wll be deleted before anything else*.

* flac-113-processed.txt, flac-113-successful.txt and flac-113-failed.txt are all deleted at the beginning of a new run, and started afresh.  If you want to keep these logs ensure that you move them after processing.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-29 08:51:08
@Synthetic Soul

Didn't want you to feel that I hustle things. Was just a question on the progress. 

Anyway, thanks 
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-29 09:05:20
S'OK. I was only joking.  Your PM didn't offend me in the slightest; it's good to know that someone is interested.

I had some spare time last night, so I thought I'd put it to some use.
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-29 10:19:33
Ok, is clear. 
Title: FLAC re-encoding
Post by: gottkaiser on 2007-01-29 11:43:36
@Synthetic Soul

It's me --again-- 

I have one suggestion. (Feel free to work on it when ever you want to!) 

It would be helpfull to have a list to processed a long re-encoding process. For example if you have to abort, in the case you have to turn of your PC. And if you have a lot of flac files it's helpfull to have a list with the "not successfull" files. (an inverted SuccessfulFiles list) Then you could just drag this list an the batch file and proceed the process.
Hope you got the explanation.

I would do it myself but I have no clue how to do it.

So, just in the case you have some minutes left!


Thanks in advance
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-29 11:59:22
Yes, this is basically what I was discussing in a previous post:

Secondly, but more difficultly, the script could somehow restart processing a folder and its subfolders, by using the newly suggested "flac-113-successful.txt" and "flac-113-processed.txt" to restart the list, skipping any files that exist in "flac-113-successful.txt".  Presumably this would be initiated by dragging "flac-113-processed.txt" onto the batch file, and having "flac-113-successful.txt" exist in the same folder as flac-113.bat.  Or something.

It would be difficult for me to create a list of files to process and then remove files from it as they were processed (leaving a list of files still needing processing).

If I, or anyone, can think of an easy/sensible way of doing this then I will try to implement it.

Now that we have flac-113-successful.txt and flac-113-processed.txt I still think that this may be the best way.  Perhaps dragging both files at the same time onto the script (to distinguish it from the new "drag a txt file" functionality).  The script would ensure that the files are called flac-113-successful.txt and flac-113-processed.txt, and then process flac-113-processed.txt, ensuring that files listed in flac-113-successful.txt are ignored... maybe...

It would be a good feature to have though.
Title: FLAC re-encoding
Post by: Teknojnky on 2007-01-29 14:35:41
if you install the flacgetv.exe/libflac.dll/libmm.dll as mentioned earlier in the thread, the script will skip all files with the current version.

I drop my entire music folder on to a shortcut for the batch file and it scans thru the 600 gigs in a bout a minute or less, then starts checking/encoding any files which aren't current.

I don't really see the point to trying to process the log files when it doesn't take very long to re-scan everything anyway.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-29 14:38:29
A very good point!  Thanks for the lateral thinking, maybe I should try some.
Title: FLAC re-encoding
Post by: Marino13 on 2007-01-30 02:48:03
SS,

Thanks for the batch file.  This made my entire process painless.  I just completed re-encoding 676GB (25,566 songs) from 1.1.2 to 1.1.3.  It took about five days to complete.  For those interested, I had my 1.1.2 files at -5 and used --best for the conversion and saved 6 GB.  Below are just a couple of things I noticed.

I actually encoded this batch of files twice in the last two weeks.  The first time it came back with 23 files were already the latest version.  However, I knew they were not as I have not started ripping with 1.1.3 yet.  It would have taken forever to try and figure out what 23 files it was talking about so I decided to run the batch file again without flacgetv in the folder.  This time it came back with 23 errors under the "list of failed files".  All of the 23 files failed the encoder test.  The list of failed files allowed me to see which one's had failed.  This did not seem like a coincidence that the first time flacgetv saw 23 already at 1.1.3 (when they weren't) and then 23 files failed the encoder test.  What did these 23 files have in common?  They all had "%" in them somewhere.  Two of the files had "%" in the name of the file.  The other 21 were in a subfolder that had a "%" in the name of the folder.  Here are some examples...

These are the two files that failed

E:\My Music\FLAC\Jane's Addiction\Jane's Addiction\04 - 1%.flac
E:\My Music\FLAC\Soul Asylum\Grave Dancers Union\11 - 99%.flac

This is one of the folders that failed all of the songs inside of it

E:\My Music\FLAC\Sweet, Matthew\100% Fun\all songs.flac

I tested this out by putting these files back through with flacgetv and sure enough it recognizes them as already the latest version (they are actually 1.1.2).  I then removed the "%" and ran them again and they encoded correctly.  I did the same without flacgetv in the folder and got the same results.  Is the "%" not good in 1.1.3?  No big deal, just something I noticed.

Another thing I noticed was that there is a 4kb difference in filesize from a file I ripped in EAC with 1.1.2 -5 and then converted with the batch file to 1.1.3 --best compared to a file ripped in EAC with 1.1.3 --best (4kb bigger).  I am sure there is some reason for this but I couldn't figure it out.  Any thoughts?
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-30 07:48:56
Another thing I noticed was that there is a 4kb difference in filesize from a file I ripped in EAC with 1.1.2 -5 and then converted with the batch file to 1.1.3 --best compared to a file ripped in EAC with 1.1.3 --best (4kb bigger).  I am sure there is some reason for this but I couldn't figure it out.  Any thoughts?

probably padding.  flac-1.1.2 adds 4k padding by default. 1.1.3 adds 8k, unless it >20min or so in which case it guesses it's a full album and adds 64k padding.  you can override that with the -P option.

Josh
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-30 09:28:31
I tested this out by putting these files back through with flacgetv and sure enough it recognizes them as already the latest version (they are actually 1.1.2).  I then removed the "%" and ran them again and they encoded correctly.  I did the same without flacgetv in the folder and got the same results.  Is the "%" not good in 1.1.3?  No big deal, just something I noticed.
Thanks for the info.  I have done some of my own testing this morning, and can confirm the issue.  Unfortunately I have not found a resolve as yet.

For some reason, when I pass a parameter with a % it gets removed.  Below are two ways to achieve the same thing (well, so I thought).  The first, which is adapted from flac-113.bat, results in the % being removed.  The second works fine.

Code: [Select]
FOR /R %1 %%G IN (*.flac) DO CALL :ListFiles "%%G"
PAUSE
GOTO:EOF
:ListFiles
ECHO %1
GOTO:EOF

Code: [Select]
FOR /R %1 %%G IN (*.flac) DO ECHO "%%G"
PAUSE

I will keep trying.
Title: FLAC re-encoding
Post by: Digisurfer on 2007-01-30 20:39:56
Just wanted to say thanks for this script. I finally decided to switch my complete library from Monkey's Audio to FLAC now that compression is a little better. Mostly my decision to switch was due to the high level of hardware and software support for the format.

This script is a really great find, especially since I've never been completely sure that the -V switch works when using foobar2000 v0.9.4.2. It's also nice that the script will balk at FLAC files containing ID3 tags, particularly since fb2k refuses to say which type of tags are being used. If only fb2k would show the audio MD5 and codec profile (compression level) as well, like it does for WavPack and Monkey's Audio files, then I would be a little bit happier about having switched formats.

I ran into a few FLAC's recently that did indeed have ID3. I used MP3tag v2.37d to sniff them out which worked pretty well, and probably never would have known otherwise, or at least not until I got around to using this script (which was not a guarantee yet at that point). Not sure how fb2k handles the transfer of tags when converting from FLAC to FLAC, but it looks like the ID3 tags are properly converted to Vorbis Comments during conversion. I'm not 100% that the newly created files are 100% clean, especially since telling fb2k to rewrite the tags doesn't seem to fix them. Someone commented on converting to WavPack as an intermediary step which sounds like a good idea to me, so that is how I'm going to handle things from now on just to be safe.

Again, thanks for the great script, and thanks to all the others that have posted some of their own useful comments.
Title: FLAC re-encoding
Post by: Marino13 on 2007-01-31 01:25:17
probably padding.  flac-1.1.2 adds 4k padding by default. 1.1.3 adds 8k, unless it >20min or so in which case it guesses it's a full album and adds 64k padding.  you can override that with the -P option.

Josh
[/quote]


Josh,

The -P function appears to remove all padding, is this correct?  I say that because the files are now 4kb less where before the were 4kb more.
Title: FLAC re-encoding
Post by: jcoalson on 2007-01-31 02:14:49
-P has to be followed by the number of bytes of padding.  it can be 0 for a 0 zero-size padding block (which actually takes 4 bytes because of the block header) or you can say --no-padding for no padding block at all.

not sure exactly why it got exactly 4k smaller, I was just guessing.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-01-31 07:04:37
-P has to be followed by the number of bytes of padding.  it can be 0 for a 0 zero-size padding block (which actually takes 4 bytes because of the block header) or you can say --no-padding for no padding block at all.

not sure exactly why it got exactly 4k smaller, I was just guessing.
I think you must be right.  The script certainly isn't doing anything related.  1.1.2 files has less padding by default, and I assume the conversion process does not add extra padding.
Title: FLAC re-encoding
Post by: gib on 2007-01-31 07:32:45
This script is a really great find, especially since I've never been completely sure that the -V switch works when using foobar2000 v0.9.4.2.

From some tests I ran on that very thing, it does seem to work.  Adding the -V switch to the commandline slowed the encoding speed down, as one would expect.
Title: FLAC re-encoding
Post by: Marino13 on 2007-01-31 13:16:51
-P has to be followed by the number of bytes of padding.  it can be 0 for a 0 zero-size padding block (which actually takes 4 bytes because of the block header) or you can say --no-padding for no padding block at all.

not sure exactly why it got exactly 4k smaller, I was just guessing.



Like this, -P4 or like this -P 4 or is it some other way?

My EAC command line is currently...

--best -V -T "artist=%a" -T "title=%t" -T "album=%g" -T "tracknumber=%n" %s
Title: FLAC re-encoding
Post by: Martin H on 2007-01-31 15:20:26
@gib

I'm guessing that he was reffering to if fb2k would pop up it's console window and show an error message if a mismatch would ever occure i.e. flac.exe returning a non-zero return code.

@Marino13

The FLAC Documentation page for flac.exe shows it in this format "-P #", so that way defenetly works, but i haven't tested to see if the other way also would work. Also, remember that the value given with the "-P" switch of flac.exe is in bytes and not kilobytes, so if you e.g. want to have only 4KB padding added instead of 8KB(if under 20min.), then use "-P 4096".
Title: FLAC re-encoding
Post by: gib on 2007-01-31 18:57:59
@gib

I'm guessing that he was reffering to if fb2k would pop up it's console window and show an error message if a mismatch would ever occure i.e. flac.exe returning a non-zero return code.
Ah!  Now that you mention it, I think you are exactly right.  Thank you. 
And that's a pretty good question, too.
Title: FLAC re-encoding
Post by: Marino13 on 2007-01-31 20:57:36
@Marino13

The FLAC Documentation page for flac.exe shows it in this format "-P #", so that way defenetly works, but i haven't tested to see if the other way also would work. Also, remember that the value given with the "-P" switch of flac.exe is in bytes and not kilobytes, so if you e.g. want to have only 4KB padding added instead of 8KB(if under 20min.), then use "-P 4096".



Yes, the -P 4096 did the trick.
Title: FLAC re-encoding
Post by: probedb on 2007-02-11 21:41:57
First of all thanks for this script, very useful

I've been getting this message on some files tho?

Code: [Select]
Checking Vendor: "Z:\Music\FLAC\White Zombie\La Sexorcisto\14 - White Zombie - Warp Asylum.flac"
________________________________________________________________________
Error: Z:\Music\FLAC\White Zombie\La Sexorcisto\14 - White Zombie - Warp Asylum.flac not found or contains no FLAC vendor string.

File is already the latest version [113]


The files definitely aren't already 113 and haven't been encoded any differently to any of my others so not sure what it means. Also what are these errors?

Code: [Select]
  "Z:\Music\FLAC\Atari Teenage Riot\60 Second Wipe Out\10 - Atari Teenage Riot - Death Of A President D.I.Y.!.flac" [E]
  "Z:\Music\FLAC\Cypress Hill\Black Sunday\05 - Cypress Hill - Lick A Shot.flac" [T]
  "Z:\Music\FLAC\Muse\Hullabaloo (CD1)\01 - Muse - Forced In.flac" [E]
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-11 22:09:29
1. I'm afraid that's down to flacgetv.exe.  It's supposed to only report an errorlevel of 113 if the file is 1.1.3.  It appears it is not.  I would just reprocess these files without flacgetv.exe.

2. An error occurred while trying to process these files. "[T]" indicates that the file failed a test decode, suggesting that it is corrupt. "[E]" indicates that an error occurred when re-encoding - the file passed the initial test decode, but failed verification when re-encoding.  None of these files have been converted.  I don't know why a file would fail re-encoding afte passing the decode test, so it is very possible that these files have ID3v2 tags at the beginning, as per earlier reports in this thread.
Title: FLAC re-encoding
Post by: Teknojnky on 2007-02-12 19:02:42
A few more ideas, should you be bored and/or looking for further improvements.

- note the file sizes before and after re-encoding, show the individual file gains and a summary at the end with the total original and re-encoded sizes.

- note the commandline parameters (in the summary)

- note the script and track encoding start/end date/times and calculate total time spent encoding and the total time the script to scan/test/encode. I understand that encode time is dependent on cpu/drive loads, however it would provide a ball park figure for differences in compression levels etc.

I suggest the above, so the script could be used to easily compare different flac versions and command lines (ie testing alpha1 etc) in a relatively consistent manner along with the results.

edit:

- date/time stamp the logs/summary file names so that they are not overwritten (optionally if you think its necessary)
Title: FLAC re-encoding
Post by: probedb on 2007-02-13 14:46:20
Thanks Synthetic Soul, it really is a very useful script  Is there any way to get it to output the no vendor string files as this is only listed when it processes the file so when you have thousands of files being processed there's no realistic way of finding them?

Cheers again!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-13 15:36:38
@ Teknojnky : some good ideas there.  Thanks for the input.

@ probedb : Try changing the line

Code: [Select]
IF ERRORLEVEL %flacVersion% (

... to :

Code: [Select]
IF %ERRORLEVEL% EQU %flacVersion% (

... in flac-113.bat.  I think this may actually solve it.  Your latest post forced me to do a little more testing with FlacGetV.  It appears it returns 255 (not 113) if no vendor string is found, but the change above should mean that now only 113 will get treated as a 1.1.3 file, and any other return code will mean the file is re-encoded.

In case it is useful, here is the batch file that I used to test FlacGetV:

Code: [Select]
@ECHO OFF

IF EXIST "%~dp0flacgetv.txt" DEL "%~dp0flacgetv.txt"

FOR /R %1 %%G IN (*.flac) DO CALL :ReportVersion "%%G"

GOTO:EOF

:ReportVersion
ECHO %1>>"%~dp0flacgetv.txt"
"%~dp0FLACGETV.EXE" %1>>"%~dp0flacgetv.txt"
ECHO ERROR LEVEL: %ERRORLEVEL%>>"%~dp0flacgetv.txt"
ECHO.>>"%~dp0flacgetv.txt"
GOTO:EOF

If you save that text as "flacversion.bat", put the file in the same folder as FlacGetV.exe (and it's required DLLs), then drag your root folder onto it, it will create "flacgetv.txt" - which lists all files, with the return code and response from FlacGetV.  It may be of some use to you.
Title: FLAC re-encoding
Post by: probedb on 2007-02-14 14:37:49
Thanks for this I'll give it ago when I convert to 1.1.4 sometime this weekend

Hmm, HA isn't making the email notification sticky.
Title: FLAC re-encoding
Post by: Marino13 on 2007-02-15 00:42:32
How would I add a command line to embed a jpeg of the album cover into the new flac file? My folder structure is F:\Artist\Album\tracknumber - title.flac. I have a folder.jpg of each covert art inside the Albums folder. So it is basically F:\Artist\Album\folder.jpg. Any way to do this? I have about 27,000 flac files and would not be able to do hese individually.
I'm not really up on the --picture switch syntax, and I don't really want to get into this too much, but you would reference the file using:

"%~dp1folder.jpg"

So, you would change the encoding command line to something like (not sure if syntax is correct):

Code: [Select]
%pathToFLAC% %flacOptions% --picture="|image/jpeg|||%~dp1folder.jpg" -V -o "%~dpn1-flac-113.flac" %1


SS,

I tried this command line with FLAC 1.1.4 with your script and changed the version to 114 and it worked perfect.  The folders that did not have a folder.jpg in them failed.  I was able to take out the --picture="|image/jpeg|||%~dp1folder.jpg" part of the command line, rename the failed.txt file and drop it back on the batch file and then it encoded any folders that did not have the foder.jpg's in them.  How easy!!  Thanks a bunch.  Now to start the full batch for all 27,000 again.  Seems just like a little while ago I did this with 1.1.3.  Oh yeah, it was just last month.

Josh,

This is awesome.  I really do appreciate your hard work.
Title: FLAC re-encoding
Post by: jcoalson on 2007-02-15 00:50:48
no prob.  BTW in flac 1.1.4 this now also works:

--picture="||||%~dp1folder.jpg"

or just

--picture="%~dp1folder.jpg"

it will try and guess the mime type from the file contents.

Josh
Title: FLAC re-encoding
Post by: Vince_TB on 2007-02-15 01:55:03
Hi, i was just wondering if :

MP3 (LAME) ripped from source cd in 192 kbps CBR = a conversion from a FLAC to the same bitrate.

Thanks, i wish this question haven't been asked.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-15 06:36:28
This thread is really about re-encoding (FLAC - FLAC), but yes, FLAC - MP3 will get you the same result as CD - MP3.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-16 22:33:39
Just to let you know that I have made a couple of small updates.

I've added the FlacGetV change suggested to probedb, and it now reports bytes saved by any re-encoding and the setting used (as suggested by Teknojnky) in the final summary.

http://www.synthetic-soul.co.uk/files/flac-113.bat (http://www.synthetic-soul.co.uk/files/flac-113.bat)
Title: FLAC re-encoding
Post by: HydroFred on 2007-02-17 02:46:07
When will flac-114.bat see the light of day?
Title: FLAC re-encoding
Post by: Teknojnky on 2007-02-17 03:26:42
there is no need really,  you can change the minimum flac version at the top of the batch file.

change it to 114 to have it check for files that are less than 1.1.4 flac.

and thanks again Synthetic Soul, looks even better.
Title: FLAC re-encoding
Post by: PatchWorKs on 2007-02-17 12:17:01
As already said in other 3ads, unfortunally SS bat script won't work with ogg-flacs 
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-17 12:42:50
All my batch file does is use FLAC.EXE to encode FLACs to FLAC.  If FLAC can't handle Ogg FLAC files as input then it can't handle Ogg FLAC files.  Nothing I can do.
Title: FLAC re-encoding
Post by: HydroFred on 2007-02-17 16:12:46
Just finished converting my collection from 1.1.3 to 1.1.4 and saved 0.25%

Code: [Select]
2174 file(s) processed
2174 file(s) encoded
0 file(s) returned an error

Settings used: FLAC v.114 '--no-padding --replay-gain -8'
Bytes Saved:   194153883 bytes
Title: FLAC re-encoding
Post by: probedb on 2007-02-18 00:17:43
Hmm odd things happening...got this error:

Quote
"Z:\Music\FLAC\Deftones\Around The Fur\03 - Deftones - Mascara.flac" [E]


Yet if I manually run the encode it works?

Quote
Z:\Music\FLAC\Deftones\Around The Fur>"C:\Program Files\FLAC\flac.exe" -V -8 "03 - Deftones - Mascara.flac" -o test.flac

flac 1.1.4, Copyright © 2000,2001,2002,2003,2004,2005,2006,2007  Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

03 - Deftones - Mascara.flac: Verify OK, wrote 24950028 bytes, ratio=0.998

Z:\Music\FLAC\Deftones\Around The Fur>
Title: FLAC re-encoding
Post by: Zoom on 2007-02-18 02:10:35
Hmm odd things happening...got this error:
...
Yet if I manually run the encode it works?
...
It could be a hardware issue such as RAM or Hard Disk failure.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-18 08:16:02
Yes, I can only suggest a temporary glitch.  The process should be exactly the same.  If you still have a copy of the source file maybe you could try it again with the script.
Title: FLAC re-encoding
Post by: probedb on 2007-02-18 10:54:13
Bugger, oh well  I also noticed it strips % characters out so fails on all files with that in the path, also the ^ character got repeated 4 times in a filename producing something that didn't exist, i.e.

E=MC^2.flac

became

E=MC^^^^2.flac

Thumbs up tho, so nice being able to leave a script running  Plus it's meant I've found a few corrupt FLACs in my collection I didn't know about so that's very useful!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-18 10:59:48
Yes, this is one bug reported previously that I have no idea how to fix - it's because batch files use % to denote variables, and the path is being parsed when passed as a parameter.  I'm afraid this is just going to have to be worked around...

Edit: Is that Big Audio Dynamite?  I'm a big fan of Mick Jones.
Title: FLAC re-encoding
Post by: probedb on 2007-02-18 11:18:47
Yes, this is one bug reported previously that I have no idea how to fix - it's because batch files use % to denote variables, and the path is being parsed when passed as a parameter.  I'm afraid this is just going to have to be worked around...

Edit: Is that Big Audio Dynamite?  I'm a big fan of Mick Jones.


No worries

It is indeed! It came out when I was a kid and always loved that song so I had to buy their best of CD
Title: FLAC re-encoding
Post by: Johncan on 2007-02-18 12:49:47
I have a dumb question as I am not a coder.  What is the FLAC compression setting of the batch file.  If I am guessing correctly, it is FLAC 8.  Is this correct?  I have been encoding at FLAC 6 and was wondering if I would gain much more hard drive space by going to FLAC 1.1.4 with compression of 8.

John
Title: FLAC re-encoding
Post by: gottkaiser on 2007-02-18 12:56:56
I have a dumb question as I am not a coder.  What is the FLAC compression setting of the batch file.  If I am guessing correctly, it is FLAC 8.  Is this correct?  I have been encoding at FLAC 6 and was wondering if I would gain much more hard drive space by going to FLAC 1.1.4 with compression of 8.

John


You can edit it with a text editor. "-8" is the best and slowest compression. You don't gain much if you change from -6 to -8. Just some MB in an album.
Title: FLAC re-encoding
Post by: Franklin on 2007-02-18 18:28:56
Hi,

I like this bat file very much, thanks for it.

There are two questions left for me:

1. Will there be a 1.1.4 version?
2. Is it possible to print the saved bytes in MB, too?

Regards
Franklin
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-18 18:53:22
1. The current version works with FLAC 1.1.4.  There is simply a variable called (IIRC) flacVersion.  This needs to be set to 114 for 1.1.4, 115 for 1.1.5, etc.  This is only relevant if you use FlacGetV with the batch file.
2. I did consider this, but apathy got the better of me.  I figured people could do the calculation themselves if they felt the need.

To be honest, I never intended this script to become so big.  It was supposed to just be a 'simple' script for users to re-encode with a little safety.
Title: FLAC re-encoding
Post by: jamesbaud on 2007-02-19 05:27:51
1. The current version works with FLAC 1.1.4.  There is simply a variable called (IIRC) flacVersion.  This needs to be set to 114 for 1.1.4, 115 for 1.1.5, etc.  This is only relevant if you use FlacGetV with the batch file.
2. I did consider this, but apathy got the better of me.  I figured people could do the calculation themselves if they felt the need.

To be honest, I never intended this script to become so big.  It was supposed to just be a 'simple' script for users to re-encode with a little safety.


Your program is a big hit! You should post this on your web site! 

(I meant that you should make it as prominent as Tag and Wapet)
Title: FLAC re-encoding
Post by: vinnie97 on 2007-02-19 06:51:52
meh, I should probably know better but this batch file is being problematic for me. 

"'"FLAC.EXE"' is not recognized as an internal or external command,
operable program or batch file."

Yet I have it in the same directory as the batch file.  What obvious factor am I overlooking?
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 07:21:56
I have created a batch file (http://www.synthetic-soul.co.uk/files/flac-113.bat) to convert to FLAC 1.1.3.

If you drag a file or folder onto the batch file it will process all FLAC files within (including subfolders).

It will first use -t to test the source file, and only if the test is successful will then re-encode the file using -fto force an overwrite .  Edit:  Version 1.1.0 now encodes to a new file, and if the encode was successful will then overwrite the source with the new file (MOVE /Y <new file> <old file>). This should now ensure that the souce is only ever overwritten if the process has been 100% successful.*

If any files do fail testing or re-encoding they will be listed once all processing has finished.

To use the batch file you need to first open it in Notepad and amend the lines:

Code: [Select]
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
... to suit.  You really only need quotes around pathToFLAC if the path contains spaces.  The switches -V -f are hardcoded into the command line already.
 
Hopefully some people will find this useful.

[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]* DISCLAIMER: But, of course, it may.  Don't blame me.  Test before you run it on anything precious.[/size]
Hello, any chance to have a script for convert from old flac to flac 1.1.4, with test before and GUI ?
It's hard for me all these things... I tested to re-encode with omni encoder and it deleted my old flac without giving new flac, just because of an error on an old file. Thanks
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 07:29:44
Your program is a big hit! You should post this on your web site! smile.gif
Then I'd have even more people hassling me.

I'm more likely to remove it than publish it!

Yet I have it in the same directory as the batch file. What obvious factor am I overlooking? sad.gif
1. That a batch file is simply a text file and can be opened, or edited, in Notepad. 2. That when a script runs it runs from system32, where cmd.exe resides, and not the containing folder.

Either edit the script to point to the proper location of your FLAC.EXE (all config is at the top) or put FLAC.EXE in a folder in your path (like system32 or your windows folder)  - which I would always recommend anyway.

Hello, any chance to have a script for convert from old flac to flac 1.1.4, with test before and GUI ?
It's hard for me all these things... I tested to re-encode with omni encoder and it deleted my old flac without giving new flac, just because of an error on an old file. Thanks
No chance of a GUI in the next five years or so.  This script will convert to 1.1.4 (see a few posts up - #147), and performs two unique tests before overwriting.
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 07:30:07
Hi again, maybe flac-113.bat can use flac 1.1.4 ?
But how configure your script ?
Sorry, I'm beginner with this things...
Where I set the path for flac.exe ?
regards
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 07:38:48
If you open the script in Notepad you will see the following near the top:

Code: [Select]
REM ######################################################
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
SET retainListOfSuccessfulFiles=0
SET flacVersion=114
REM ######################################################

Use pathToFLAC to set the path to your FLAC.EXE file.
If you are using FlacGetV to check the file's current version before encoding (search this thread for FlacGetV for more info) then you will need to set flacVersion to your required version.  All other variables have been explained somewhere in this thread (search for the var name using the search at the bottom-left of this page).
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 07:41:48
If you open the script in Notepad you will see the following near the top:

Code: [Select]
REM ######################################################
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
SET retainListOfSuccessfulFiles=0
SET flacVersion=114
REM ######################################################

Use pathToFLAC to set the path to your FLAC.EXE file.
If you are using FlacGetV to check the file's current version before encoding (search this thread for FlacGetV for more info) then you will need to set flacVersion to your required version.  All other variables have been explained somewhere in this thread (search for the var name using the search at the bottom-left of this page).

Thank you very much, I modify the path:


REM ######################################################
SET pathToFLAC="C:\Soft\Audio\FLAC_RE-ENCODE\FLAC.EXE"
SET flacOptions=-8
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
SET retainListOfSuccessfulFiles=0
SET flacVersion=114
REM ######################################################

but when I launch, I have:
"To run this script, please pass a valid file or folder as a parameter."
What else to modify, please ? (and sorry to bother you)
Regards
Title: FLAC re-encoding
Post by: probedb on 2007-02-19 09:33:35
but when I launch, I have:
"To run this script, please pass a valid file or folder as a parameter."
What else to modify, please ? (and sorry to bother you)
Regards


You give it a directory as a parameter, I'm pretty sure it says in this thread if you read it.

i.e.

Code: [Select]
flac-113.bat "c:\my music"
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 09:39:06
probedb is correct.  Either run the script on the command line as he suggests, or simply drag a folder onto the batch file icon.  If you run:

Code: [Select]
flac-113.bat "c:\my music"

.. the script will process all files and subfolders in "C:\My Music".  Similarly, if you drag the folder "My Music" onto the batch file icon.
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 09:47:31
probedb is correct.  Either run the script on the command line as he suggests, or simply drag a folder onto the batch file icon.  If you run:

Code: [Select]
flac-113.bat "c:\my music"

.. the script will process all files and subfolders in "C:\My Music".  Similarly, if you drag the folder "My Music" onto the batch file icon.

GREAT !!!!!!!!!!
IT WORKS !!!!!!!!
Thanks to all of you !
I still don't know how drag a folder onto the batch file icon, bot with dos command it works.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 09:59:15
Dragging a folder is as simple as it sounds. * If the batch file is not visible but you have another Explorer window open listing the file you can drag the folder onto the relevant taskbar item and wait a second, without releasing the drag, for the window to become visble, then continue your drag.

I assumed everyone was using the drag'n'drop approach.  I generally write the scripts so that non-command line users can use them as well.
Title: FLAC re-encoding
Post by: PatchWorKs on 2007-02-19 10:13:29
All my batch file does is use FLAC.EXE to encode FLACs to FLAC.  If FLAC can't handle Ogg FLAC files as input then it can't handle Ogg FLAC files.  Nothing I can do.

Well, FLAC.exe is able to re-encode a single OGG-flac file to .flac but won't "*.ogg" input (strange, isn't it ?)
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 10:19:56
Sorry, I didn't realise that Ogg-FLAC files had a .ogg extension!

You may just need to amend line 91 to:

Code: [Select]
IF /I [%~x1] EQU [.ogg] (

... and line 115 to:

Code: [Select]
FOR /R %1 %%G IN (*.ogg) DO CALL :ListFiles "%%G"

... and amend line 176 (the line that runs the encode) accordingly.
Title: FLAC re-encoding
Post by: PatchWorKs on 2007-02-19 10:45:57
Sorry, I didn't realise that Ogg-FLAC files had a .ogg extension!


OK, it works now (sincerly i already changed that lines, but my FLAC.exe was corrupted  )

BTW 2 errors:

1. (baddest) directory drop won't work

2. testing fails (WARING, cannot check MD5 signature since it was unset in the STREAMINFO)
Title: FLAC re-encoding
Post by: vinnie97 on 2007-02-19 10:51:58
Yet I have it in the same directory as the batch file. What obvious factor am I overlooking? sad.gif
1. That a batch file is simply a text file and can be opened, or edited, in Notepad. 2. That when a script runs it runs from system32, where cmd.exe resides, and not the containing folder.

Either edit the script to point to the proper location of your FLAC.EXE (all config is at the top) or put FLAC.EXE in a folder in your path (like system32 or your windows folder)  - which I would always recommend anyway.

Thanks so much...I completely forgot about scripts utilizing the system directory!  I also have little experience with them but this did the trick.  It's probably been answered already but will this work with the FLAKE encoder as well?

And here's another thank you for this most useful batch (the ratio reading is an extra useful touch!).
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 11:12:46
BTW 2 errors:

1. (baddest) directory drop won't work

2. testing fails (WARING, cannot check MD5 signature since it was unset in the STREAMINFO)
1. In what way?  Are you saying that it works if you run on the command line but not if you drag/drop?  If so, that would be really freaky!

2. Hmm.. guess that must be an Ogg-FLAC thing.  Certainly not something I'll be supporting further, sorry.

It's probably been answered already but will this work with the FLAKE encoder as well?
Currently the script uses FLAC's -t switch to test the files, and then uses FLAC, with the -V switch, to encode.

You could use FLAC.EXE to perform the test and FLAKE.EXE to do the encode, but you'd have to amend line 176 to run FLAKE, and remove the -V switch  - which I don't think Flake has.
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 12:38:16
Some files encoded with flac frontend with 1.1.4 -8 are re-encoding with flac-113.bat last version...
Do I have to put any FlacGetV file into the same directory ?
Regards
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 13:03:19
Yes.  The version check will only be made if FlacGetV (http://www.hydrogenaudio.org/forums/index.php?showtopic=51084), and the DLLs it requires (all included in the download) are in the same directory as the batch file.

I guess i should have a readme, but all the info can be found in this thread, so I didn't bother.  I realise that it makes it more of a task for someone only joining the thread now.
Title: FLAC re-encoding
Post by: probedb on 2007-02-19 13:25:31
I'm going to see if I can amend your script to do a check even if the version is up to date. I just want to make sure that after reripping some broken tracks that all my FLACs are now 100% OK
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 13:30:17
I have an existing script that will use FLAC -t on a folder of files, if that's what you want.

http://www.synthetic-soul.co.uk/files/flac-verify.bat (http://www.synthetic-soul.co.uk/files/flac-verify.bat)

Pass it a folder and it will go through all files, run FLAC -t, and report any that fail at the end.

Hopefully that will do what you need.  Job done!
Title: FLAC re-encoding
Post by: probedb on 2007-02-19 13:46:29
I have an existing script that will use FLAC -t on a folder of files, if that's what you want.

http://www.synthetic-soul.co.uk/files/flac-verify.bat (http://www.synthetic-soul.co.uk/files/flac-verify.bat)

Pass it a folder and it will go through all files, run FLAC -t, and report any that fail at the end.

Hopefully that will do what you need.  Job done!


Sweet  Cheers for that! Is it recursive or should I try and mangle it to be recursive?
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 13:49:46
It is recursive.

Glad to be of further help.
Title: FLAC re-encoding
Post by: ludwig on 2007-02-19 14:05:07
Once more THANKS to YOU !!!!
Wonderful Job...
Title: FLAC re-encoding
Post by: probedb on 2007-02-19 14:08:58
It is recursive.

Glad to be of further help.


Awesome  Thanks again.
Title: FLAC re-encoding
Post by: aliendesaster on 2007-02-19 18:28:35
Nice and fast synthetic-soul, your solution is much appreciated!
Title: FLAC re-encoding
Post by: dandomoore on 2007-02-19 19:57:39
Got the same problem with drag n drop - folders don't work, and if you drag multiple files, it processes only the first one.... I assumed it was because I was running vista.....
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-19 21:37:15
Curious!

The multiple files thing makes sense - the script is only expecting one parameter - a FLAC file or a folder.

No idea what the change in drag'n'drop functionality is though, sorry.
Title: FLAC re-encoding
Post by: cpalcott on 2007-02-20 01:21:37
Is there a quick easy fix to get te batch file to write the proper version to the encode tag? It's still showing 1.1.3 in the tags.
Title: FLAC re-encoding
Post by: drbeachboy on 2007-02-20 04:00:14
Is there a quick easy fix to get te batch file to write the proper version to the encode tag? It's still showing 1.1.3 in the tags.

FLAC itself writes the encoder name to the file. If you are talking about the "encoding" tag that REACT writes to the file, then you need to change the [USERSETTINGS] (Near the bottom) of the REACT config file to: Ver_Flac=1.1.4.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-20 06:45:53
As drbeachboy said, FLAC writes the vendor string to the file.  If it's writing 1.1.3 you must still be running FLAC 1.1.3.

If you are talking about a specific tag that you have set as "1.1.3" I guess you'll need to use a tagging app to update that.  I can't add it to the script as it is non-standard.
Title: FLAC re-encoding
Post by: cpalcott on 2007-02-20 12:52:21
I downloaded Flac 1.1.4 and overwrote the files in the existing Flac folder (C:\Program Files\Flac), downloaded the latest batch file with the changed version number in the config, yet when I watch the encoding process it is still showing that it is encoding to 1.1.3. However, at the end of the encode it lists the version as 114 (from the config listing I assume). Then when I re-convert those same files,I would expct them to be skipped and come up as already in correct version, but they don't they reprocess. Could this have something to do with the Flacgetv? Do I need to specify a path to flac.exe. Before it seemed to default C:\Program Files\Flac. Thanks for your help.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-20 13:00:01
I think you have two versions of FLAC on your machine.  Do a search in Explorer.

To explicitly use the one in Program Files set the script's pathToFLAC variable accordingly.

I suspect the other version is in your Windows folder.  You may have even done this after a recommendation from me!  I personally think it's best to have the EXEs in a folder in PATH, like your Windows folder, so wherever you open a command line you can just use FLAC.EXE, not "C:\Program Files\Flac\FLAC.EXE".  You should only have one version though, to save confusion.
Title: FLAC re-encoding
Post by: probedb on 2007-02-20 13:07:12
I found a copy of flac.exe in Windows/System32 and I have no idea what put it there!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-20 13:10:28
I snuck into your room, skiffed your toothbrush, and put FLAC in your system32 folder to play with your mind.

Nah, I'm just playing wit ya.  I honestly have no idea.

Blame the FLAC pixies...
Title: FLAC re-encoding
Post by: cpalcott on 2007-02-20 13:19:00
Good call...that took care of it. Thanks for your help!
Title: FLAC re-encoding
Post by: probedb on 2007-02-20 16:26:24
I snuck into your room, skiffed your toothbrush, and put FLAC in your system32 folder to play with your mind.

Nah, I'm just playing wit ya.  I honestly have no idea.

Blame the FLAC pixies...


They're quite mischievous I've heard...I'll keep an eye out in future.
Title: FLAC re-encoding
Post by: aliendesaster on 2007-02-21 11:57:25
Recently I ran the bat, skipped testing a flac with keys ctrl+c and afterwards even skipped reencoding to 1.14 on a flac, sadly source flac was deleted and incomplete renamed to source flac. While this time the source file is easily restore (and could have been reripped easily as well) I had initially hoped your batch file could detect this.

Scheme:
testing process + ctrl+c starts...
encoding process + ctrl+c starts...
deletetion of source & renaming of output file starts regardless if output file is complete

Anyway instead of deleting a file I'd lik to have an option so that source files are moved to root:/somedir and must be deleted manually. I don't know batch scripting that well but since I guess one cannot detect if execution of some programm started by a batch has been halted with ctrtl+c my proposed behaviour would help.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-21 12:39:42
As you say, I don't think I can detect users messing about in this way.

The option to move the source is quite achievable. In essence, line 189 could be amended from:

Code: [Select]
MOVE /Y "%~dpn1-flac-113.flac" %1

.. .to:

Code: [Select]
IF NOT EXIST "C:\My\New\Root\%~p1" MKDIR "C:\My\New\Root\%~p1"
MOVE /Y %1 "C:\My\New\Root\%~pnx1"
MOVE /Y "%~dpn1-flac-113.flac" %1


Progressing this further, 'C:\My\New\Root' could be set in a variable (preferably at the top with the other config vars), e.g.:

Code: [Select]
movePath=C:\My\New\Root
...
IF [%movePath%] NEQ [] (
    IF NOT EXIST "%movePath%%~p1" MKDIR "%movePath%%~p1"
    MOVE /Y %1 "%movePath%%~pnx1"
)
MOVE /Y "%~dpn1-flac-113.flac" %1

Edit: Tested and updated code.
Title: FLAC re-encoding
Post by: aliendesaster on 2007-02-23 01:34:45
Thanks for your support, I will try it out later.
Title: FLAC re-encoding
Post by: foo_fighter on 2007-02-23 05:11:48
I've used the bat script on ~8000 files or so and it works great.

I had trouble with the following:
id3v2 tags: had to cut then paste the tags back with mp3tag

1 file had an error due to missing md5 checksum

The most false errors were due to files with  ' (apostrophe) in the filename or % in the filename.

When passed individually they work but not when passed as a directory. It always thought they were missing.

Any easy fix for that?

Thanks.
Title: FLAC re-encoding
Post by: krabapple on 2007-02-25 10:18:42
How does one add more options to the default "SET flacOptions=-8"?
Is it a matter of adding more "SET flacOptions=" lines to the code, or do the options all get added on one line?
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-25 12:50:47
No, just add more switches to that one line, e.g.:

Code: [Select]
SET flacOptions=-5 -A hamming --no-padding --no-seektable

The script already adds -V, so no need to add that.
Title: FLAC re-encoding
Post by: krabapple on 2007-02-26 22:41:41
I tried this

SET flacOptions=-8 -A tukey(0.25) -A gauss(0.1875) -b 4096

and it refused to run
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-02-27 07:49:17
Sorry, try this:

Code: [Select]
SET flacOptions=-8 -A "tukey(0.25)" -A "gauss(0.1875)" -b 4096


The script gets confused with the brackets.
Title: FLAC re-encoding
Post by: tylast on 2007-03-04 22:19:01
OK...I got lost in the numerous pages.  What's the most current bat file to convert to 1.1.4??
Thanks!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-03-04 22:21:35
http://www.synthetic-soul.co.uk/files/flac-113.bat (http://www.synthetic-soul.co.uk/files/flac-113.bat)
Title: FLAC re-encoding
Post by: tylast on 2007-03-04 22:55:34
Thanks!  OK, figured out that I needed to actually drag/drop the top most folder on the bat file. 

Is this bat using the 1.1.4 dll???
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-03-05 07:51:32
To save all such further questions I have finally gotten around to writing a readme (of sorts).

http://www.synthetic-soul.co.uk/files/flac-113.txt (http://www.synthetic-soul.co.uk/files/flac-113.txt)

I realise that it is a little unfair to expect new users finding this thread to scan the whole thread and piece the information together.  It is worth noting that any questions still left unanswered after reading the document may have been answered here already though.
Title: FLAC re-encoding
Post by: Tim Morris on 2007-06-22 15:45:15
Neil,

Just wanted to add my thanks to the rest. I was going to use Foobar, but that would have meant transcoding to a different folder and then moving all the artwork across.

Often the simplest solutions are the best.

Tim
Title: FLAC re-encoding
Post by: Tim Morris on 2007-06-23 12:58:28
One Minor problem I came across yesterday is that it won't accept track names with a % symbol in them. At a guess I'd say there's not a lot you can do about that.

Tim
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-06-23 18:49:51
Yes, you're right.  This was reported to me before, and I spent some time trying to work around it, but could not.  It would involve a total re-write, and even then I'm not sure.  Sorry.
Title: FLAC re-encoding
Post by: madorangepanda on 2007-06-23 19:09:03
Thanks for this, shaved off half a gig using this yesterday going from various old Flac versions.

One problem, exiting the script part way through I ended up with a corrupted file. Is there any way to exit safely? I was simply able to re-rip the file so it didn't matter much.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-06-24 06:47:03
Sorry, AFAIK I have no control over stopping a script.
Title: FLAC re-encoding
Post by: dagordon on 2007-07-10 16:35:37
For us Vista users out there, there's a problem if you try to drop a folder onto flac-113.bat. The problem also happens with flac-verify, another one of Synthetic Soul's invaluable scripts.

There's an easy solution. With both flac-113.bat and flac-verify.bat, find the line

Code: [Select]
 IF %~z1 EQU 0 (CALL :FolderAction %1) ELSE (CALL :FileAction %1)


Replace 'IF %~z1 EQU 0' with 'IF %~x1x==x', yielding

Code: [Select]
 IF %~x1x==x (CALL :FolderAction %1) ELSE (CALL :FileAction %1)


Explanation:

In previous versions of Windows %~z1 would yield the file size of the object passed to the batch file; if it's a folder it would be 0. But in Vista for whatever reason %~z1 is not 0 if a folder is passed (incidentally, it doesn't even seem to be the folder's size).

So the fix looks at the extension of what's passed to the batch file; if it's a file then it has an extension, if it's a folder it has none.
Title: FLAC re-encoding
Post by: paulgj on 2007-08-02 07:31:03
Hello,

I love the script but I am having a recurring problem when running it, which may or may not be related to the script itself.

When I set the script to run a very large number of converts (i.e. I drop a folder on it with many hundreds if not thousands of files) I find that eventually the converting will pause or "stall" at a certain percentage of a file and the CPU usage will drop to zero (according to the task manager), it will then resume after maybe a minute or so and then stop again later in the file.

If I cancel the script and re-run the behavior will return almost immediately, but If I reboot I can rerun a lot of files again before the problem repeats itself. 

I'm wondering if there's some kind of memory leak?

Anyone else have this problem?  Running WinXP SP2 with 768MB RAM

Thanks for any ideas.
-Paul
Title: FLAC re-encoding
Post by: ludwig on 2007-11-07 21:23:52
Hi, I don't know why, but since 1.2.0 then 1.2.1, there're more and more failed. And something strange: if I download for instance a concert from a p2p website, then use the script,
1) I have the track 05 failed;
2) I download again only the 05; then use script again (on all the concert files)
3) 05 is ok, but 06 failed, whereas it was 1.2.1 and ok just before !!!!

What's wrong ?

Regards
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-11-07 21:57:00
Personally I have no idea; it doesn't appear to make logical sense.

Perhaps you could post some of the errors/reports you have been receiving.
Title: FLAC re-encoding
Post by: wdekler on 2007-11-11 21:30:04
I just used flac-113 (with dagordon's Vista fix) to convert a bunch of flac files. I noticed that some files failed to convert but I'm not sure why (for example) these files fail:

"c:\audio\Collectie\Robert Cray Band\False Accusations\07 - The Last Time (I Get Burned Like This).flac" [E]
"c:\audio\Collectie\Robert Cray Band\Twenty\02 - That Ain't Love.flac" [T]

I've already manually converted them to flac 1.21 without any problems...


thanks!
Title: FLAC re-encoding
Post by: Synthetic Soul on 2007-11-11 22:24:45
It's possible that the brackets and apostrophe are causing problems.  I know there was an issue with percent signs; it's possible that these characters are throwing it out also.

I'm not supporting the script anymore, and I cannot test on Vista.  Sorry.

I would use foobar.
Title: FLAC re-encoding
Post by: wdekler on 2007-11-11 23:15:51
OK,thanks. I guess that the brackets and the ' character are the culprits here... 
Title: FLAC re-encoding
Post by: Mr Bungle on 2007-11-17 10:50:19
Hi,

Can anyone advise me of the official tag for stating the encoder version?

It seems foobar is looking for the "tool" field.  This worked fine when I was ripping with EAC+MAREO+FLAC&OGG - I ended up with the tool field being populated for both the ogg and FLAC files and foobar was happy.

Now I am trying flac-113.bat with FlacGetV and finding the tool tag is remaining untouched.  I know the re-encoding is working as FlacGetV reports the file as being the new version, and the file is smaller due to better compression (1.21 vs 1.1.2).  However, foobar is not looking at whatever tag is being used, and instead looks at the tool tag with the old version.

EDIT: Is it VORBIS_COMMENT?

Also, is there a way of incorporating metaflac with parameter --add-replay-gain into the batch file?  Or should I just use have --add-replay-gain in the 'SET flacOptions' section?  Note some of my files already have replay-gain tags, obtained using metaflac.exe and glob.exe.

Regards,
Jeff
Title: FLAC re-encoding
Post by: I am all FLAC on 2008-01-05 16:16:13
For Linux users put this script in your path.
Code: [Select]
#!/bin/sh

OUTPUT="recoded"
mkdir $OUTPUT

for f in *flac; do
flac "$f" --best -V -o $OUTPUT/"$f"
done


It makes a directory "recoded" in the current directory (where the flac files you want to re-encode are) and re-encodes to that new directory.

Afterwards can you just type
Code: [Select]
rm *flac
mv recoded/* .
rm -r recoded

And your album is re-encoded 
Title: FLAC re-encoding
Post by: jcoalson on 2008-01-07 00:02:33
even simpler:
Code: [Select]
mkdir recoded
flac --output-prefix=recoded/ --best -V *.flac && mv recoded/*.flac . && rmdir recoded
Title: FLAC re-encoding
Post by: ludwig on 2008-01-16 12:48:42
@ jcoalson
you wrote: "mkdir recoded
flac --output-prefix=recoded/ --best -V *.flac && mv recoded/*.flac . && rmdir recoded"
Could you give the whole script / way to do the same under linux, please ?
I'm beginner
Regards
Title: FLAC re-encoding
Post by: jcoalson on 2008-01-16 16:08:07
that is how you do it in linux, it will work in evey shell that I know of (sh, bash, csh, etc)
Title: FLAC re-encoding
Post by: ludwig on 2008-01-17 21:59:21
that is how you do it in linux, it will work in evey shell that I know of (sh, bash, csh, etc)

Thank you, again, again and again, for all your work and generosity !
Title: FLAC re-encoding
Post by: jcoalson on 2008-01-18 02:08:03
my pleasure, always glad to hear when it's useful.

bash is also really useful for all kinds of things.  if you're new, this book is good: http://www.oreilly.com/catalog/bash3/?CMP=AK (http://www.oreilly.com/catalog/bash3/?CMP=AK)
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-01-23 04:37:18
Hi everybody, and big thanks to Synthetic Soul for this useful script ! 

This script would be perfect for me... if only I could specify a "source" and a "destination" directory ! I've just got a new HD, and I need to copy all my 20.000+ FLAC files to it. But I'd like to take this opportunity to verify them / make sure they're good before re-encoding them and copying them to the new HD (no need to delete source files BTW). So that I'm sure that all the copied files are perfect (they will be within a RAID 5 array, so they will be quite safe there... once I can copy them of course).

So I need to use some efficient and secure tool (this script ? foobar ? something else ?) that can :
- take a source AND a destination directory,
- scan the source directory (and all its subfolders, sub-subfolders, etc.)
- check the FLAC files for corruption / non-proper id3v2 tags, etc.,
- if one given FLAC file is good, re-encode it and copy it to the new destination directory (preserving folder hierarchy of course, i.e. creating all necessary folders within the destination directory),
- if not, log the faulty FLAC file (i.e. give me some text report of all failed files so I can check them one by one manually).

Again, Synthetic Soul's script would be perfect for me... if only it had this feature implemented.

Can somebody please help me ? Many thanks in advance.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2008-01-25 11:05:48
The code below is a hacked version of the script.  This script adds the following variables:

Code: [Select]
SET srcRoot=C:\Source Folder
SET dstRoot=D:\Destination Folder
So, if your files are in the structure "C:\My Music\<artist>\<album>" you should set srcRoot to C:\My Music.

Ensure that the paths are accurate, and in the same format - i.e.: if you leave a slash at the of srcRoot ensure that dstRoot also ends in a slash.  The script will simply take the path of the source file and replace the text set in srcPath with that in destPath, so "C:\Source Folder\Pixies\Doolittle\01 - debaser.flac" will convert to "D:\Destination Folder\Pixies\Doolittle\01 - debaser.flac".

I have tested, briefly, but you would do well to test thoroughly yourself, before running on your library.


Code: [Select]
@ECHO OFF
CLS

REM FLAC-113-HACK.BAT Written by Neil Popham, 2008 (neilpopham@bigfoot.com)

SET batchname=FLAC-113-HACK.BAT
SET version=0.0.1
TITLE=%batchname%, Version %version%

REM ######################################################
SET pathToFLAC="FLAC.EXE"
SET flacOptions=-8
SET retainListOfFailedFiles=1
SET retainListOfProcessedFiles=0
SET retainListOfSuccessfulFiles=0
SET flacVersion=121
SET srcRoot=C:\Source Folder
SET dstRoot=D:\Destination Folder
REM ######################################################

REM Check whether a valid file or folder has been passed
IF NOT EXIST %1 DO GOTO NoParams

REM Set counters
SET /A noProcessed=0
SET /A noErrors=0
SET /A noEncoded=0
SET /A noSkipped=0
SET /A srcBytes=0
SET /A dstBytes=0

REM Set path to the list of failed files depending on whether it is to be kept or not
IF [%retainListOfFailedFiles%] EQU [1] (
    SET pathForFails=%~dp0%
) ELSE (
    SET pathForFails=%TEMP%\
)

REM Set path to the list of successful files depending on whether it is to be kept or not
IF [%retainListOfSuccessfulFiles%] EQU [1] (
    SET pathForSuccess=%~dp0%
) ELSE (
    SET pathForSuccess=%TEMP%\
)

REM Set path to the list of files to process depending on whether it is to be kept or not
IF [%retainListOfProcessedFiles%] EQU [1] (
    SET pathForList=%~dp0%
) ELSE (
    SET pathForList=%TEMP%\
)

REM Clear file used to store failed filenames
IF EXIST "%pathForFails%flac-113-failed.txt" DEL "%pathForFails%flac-113-failed.txt"

REM Clear file used to store successful filenames
IF EXIST "%pathForSuccess%flac-113-successful.txt" DEL "%pathForSuccess%flac-113-successful.txt"

REM Clear file used to store the list of files to process
IF EXIST "%pathForList%flac-113-processed.txt" DEL "%pathForList%flac-113-processed.txt"

REM Check whether the parameter is a single file or a folder
IF %~z1 EQU 0 (CALL :FolderAction %1) ELSE (CALL :FileAction %1)

REM Calculated bytes saved
SET /A dffSize=%srcSize%-%dstSize%

REM Report results
ECHO ________________________________________________________________________
ECHO.
ECHO %noProcessed% file(s) processed
IF EXIST "%~dp0FLACGETV.EXE" ECHO %noSkipped% file(s) skipped (already latest version)
ECHO %noEncoded% file(s) encoded
ECHO %noErrors% file(s) returned an error
IF %noErrors% GTR 0 CALL :ReportFiles
ECHO.
ECHO Settings used: FLAC v.%flacVersion% '%flacOptions%'
ECHO Bytes Saved:  %dffSize% bytes

REM Pause
ECHO.
ECHO Press any key to exit
PAUSE >NUL

REM End
GOTO:EOF

REM ==========================================
REM  FileAction : single file has been passed
REM ==========================================
:FileAction
REM Do we have a FLAC file?
IF /I [%~x1] EQU [.flac] (
    CALL :Encode %1
) ELSE (
    REM Do we have a TXT file?
    IF /I [%~x1] EQU [.txt] (
        REM Process the list of files in the file
        SET pathForList="%~dp1"
        CALL :ProcessList "%~nx1"
    ) ELSE (
        GOTO NoParams
    )
)
GOTO:EOF

REM =======================================
REM  FolderAction : folder has been passed
REM =======================================
:FolderAction
REM Check folder and subfolders for FLAC files,call ListFiles for each file, and then Encode
ECHO Processing: "%~1"
ECHO.
REM Create temporary list of files to process
ECHO Creating list of files to process
ECHO.
FOR /R %1 %%G IN (*.flac) DO CALL :ListFiles "%%G"
CALL :ProcessList flac-113-processed.txt
GOTO:EOF

REM =============================================
REM  ListFiles : Create list of files to process
REM            : %1 The FLAC file to add
REM =============================================
:ListFiles
ECHO %1>>"%pathForList%flac-113-processed.txt"
GOTO:EOF

REM ============================================
REM  ProcessList : Encode all files in the list
REM              : %1 The text list of files
REM ============================================
:ProcessList
REM Encode each file
PUSHD %pathForList%
FOR /F "tokens=* delims=" %%H IN (%~s1) DO CALL :Encode %%H
POPD
IF [%retainListOfFailedFiles%] EQU [1] (
    REM ECHO.>>"%pathForList%flac-113-processed.txt"
    REM ECHO List created at %DATE% %TIME%>>"%pathForList%flac-113-processed.txt"
) ELSE (
    DEL "%pathForList%flac-113-processed.txt"
)
GOTO:EOF


REM =====================================
REM  Encode : Encode FLAC file
REM        : %1 The FLAC file to Encode
REM =====================================
:Encode
REM Check the vendor string to see if the file is already the latest version
IF EXIST "%~dp0FLACGETV.EXE" (
    ECHO Checking Vendor: "%~1"
    ECHO ________________________________________________________________________
    "%~dp0FLACGETV.EXE" %1
    ECHO.
)
REM Create destination path from source path
SET dst=%~1
SET dst=%dst::=?%
SET srcRoot=%srcRoot::=?%
SET dstRoot=%dstRoot::=?%
CALL SET dst=%%dst:%srcRoot%=%dstRoot%%%
SET dst=%dst:?=:%
FOR %%I IN ("%dst%") DO SET dstf="%%~dpI"
IF %ERRORLEVEL% EQU %flacVersion% (
    SET /A noSkipped+=1
    ECHO File is already the latest version [%flacVersion%]
) ELSE (
    REM Test the original
    ECHO Testing: "%~1"
    ECHO ________________________________________________________________________
    %pathToFLAC% -t %1
    REM If an error code has been returned increase the error counter
    IF ERRORLEVEL 1 (
        SET /A noErrors+=1
        ECHO  %1 [T]>>"%pathForFails%flac-113-failed.txt"
        ECHO.
        ECHO File failed testing.
    ) ELSE (
        REM Encode the file
        ECHO.
        ECHO Encoding: "%~1"
        ECHO ________________________________________________________________________
        IF NOT EXIST %dstf% MKDIR %dstf%
        %pathToFLAC% %flacOptions% -V -f -o "%dst%" %1
        REM If an error code has been returned increase the error counter
        IF ERRORLEVEL 1 (
            SET /A noErrors+=1
            ECHO  %1 [E]>>"%pathForFails%flac-113-failed.txt"
            ECHO.
            ECHO File failed encoding.
            IF EXIST "%dst%" DEL "%dst%"
        ) ELSE (
            SET /A noEncoded+=1
            CALL :IncreaseDestinationBytes "%dst%"
            CALL :IncreaseSourceBytes %1
            ECHO %1>>"%pathForSuccess%flac-113-successful.txt"
        )
    )
)
ECHO.
ECHO.
REM Increase file counter
SET /A noProcessed+=1
GOTO:EOF

REM ==========================================
REM  ReportFiles : List the files that failed
REM ==========================================
:ReportFiles
ECHO.
ECHO Files that failed:
ECHO.
TYPE "%pathForFails%flac-113-failed.txt"
REM Delete the temporary file if not required, or add footer if keeping
IF [%retainListOfFailedFiles%] EQU [1] (
    REM ECHO.>>"%pathForFails%flac-113-failed.txt"
    REM ECHO List created at %DATE% %TIME%>>"%pathForFails%flac-113-failed.txt"
) ELSE (
    DEL "%pathForFails%flac-113-failed.txt"
)
ECHO.
GOTO:EOF

REM =====================================================
REM  NoParams : neither a file or folder has been passed
REM =====================================================
:NoParams
ECHO To run this script, please pass a valid file or folder as a parameter.
ECHO.
ECHO Press any key to exit
PAUSE >NUL
GOTO:EOF

:IncreaseSourceBytes
SET /A srcSize+=%~z1
GOTO:EOF

:IncreaseDestinationBytes
SET /A dstSize+=%~z1
GOTO:EOF
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-01-25 13:39:23
THANK YOU, OH THANK YOU Synthetic Soul !!! 

I'll report my test results soon.

Cheers,

Jose
Title: FLAC re-encoding
Post by: kmitch on 2008-02-04 02:11:29
I'm in the process of writing a VB Script that performs steps similar to those in flac-113.bat.  It's basically for my own use... but I'm willing to share.

Is there any interest out there for this?

-K
Title: FLAC re-encoding
Post by: probedb on 2008-02-04 10:52:11
I'm in the process of writing a VB Script that performs steps similar to those in flac-113.bat.  It's basically for my own use... but I'm willing to share.

Is there any interest out there for this?

-K


If it can do the same job without falling over on files with certain characters in them I'd be interested.

It's not the script the problem it's just the DOS scripting that makes certain characters in filenames invalid and unable to be processed but your script would sort this?
Title: FLAC re-encoding
Post by: kmitch on 2008-02-04 11:29:15
If it can do the same job without falling over on files with certain characters in them I'd be interested.

It's not the script the problem it's just the DOS scripting that makes certain characters in filenames invalid and unable to be processed but your script would sort this?


Which characters in particular?  I'll test with them.
Title: FLAC re-encoding
Post by: Synthetic Soul on 2008-02-04 11:33:44
They shouldn't pose an issue for you.  Characters like percent, caret, and brackets can cause problems in batch files (or at least mine) if not escaped properly.

I for one would be happy to see a script to supercede flac-113.bat.

I really should use VBScript more for my scripts, I really don't know why I don't.  IIRC the WSH is built-in to all XP machines.
Title: FLAC re-encoding
Post by: probedb on 2008-02-04 11:33:53

If it can do the same job without falling over on files with certain characters in them I'd be interested.

It's not the script the problem it's just the DOS scripting that makes certain characters in filenames invalid and unable to be processed but your script would sort this?


Which characters in particular?  I'll test with them.


I'll try and remember to check this evening  I believe it's things like single quotes.
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-02-04 16:41:24
Thanks in advance kmitch (with credits to synthetic soul also of course).
Title: FLAC re-encoding
Post by: kmitch on 2008-02-04 17:42:16
I'll try to type up some documentation this evening and post the script.  Just wanted to set a few expectation with this post, though...  The script is not really a direct replacement of the batch files.  It won't really handle dropping items on it and have it process them.  It's more of a command line script with parameters that allows processing a directory or a file list.

-K
Title: FLAC re-encoding
Post by: kmitch on 2008-02-05 00:15:46
Here's the document I typed up about the functionality:
---
Re-FLACer v1.0

Purpose:
I had a need.  I wanted something that could help me handle my FLAC
library.  Verify that the files were not corrupt, Re-Encode them if a
new version of FLAC came out that had better compression, decode them
back to a WAV file, or allow me to easily convert to MP3s for portable
devices.

I considered a VB GUI app, possibly a VB console app... but decided that
I wanted the freedom of a VB Script.  The code isn't compiled, and if I
need something for a special situation, this provides an easy way to
modify the code.

There are other applications out there, probably with more features, but
for simplicty and ease of use, I rolled my own.

Basic use:
You set up a config file with the values you want to use, and then run
the program (optioanlly with command line parameters).

Some of the required information is:

  Mode
  The program can be run in one of the following modes at a time:
      Encode - The program looks for .WAV files and will encode them
              using .FLAC

      Decode - The program looks for .FLAC files and will decode them to
              .WAV

      MP3    - The program looks for .FLAC files, intermediately decodes
              them to .WAV, then uses lame to encode the .WAV to .MP3
              and removes the .WAV file

      ReFLAC - The program looks for .FLAC files and re-encodes them to
              .FLAC

      Test  - The program looks for .FLAC and tests the files for
              validity

  Input
  There are three choices (only 2 have been coded thus far)
      Directory - Command Line Parameter DIR.  If used, the program will
                  look in this directory and all subdirectories for
                  files and perform the Mode action on those files

      File List - Command Line Parameter FILELIST.  formatted as 1 file
                  per line with full path and filename, the program will
                  iterate through each file and perform the mode action.

      File      - Command Line Parameter will be FILE.  As this is the
                  least important option for me, it hasn't been coded
                  yet.  It will allow the program t act on an individual
                  file.

A little discussion on the other command line/config file parameters:

CONFIG
The program always expects a configuration file (Re-FLACer.cfg) to be
present in the script directory.  This config file is read first, then
any command line options are processed in the order they appear on the
command line.  You can load another config file from the command line
that can override any values that exist in the original config file, or
appear on the command line earlier than the CONFIG parameter.


LOGFILENAME
The program will log all of it's information to the LOGFILENAME in the script directory

TARGETDIR
If this parameter is left blank, the action will occur the the original
file's directory.  If this value is populated, the resulting directory
(if any) will be determined based on the type of Input:

  Directory - The Original directory will be replaced by TARGETDIR as
              the root, any subdirectories in the Directory will be
              created in the TARGETDIR.

  File List - The root directory of the file in the list will be placed
              in the TARGETDIR.  For example, given the file:
              X:\Music\ZZ Top\Greatest Hits\Legs (Remix Version).flac
              And a TARGETDIR of G:\Target, the file will be placed in:
              G:\Target\Music\ZZ Top\Greatest Hits\Legs (Remix Version).flac

  File      - The file will be placed in the TARGETDIR

FLAC Related
  FLACPROGRAM
  The full path and filename to flac.exe

  METAFLACPROGRAM
  The full path and filename to metaflac.exe

  VERSIONSKIP
  Skip the file for processing if the version of the FLACPROGRAM is the
  same as the version of the FLAC file being processed.

Tag Related
  TAGPROGRAM
  The full path and filename to tag.exe

  REMOVEID3V2
  If this has a value of Y, ID3v2 tags will be removed prior to the
  operations.  This only occurs if the TARGETDIR parameter is left
  blank.

Lame Related
  LAMEPROGRAM
  The full path and filename to lame.exe

  LAMEPARAMETERS
  The lame parameters that should be used when encoding to MP3

The following files all reside in the script directory, and are written
to based on the associated KEEP* parameter

  COMPLETEDLIST (KEEPCOMPLETED=Y or N)
  The list of files that were processed successfully

  ERRORLIST (KEEPERROR=Y or N)
  The list of files that did not complete

  SKIPPEDLIST (KEEPSKIPPED=Y or N)
  The list of files that were skipped because of the VERSIONSKIP
  parameter.


External Programs
This program is just a wrapper around functionality available in other
programs.  It makes use of the following executables:

  FLAC v1.2.1
  Makes use of flac.exe and metaflac.exe, these programs can be obtained from
  http://flac.sourceforge.net/ (http://flac.sourceforge.net/)  on the Download page, click on the link to
  download FLAC for Windows (command-line tools only).

  Tag v2.0.52
  Makes use of Tag to identify and remove ID3v2 tags.  This program can be
  obtained from http://synthetic-soul.co.uk/tag/ (http://synthetic-soul.co.uk/tag/)

  Lame v3.97
  LAME is an MPEG Audio Layer III (MP3) encoder licensed under the LGPL.
  It can be downloaded from http://lame.sourceforge.net (http://lame.sourceforge.net)


I also wanted to thank Synthetic Soul (http://www.synthetic-soul.co.uk/)
for his work on flac-113.bat, and the other related batch files.  They
helped me determine what I wanted the script to do.
---

I don't really have a place to host this code, and it looks like I can't add an attachment to this post.  I can post the VBScript and the config file in code sections, but don't think that's the best option.  Is anyone aware of a place I can post the ZIP file (it's only about 10K).
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-02-05 01:07:18
You can try a hosting service like rapidshare, or I can host it if you mail it to me. Up to you.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-05 01:58:17
The file has been posted on RapidShare
RapidShare Link to Re-FLACer_1_0.zip (http://rapidshare.com/files/89243653/re-FLACer_1_0.zip.html)
Title: FLAC re-encoding
Post by: Synthetic Soul on 2008-02-05 08:04:49
That all sounds great.  I look forward to taking a look.

I don't really have a place to host this code, and it looks like I can't add an attachment to this post.  I can post the VBScript and the config file in code sections, but don't think that's the best option.  Is anyone aware of a place I can post the ZIP file (it's only about 10K).
You can zip the scripts and upload them to the Uploads forum (http://www.hydrogenaudio.org/forums/index.php?act=SF&s=&f=35) here.  There are temporary hosts but they tend to remove the files after a time, or if there is not enough traffic.  The Uploads forum is the perfect place for this.

Edit: Oops, must have missed the last page of posts.
Title: FLAC re-encoding
Post by: Demetris on 2008-02-05 13:25:48
Thanks for this script, kmitch! :-) I run a quick test (a few dozen FLAC files) and it seems to work fine.

A couple of questions:

And a couple of ideas:
Title: FLAC re-encoding
Post by: kmitch on 2008-02-06 00:44:32
A couple of questions:
  • Does it use --best by default for FLAC? Can we change this? In general, can we pass parameters to flac.exe?
  • Does it use --verify?

The FLAC command currently uses -f -8 for encoding, -f -d for decoding, and -t for testing, I'll look into moving these into the config file/command line.
  • I would like to be able to save the log files in dedicated directories for each batch job, named after the date and also the version of flac used. E.g.: 20080205a-flac121

I'll look into adding a Log Directory config/command line parameter that can use variables (Mode, Date, etc.).

Thanks for the suggestions.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-07 01:11:24
A new version of Reflacer has been posted to Google Code.  Here's the link to the project:

http://code.google.com/p/reflacer/ (http://code.google.com/p/reflacer/)

The following changes have been made in this version:
The .txt file with documentation has also been updated.
Title: FLAC re-encoding
Post by: Demetris on 2008-02-07 15:02:10
Thanks again, kmitch! and congrats on the project page!

Another two ideas; they are not suggestions -- just ideas! :-)

And a small problem in the MP3 mode:
Title: FLAC re-encoding
Post by: kmitch on 2008-02-07 17:56:40
  • Create automatically the specified TargetDir if it does not exist -- or maybe add something like this to the comment: "Destination directory must exist"

With version 1.01, the TargetDir will be created if it doesn't exist.

  • When a TargetDir is specified, ability to copy over non-audio files, perhaps with some filter. E.g.: folder.jpg;*.log;*.cue, or: *.*, or *.jpg

I'll have to think about how to implement this one and make it flexible enough.

    And a small problem in the MP3 mode:
      [/li][li]It seems tag cannot write ID3v2 tags, which means that a lot of information may be lost (like Unicode strings or custom fields) -- but maybe there is not much you can do about this; are there command-line taggers for Windows that can write ID3v2.4 or ID3v2.3?[/li]

I don't know of another command line tagger that could be used.  The nice thing about Tag is that it allows copying the tags from FLAC to MP3.  I can parse the tags from FLAC but this would require some additional logic, and probably an additional TagMapping file... if I need to use a different executable.
Title: FLAC re-encoding
Post by: probedb on 2008-02-07 21:00:21
Just used this for the first time and it's worked except there's something wrong with the directory creation logic. I have:

' Top level directory that contains the files to process
Dir=G:\Temp\_music
'
' Top level destination directory
TargetDir=G:\Temp\_music\_encoded

It's created the _encoded directory and the album directory down to

G:\Temp\_music\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded\_encoded

I think that's roughly twice the number of tracks!?
Title: FLAC re-encoding
Post by: kmitch on 2008-02-08 03:18:14
Just used this for the first time and it's worked except there's something wrong with the directory creation logic. I have:

' Top level directory that contains the files to process
Dir=G:\Temp\_music
'
' Top level destination directory
TargetDir=G:\Temp\_music\_encoded

It's created the _encoded directory and the album directory down to

G:\Temp\_music\_encoded\_encoded\_encoded\_encoded\ ...

I think that's roughly twice the number of tracks!?


I had only tested with the TARGETDIR in a separate parent directory, not nested within the DIR... I'll try to recreate the issue, and take a look at the code...

Edit:  That's not going to work by specifying a DIR, because the program is recursively going through the directories and looking for files, you'd have to run using a filelist.  If it finds files, it processes them... This really should have kicked an error out to you saying that the the TARGETDIR cannot be a child of DIR.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-08 12:27:52
  • Create automatically the specified TargetDir if it does not exist -- or maybe add something like this to the comment: "Destination directory must exist"

With version 1.01, the TargetDir will be created if it doesn't exist.


I was mistaken.  the TargetDir would not be created if it did not exist.  I have corrected this in the code, and it will be in the next version.
Title: FLAC re-encoding
Post by: probedb on 2008-02-08 13:41:42
Edit:  That's not going to work by specifying a DIR, because the program is recursively going through the directories and looking for files, you'd have to run using a filelist.  If it finds files, it processes them... This really should have kicked an error out to you saying that the the TARGETDIR cannot be a child of DIR.


Cheers that makes sense! I'll use a dir outside the other one

Out of interest what happens if they're the same directory? Will it try and copy files onto themselves or behave as the .bat file did and rename then reencode if required? I did like the ability to be able to give it a directory and just end up with a set of updated FLAC files.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-09 02:07:02
Out of interest what happens if they're the same directory? Will it try and copy files onto themselves or behave as the .bat file did and rename then reencode if required? I did like the ability to be able to give it a directory and just end up with a set of updated FLAC files.


It will issue the command
Code: [Select]
flac.exe --force --best --verify filename.flac

flac will create a temporary file, and re-encode the file to the original filename.  The script can (based on the VersionSkip config file/command line parameter) also skip .flac files that are already encoded with the flac.exe version.

If a TargetDir isn't specified, you can also Decode, Encode, or MP3 to the same directory.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-09 14:10:36
I've just released Reflacer v1.02, you can find it at http://code.google.com/p/reflacer/ (http://code.google.com/p/reflacer/)

Here are the changes that are included in this version:

* Fixed bug with the Logo being written to the screen in an error state
* If using DIR and TARGETDIR, a list of files that are in TARGETDIR but not in DIR will be logged
* Added COPYFILEMASKS command line/config file parameter (Demetris)
* Will now create TARGETDIR if it does not exist (Demetris)
* Will now handle TARGETDIR being a child of DIR (will not recurse TARGETDIR) (probedb)
* When specify variables for LOGDIR, may use ^ instead of % (easier in batch files)
* Fixed bug with displaying TARGETDIR parameter
* Fixed bug that occurred when decoding a flac file failed in MP3 mode

I've also added ReflacerTest, that includes some sample WAV files (one that is corrupt, one with an ID3v2 tag) and a batch file to test how Reflacer works.
Title: FLAC re-encoding
Post by: Demetris on 2008-02-15 20:05:20
Thanks for the enhancements, kmitch!
Title: FLAC re-encoding
Post by: jamesbaud on 2008-02-21 16:34:33
I just started using this program, and it's great. I have a large library of FLAC files and a dual core machine. It's taking a long time (ongoing as I write) but 1 core is idle.

I have one suggestion, from another thread, "FLAC for core duo"

http://www.hydrogenaudio.org/forums/index....st&p=548292 (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=60656&view=findpost&p=548292)

Can you add the ability to call multiple instances of FLAC for multiple core machines, the way foobar does?
Title: FLAC re-encoding
Post by: kmitch on 2008-02-22 00:41:06
I just started using this program, and it's great. I have a large library of FLAC files and a dual core machine. It's taking a long time (ongoing as I write) but 1 core is idle.

I have one suggestion, from another thread, "FLAC for core duo"

http://www.hydrogenaudio.org/forums/index....st&p=548292 (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=60656&view=findpost&p=548292)

Can you add the ability to call multiple instances of FLAC for multiple core machines, the way foobar does?


As far as I know, it can't be easily done in VBScript.  VBScript doesn't allow for threading, I'd also have to rewrite some of the logic used for the temporary files that are created during the process, and it would complicate logging a bit.

I do have an alternative for you, though.  I would create a second directory to place the script in, and copy the neccessary files to that directory (you can leave the executables where they are).  In DOS, go to the directory that you want to work against, and type
Code: [Select]
dir /b /s *.flac > files.txt
you can then split this file into 2 lists of files.  Then you can run Reflacer twice at the same time with different file lists.

It's not the most elegant solution, but it's the best I can offer without moving to a compiled executable using VB .Net or doing something similar to what is outlined below.

Once I finish with the testing in this version and get it out the door, I'll look at making the temporary files that are being used by the process a little more run-centric so you can use the same .vbs to run multiple times. 

It looks like I can determine the number of processors at runtime:
Code: [Select]
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
  Wscript.Echo "Computer Name: " & objOS.CSName

  Wscript.Echo "Operating System"
  Wscript.Echo "  Caption: " & objOS.Caption 'Name
  Wscript.Echo "  Version: " & objOS.Version 'Version & build
  Wscript.Echo "  BuildNumber: " & objOS.BuildNumber 'Build
  Wscript.Echo "  BuildType: " & objOS.BuildType
  Wscript.Echo "  OSProductSuite: " & objOS.OSProductsuite 'OS Product suite
  Wscript.Echo "  OSType: " & objOS.OSType
  Wscript.Echo "  OtherTypeDescription: (2003 Server R2 release only)" & objOS.OtherTypeDescription
  WScript.Echo "  ServicePackMajorVersion: " & objOS.ServicePackMajorVersion & "." & _
   objOS.ServicePackMinorVersion

Next

Wscript.Echo "Processors"

Set colCompSys = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objCS in colCompSys
  WScript.Echo "  NumberOfProcessors: " & objCS.NumberOfProcessors
Next

Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objProcessor in colProcessors
  WScript.Echo "  Manufacturer: " & objProcessor.Manufacturer
  WScript.Echo "  Name: " & objProcessor.Name
  WScript.Echo "  Description: " & objProcessor.Description
  WScript.Echo "  ProcessorID: " & objProcessor.ProcessorID
  WScript.Echo "  Architecture: " & objProcessor.Architecture
  WScript.Echo "  AddressWidth: " & objProcessor.AddressWidth
  WScript.Echo "  DataWidth: " & objProcessor.DataWidth
  WScript.Echo "  Family: " & objProcessor.Family
  WScript.Echo "  MaximumClockSpeed: " & objProcessor.MaxClockSpeed
Next


I may be able to create a way to divy up the files between 2 runs and kick them both off from a single command.  You'd still have 2 log files, etc... but would make the most use of your dual core/quad core processor.

BTW... I'm doing my final testing on a new version that adds quite a bit of functionality to re-encoding to MP3... more info to come on that.

-K
Title: FLAC re-encoding
Post by: ludwig on 2008-02-22 01:14:45
sorry kmitch, but there's a problem with 1.2.1 on 24 bits files. Could it be possible to encore everything but 24 bits with 1.2.1, and stay with 1.2.0 for 24 bits files ?
Regards
Title: FLAC re-encoding
Post by: jamesbaud on 2008-02-22 17:14:14
I do have an alternative for you, though.

Thanks for the tip.
Quote
Once I finish with the testing in this version and get it out the door, I'll look at making the temporary files that are being used by the process a little more run-centric so you can use the same .vbs to run multiple times.

I look forward to the new version. In addition to being able to set target directories and destination directories, would it be possible to set a temp directory for the temp files?
Quote
BTW... I'm doing my final testing on a new version that adds quite a bit of functionality to re-encoding to MP3... more info to come on that.

This sounds exciting. Regarding MP3 encoding, as someone pointed out earlier in the thread, Tag does not support ID3v2 tags, so those don't get copied over from the FLAC tags. After a batch encode, I have to open up MP3Tag to correct the tags. I hope your new version can help to address this.

Thx again for a great tool!
Title: FLAC re-encoding
Post by: jamesbaud on 2008-02-22 17:49:08
I don't know of another command line tagger that could be used.  The nice thing about Tag is that it allows copying the tags from FLAC to MP3.  I can parse the tags from FLAC but this would require some additional logic, and probably an additional TagMapping file... if I need to use a different executable.


Check out this thread, "Windows mp3/id3 command line tagger?"
Maybe it could be of some use to you.

http://www.hydrogenaudio.org/forums/index....st&p=326750 (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=37055&view=findpost&p=326750)
Title: FLAC re-encoding
Post by: kmitch on 2008-02-22 22:54:14
[In addition to being able to set target directories and destination directories, would it be possible to set a temp directory for the temp files?


In the next version, a Temp directory will be created under the Script Directory automatically.  All files that are used by the processes will be in that directory.

Quote
This sounds exciting. Regarding MP3 encoding, as someone pointed out earlier in the thread, Tag does not support ID3v2 tags, so those don't get copied over from the FLAC tags. After a batch encode, I have to open up MP3Tag to correct the tags. I hope your new version can help to address this.


I also looked at using ID3 Mass Tagger, but it didn't provide what I wanted.  I didn't want to have issues with characters that don't work well in a command line.  ID3 Mass Tagger didn't include a way to pull tags in from a file.

With the new version, I'll still be using Tag to remove ID3v2 tags from FLAC files, and you'll gave the choice to use it to copy tags from FLAC to MP3, or to use metamp3 (http://www.hydrogenaudio.org/forums/index....showtopic=49751 (http://www.hydrogenaudio.org/forums/index.php?showtopic=49751)).  When using metamp3, the script will export each tag to a separate file, and then all at once use those files to tag the MP3.  I've also built a mapping file (Reflacer.tag) that you can use to map the FLAC tags to the MP3 frames.

The next version also includes the ability to add images to the MP3 either from a file in the original directory, or you can pull it from the FLAC file (you provide a list of sources, and it checks until it finds a match).  Only one image will be used to tag the MP3.

I've also written a little utility to resize the image (if you want to) prior to tagging the MP3.  Some hardware only supports images in tags up to a certain resolution, this should take care of that.

The only thing I'm working on now is to create additional ReflacerTest scenarios to cover the new functionality... this helps me regression test the script to make sure I haven't broken anything along the way.

-K
Title: FLAC re-encoding
Post by: kmitch on 2008-02-23 02:17:15
A new version of Reflacer has been released.  I've also created a new topic for Reflacer discussion here:

http://www.hydrogenaudio.org/forums/index....showtopic=61511 (http://www.hydrogenaudio.org/forums/index.php?showtopic=61511)

Here are the changes for this version:

02/22/2008 v1.03-K
Title: FLAC re-encoding
Post by: jamesbaud on 2008-02-23 03:41:03
Wow! you're fast. I'll try it out. Thx.
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-02-23 18:02:28
sorry kmitch, but there's a problem with 1.2.1 on 24 bits files.

Hi ludwig, can you be more specific please ? I'd like to know more about that. Thank you.
Title: FLAC re-encoding
Post by: kmitch on 2008-02-23 22:18:33
sorry kmitch, but there's a problem with 1.2.1 on 24 bits files. Could it be possible to encore everything but 24 bits with 1.2.1, and stay with 1.2.0 for 24 bits files ?
Regards


Is the problem only with one of the functions?  Just Decoding, Encoding, Testing?  Is Metaflac.exe affected, or just flac.exe?

Depending on what it impacts, I may be able to add some logic around an alternate FLAC program.  I'd aso need a sample file to play with.

I would really like to take the discussion here:
http://www.hydrogenaudio.org/forums/index....showtopic=61511 (http://www.hydrogenaudio.org/forums/index.php?showtopic=61511)
Title: FLAC re-encoding
Post by: ludwig on 2008-02-25 22:01:33

sorry kmitch, but there's a problem with 1.2.1 on 24 bits files. Could it be possible to encore everything but 24 bits with 1.2.1, and stay with 1.2.0 for 24 bits files ?
Regards


Is the problem only with one of the functions?  Just Decoding, Encoding, Testing?  Is Metaflac.exe affected, or just flac.exe?

Depending on what it impacts, I may be able to add some logic around an alternate FLAC program.  I'd aso need a sample file to play with.

I would really like to take the discussion here:
http://www.hydrogenaudio.org/forums/index....showtopic=61511 (http://www.hydrogenaudio.org/forums/index.php?showtopic=61511)

Sorry guys for the delay, I'm just back home. Encoding problem, then decoding problem too (when I've encoded a flac with 1.2.1 or reflac and old flac).
So @this time (I didn't have time to try your reflacer yet, but with synthetic sounds' script; I have to use 2 scripts, one using 1.2.1 for everything except the 24bits, and another script using 1.2.0 for 24 bits files.) I told that in the flac-113 forum. Regards
Title: FLAC re-encoding
Post by: Jose Hidalgo on 2008-02-26 13:01:29
Haven't you read kmitch's post ? 

I would really like to take the discussion here:
http://www.hydrogenaudio.org/forums/index....showtopic=61511 (http://www.hydrogenaudio.org/forums/index.php?showtopic=61511)
Title: FLAC re-encoding
Post by: JJZolx on 2008-03-25 00:44:07
but with id3v2 that could be a lot and you can't really know how long except with multiple reads, so I punt in this case.

there are three possible fixes, but all seem like more than acceptable than to just reject invalid files:

1) add another option like --force-flac-format
2) split the filetype detection code to work for seekable input, then the bug will only be with pipes
3) make the detection code more complicated to buffer the whole id3 tag

Josh,

Have you given any recent thought to the --force-flac-option?  I think this would be a welcome option for anyone trancoding what they know for certain are flac files.

Thanks.
Title: FLAC re-encoding
Post by: Quidsane on 2010-09-28 04:13:15
Having the worst time trying to get Neil's batch file to work on Windows 7 x64.
I finally got flac.exe and flac frontend to work by NOT using the versions with installers.
Successfully registered mscomctl.ocx in C:\Windows\SysWOW64, and FLAC is running just fine.
But the batch file doesn't work. File has been edited to reflect the new path to flac.exe so it's not that.
When I drag a folder full of FLACs onto the batch file, the only thing that happens is:
a command prompt box flashes on the screen for a split second.
Having used the batch file for years now and finding it utterly indispensible, I'm about ready to give up
Win 7 just to be able to use it. Anyone able to run this on Win 7? Any suggestions?
Title: FLAC re-encoding
Post by: Quidsane on 2010-09-30 13:01:32
Hmmm, okay.
So no one else is having problems running Neil's batch file on Windows 7?

Search is my friend!
Trying ReFLAC now...
Title: FLAC re-encoding
Post by: Quidsane on 2010-09-30 14:00:44
OK, ReFLAC is not a viable option for me.
I'm not happy with having to edit a .cfg file to change directories every time I
want to use it. Sorry. It has no drag and drop functionality (like Neil's batch file does)
that I can ascertain. Or am I missing something?
Anyhow, I just discovered that dbPoweramp will do the job just fine.
I do miss Neil's file, though...