Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 10th August 2013, 09:05   #1  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Properly transcode FLAC to WAVE then encode with LAME

Hi,

Last year I asked many questions about how to encode and transcode. But, I don't manage to do what I plan properly.

First of all, let's say I've ripped a CD of mine in FLAC via EAC. The extracted FLAC files contain tags such as the name of the artist, the year and so on. I would like to transcode a resulting FLAC to WAV then to encode the later with LAME. If I use the following comand line in a BAT file :

Code:
flac -d %1
lame -b 320 -h --add-id3v2 %1 "%~dpn1.mp3"
pause
It doesn't work because the %1 doesn't refer to the transcoded WAVE file. Consequently Lame doesn't find this WAVE.

I also tried the simple comand line applied to the WAVE :

Code:
lame -b 320 -h --add-id3v2 %1 "%~dpn1.mp3"
pause
It works but the tags (artist, year..) are lost ! To sum up, how could I properly transcode the FLAC to WAVE without loosing the tags then encode it to 320 in one single BAT file ? In fact I don't particulary want to transcode from FLAC to WAVE but Lame doesn't seem to work when a FLAC is an input.

Last edited by sirt; 10th August 2013 at 09:27.
sirt is offline   Reply With Quote
Old 10th August 2013, 10:30   #2  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,395
you could use ffmpeg to keep metadata as well, challenge is to get some nice mp3 command line.

https://trac.ffmpeg.org/wiki/Encoding%20VBR%20(Variable%20Bit%20Rate)%20mp3%20audio

like;

ffmpeg -i some.flac -q:a 2 out.mp3

If the tags are incorectly copied then you could use some sort of command line tagger to copy tags from flac to mp3.

for win cli and parameter expansions, perhaps read
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true
__________________
certain other member

Last edited by smok3; 10th August 2013 at 10:33.
smok3 is offline   Reply With Quote
Old 10th August 2013, 10:38   #3  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks smok3. But I don't want to use ffmeg or anything like that. I want to use a BAT file. At least, I would like to transcode and encode like I tried above.
sirt is offline   Reply With Quote
Old 10th August 2013, 10:46   #4  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,395
you can
a. change my ffmpeg example to your bat by reading the provided parameter expansions link
b. make a bat file that uses: flac -d, lame to encode, 3rd party tagger to copy tags from flac to mp3 (again this will be possible once you understand parameter expansions)

There are also lame compiles that are capable of flac input
http://www.rarewares.org/mp3-lame-bundle.php

(I'am not on windows, so I can't really test all that)
__________________
certain other member
smok3 is offline   Reply With Quote
Old 10th August 2013, 11:14   #5  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Unfortunately I don't really understand how this bat language works. As I said below, I don't even manage to transcode from FLAC to WAV and then encode in the same BAT file. We could first start to set that.

Secondly, I'm not sure to understand either how I could use a "3rd party tagger to copy tags from flac to mp3" in a BAT file. And about the lame compiles capable of dealing with FLAC input, is this RareWares version similar to the official one ?
sirt is offline   Reply With Quote
Old 10th August 2013, 12:25   #6  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
>It doesn't work because the %1 doesn't refer to the transcoded WAVE file.
Instead of
lame ... %1 "%~dpn1.mp3"
use
lame ... "%~dpn1.wav" "%~dpn1.mp3"

See Path Manipulation in a Batch File

BTW, using "%~dpnx1" in place of %1 enforces quote wrapping instead of trusting the OS to do it.
raffriff42 is offline   Reply With Quote
Old 10th August 2013, 13:05   #7  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks raffriff42 for your answer. Something like that :

Code:
if [%1]==[] goto :eof
:loop
flac -d %1
lame_normal -b 320 -q0 --add-id3v2 "%~dpn1.wav" "%~dpn1.mp3"
del "%~dpn1.wav"
shift
if not [%1]==[] goto loop
pause
Transcodes all the FLAC from the directory to WAVES and encode those WAVES to MP3. The WAVES are also deleted after being compressed. Then, this is equivalent to :

Code:
PUSHD %~dp0
if [%1]==[] goto :eof
:loop
lame -b 320 -q0 --add-id3v2 %1 "%~dpn1.mp3"
shift
if not [%1]==[] goto loop
pause
By using the special build from smok3 link allowing FLAC processing.

Howhever, in both cases I loose all the original tags from FLAC files and it forces me to rewrite them manually. What would be a simple way to preserve them ? I guess it would be based on smok3 idea but I don't understand.

Moreover how could I write the MP3 into a directory called "result" for example ? What would be the command to use into the BAT ?
sirt is offline   Reply With Quote
Old 10th August 2013, 13:09   #8  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,395
an example going from flac to lossy flac using "tag" to copy/paste tags;

Code:
@echo off
:repeat
if %1.==. goto end
if exist %1 flac -d %1 --stdout --silent|lossywav - --stdout -P --stdinname %1|flac - -b 512 -o "%~dpn1.lossy.flac" --silent && tag --fromfile %1 "%~dpn1.lossy.flac"
shift
goto repeat
:end
tag can be found here;
http://www.rarewares.org/others.php

(again this is just from my memory, not even sure if that compile of tag is still working today)
__________________
certain other member
smok3 is offline   Reply With Quote
Old 10th August 2013, 13:37   #9  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
smok3, thanks for your help. Something is still unclear to me : let's say I download that "TAG command line tagger" from your related link. Then, how am I supposed to use your last code above ?

I don't see how it could be included there :

Quote:
if [%1]==[] goto :eof
:loop
flac -d %1
lame_normal -b 320 -q0 --add-id3v2 "%~dpn1.wav" "%~dpn1.mp3"
del "%~dpn1.wav"
shift
if not [%1]==[] goto loop
pause
To be honest I'm not even sure to understand your code : is this a way to recover the tags from flac files, keep them in memory and rewrite them into the final mp3 files generated by lame ? It is in fact much more similar to an example so I can't use it directly in my context. In particular, I don't want to recompress any flac to "lossy flac".
sirt is offline   Reply With Quote
Old 10th August 2013, 13:41   #10  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,395
maybe (not tested)

Code:
if [%1]==[] goto :eof
:loop
flac -d %1
lame_normal -b 320 -q0 --add-id3v2 "%~dpn1.wav" "%~dpn1.mp3" && tag --fromfile %1 "%~dpn1.mp3"
del "%~dpn1.wav"
shift
if not [%1]==[] goto loop
pause
__________________
certain other member

Last edited by smok3; 10th August 2013 at 13:44.
smok3 is offline   Reply With Quote
Old 10th August 2013, 13:56   #11  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Well, thanks at least this code works but there is something weird. Even if the tags seem to have been written they don't exist. I open a resulting MP3 into Mp3tag in order to add a frame as tag to but none of the tags previously written appear there. I don't see a reason why excepted that the "tag.exe" doesn't write them properly.

After different tries, it seems there is a conflict with a lame parameter I use --add-id3v2 because tag reports "ID3v1tag written". Disabling --add-id3v2 enables tag to write some tags but the type of music isn't kept for example. Well do you think it is possible to writ v2 tags with tag.exe instead of v1 tags ?

Last edited by sirt; 10th August 2013 at 13:58.
sirt is offline   Reply With Quote
Old 10th August 2013, 14:02   #12  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,395
According to tag docs it does not support writing id3v2 tags (only reading and removing).
__________________
certain other member
smok3 is offline   Reply With Quote
Old 10th August 2013, 14:06   #13  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Then what is the difference between v1 and v2 ? Personally, I don't mind but does that, practically, change something ?

And to conclude, if you want to make me really happy () let's say the FLAC files are on a folder named MAIN, I would like the MP3 files to be written into a folder called RESULT inside MAIN.
sirt is offline   Reply With Quote
Old 10th August 2013, 15:02   #14  |  Link
JReiginsei
Registered User
 
Join Date: Apr 2002
Posts: 75
Foobar2000

I use Foobar2000 because it will keep the tags when transcoding FLAC. But it doesn't seem to transfer the cover art.

So, I use mp3tag to add the cover art to the transcoded songs.
__________________
Intel Core i5-4250U, 8 GB Ram, Intel HD 5000
JReiginsei is offline   Reply With Quote
Old 10th August 2013, 15:49   #15  |  Link
detmek
Registered User
 
Join Date: Aug 2009
Posts: 475
It would be much easier to use some of lame GUIs like TAudio Converter, foobar2000, LamedropXPd3, dbPowerAmp ect. LamedropXPd3 works with drag-and-drop, dbPowerAmp offers shell integration (even in free version), foobar can apply DSP effects during conversion. So, if your goal is a specific way of conversion (using cmd) I can not help but if you just want mp3 files one of the GUIs is the way to go.
So, the question is: Do you really need CMD way of conversion?
BTW, WAV files have no standard way of taging so most applications do not support tagging WAV files. Converting FLAC to WAV and than to mp3 is useless.
detmek is offline   Reply With Quote
Old 10th August 2013, 16:58   #16  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks detmek, indeed I want to learn how to do all this manually. I could simply do it with EAC but I intentionally extracted tracks as FLAC files via EAC in order to encode them like I intend above. Well, what I did before is great : my code works fine and I just need to add a few things on Mp3tag to be satisfied. My only doubt is that conflict between v1 and v2 way of tagging : do you know something about this ? In particular, what would change using v1 instead of v2 ?

And moreover why do you think converting FLAC to WAVE and finally to MP3 is "useless" ? By using the code above, FLAC are transcoded to WAVES then encoded to LAME and the use of tag.exe allows to extract (all) tags from original FLACS and write them into the resulting MP3.
sirt is offline   Reply With Quote
Old 10th August 2013, 19:02   #17  |  Link
detmek
Registered User
 
Join Date: Aug 2009
Posts: 475
Because lame.exe with FLAC input support already decode FLAC to PCM internaly (that is also what you get when you decode FLAC to WAV). So, it is useless, takes more time and disk space and complicates your script. And you already extract info from FLAC files, not WAV ones.

ID3 V1 tags have more restrictions than V2, like shorter file names, custom fields can not be used with V1, tag size is limited to 128 bytes, limited genre support, no album art, ect. You have article on Wikipedia about ID3 tags.

You could use MediaInfo to extract info from original file and than write that to new mp3 file or pass it to lame encoder. In that case you can use ID3 V2 tags. It will require more complicated script, though.

Last edited by detmek; 10th August 2013 at 19:31.
detmek is offline   Reply With Quote
Old 11th August 2013, 09:43   #18  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Ok thanks detmek.

After a few tests I found something like this :

Code:
if [%1]==[] goto :eof

mkdir result

:loop
flac -d %1
lame_normal -b 320 -q0 --add-id3v2 "%~dpn1.wav" "%~dp0result\~n1.mp3"
del "%~dpn1.wav"
if not [%1]==[] goto loop
pause
I would have excepted this code to create a sub folder "result" under my main folder where all the compressed MP3 files would have been compressed. But it doesn't work well : indeed, "result" is created by the mkdir line but if I drag several FLAC files to the BAT file, it looks like an infinit loop occurs : the first track is processed and it never stops.
sirt is offline   Reply With Quote
Old 11th August 2013, 10:07   #19  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
> it looks like an infinit loop occurs
You left out the "shift" line; see post #10
raffriff42 is offline   Reply With Quote
Old 11th August 2013, 11:20   #20  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Okay. Finally this code is working :

Quote:
if [%1]==[] goto :eof

mkdir result

:loop
flac -d %1
lame_normal -b 320 -q0 --add-id3v2 "%~dpn1.wav" "%~dp1result\%~n1.mp3"
del "%~dpn1.wav"
shift
if not [%1]==[] goto loop
pause
sirt is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.