Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: FLAC re-encoding (Read 163705 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

FLAC re-encoding

Reply #25
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...
I'm on a horse.

FLAC re-encoding

Reply #26
OK, the batch file 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.
I'm on a horse.

FLAC re-encoding

Reply #27
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.

FLAC re-encoding

Reply #28
Yes, it does work recursively.
I'm on a horse.

FLAC re-encoding

Reply #29
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
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?

FLAC re-encoding

Reply #30
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

FLAC re-encoding

Reply #31
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.  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).
I'm on a horse.

FLAC re-encoding

Reply #32
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.  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.

FLAC re-encoding

Reply #33
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.
I'm on a horse.

FLAC re-encoding

Reply #34
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&#

Don't be modest, take a bow! 

FLAC re-encoding

Reply #35
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?

FLAC re-encoding

Reply #36
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

FLAC re-encoding

Reply #37
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.

FLAC re-encoding

Reply #38
@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

FLAC re-encoding

Reply #39
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.  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.
I'm on a horse.

FLAC re-encoding

Reply #40
@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?
I'm on a horse.

FLAC re-encoding

Reply #41
yes, it's not supposed to return 0 in this case, I'm hoping with the file I can debug what's wrong.

FLAC re-encoding

Reply #42
@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.

FLAC re-encoding

Reply #43
got the file... the problem is the id3v2 tag on the front of it.

Josh

FLAC re-encoding

Reply #44
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

FLAC re-encoding

Reply #45
I have updated my batch file 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!
I'm on a horse.

FLAC re-encoding

Reply #46
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!

FLAC re-encoding

Reply #47
I guess that could be achieved using this tool.

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...
I'm on a horse.

FLAC re-encoding

Reply #48
OK, version 2.2.0.

If FlacGetV.exe (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]
I'm on a horse.