LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-28-2011, 09:26 PM   #1
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
Using flac with standard input


I can’t convert audio files using flac with standard input. I tried the commands such as:

Code:
mpg321 -b 10000 -s -r 44100 -w - file.mp3 |  flac - -o file.flac
or:

Code:
ogg123 -d wav -f - file.ogg | flac - -o file.flac
In all cases the conversion breaks and the program displays the message such as:

Code:
Playing MPEG stream from file.mp3 ...
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo
-: 2% complete, ratio=0.509
[3:53] Decoding of file.mp3 finished.
-: WARNING: unexpected EOF; expected 536870900 samples, got 10289152 samples
-: ERROR during read of data pad byte
or:

Code:
Playing: file.ogg
Ogg Vorbis stream: 2 channel, 44100 Hz
                                                                                
Done.
-: WARNING: unexpected EOF; expected 536870900 samples, got 10289152 samples
-: ERROR during read of data pad byte
All such conversions doesn’t produce any *.flac file. It seems flac doesn’t accept minus sign for the standard input although flac manual allows to use it.

So my question is how I can use the standard input in order to decode audio data with flac?
 
Old 06-29-2011, 12:46 AM   #2
Sjonnie48
Member
 
Registered: Jun 2005
Location: Earth
Distribution: Ubuntu10.04
Posts: 308

Rep: Reputation: 43
It makes no sense to convert an mp3 file to flac.
If you think flac sounds better than mp3: no, because with the mp3 encoding part of the musical information is cut in favour of a high compression rate, an irreversible process. The resulting flac audio will sound as limited as the mp3 version did, but it will take more disk space.
But if you insist try:
Code:
ogg123 -d wav -f - file.ogg | flac -0 file.flac
I removed the unneccesary dash after the flac command and replaced the character 'o' with a true zero.

Last edited by Sjonnie48; 06-29-2011 at 01:10 AM.
 
Old 06-29-2011, 09:59 AM   #3
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
Sjonnie48,

you didn’t even try that command, right?

The switch -o is for output file; the switch -0 is for fastest compression. They are for different purposes.

The command you suggested:

Code:
ogg123 -d wav -f – file.ogg | flac -0 file.flac
displays the message:

Code:
ERROR: can't open input file file.flac: No such file or directory

Audio Device:   WAV file output

Playing: file.ogg
Ogg Vorbis stream: 2 channel, 44100 Hz
Time: 00:00.26 [06:13.14] of 06:13.39  (155.2 kbps)  Output Buffer  33.3%
and stays doing nothing and waiting for your Ctrl-C.

The similar command:

Code:
mpg321 -b 10000 -s -r 44100 -w – file.mp3 |  flac -0 file.flac
aborts immediately displaying the message:

Code:
ERROR: can't open input file file.flac: No such file or directory
You removed - and -o switches. In result flac interprets non-existing file.flac as source file but it can’t find it. So your tip is completely useless, Sjonnie48.

I’m not here to argue whether these or the other conversions have or haven’t point. I’m preparing audio converter and I’d like to allow in it different conversions. These two from MP3 and OGG to FLAC are two from thirty one conversions I try to implement. Now all conversions work except for three conversions from M4A, MP3, and OGG to FLAC.

What’s interesting the conversion from FLAC to FLAC works well:

Code:
flac -d -c file.flac | flac - -o file.flac.flac
The conversions from APE and MPC to FLAC work well too while the mentioned above conversions from M4A, MP3, and OGG to FLAC fail. It seems flac, mac, and mpcdec programs send valid data to standard output, while faad, mpg321, and ogg123 don’t send the information about the size of the data and flac fails to convert it.

To convert M4A files to FLAC ones I use the command:

Code:
faad -o - file.m4a | flac - -o file.flac
As I mentioned above that command fails displaying the message:

Code:
0% decoding file.m4a.
flac 1.2.1, Copyright (C) 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.

-: ERROR: 'data' subchunk has size of 0
I’m aware I can convert these files to WAV ones and then convert WAV ones to FLAC ones but I’d like to avoid that. So my question is still the same: how I can convert audio files from M4A, MP3, and OGG formats to FLAC one using standard output and standard input (or alternatively fifo).
 
Old 06-29-2011, 10:18 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
The decoding part works for me using 'mpg123 -s file.mp3' in place of your 'mpg321' bit. However, you will need to give the '--endian' '--sign' '--channels' '--bps' and '--sample-rate' options to flac, as it will be trying to encode from a raw format.

Hope this helps,
 
1 members found this post helpful.
Old 06-29-2011, 10:53 AM   #5
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
Snark1994,

thank you for the tip. In the meantime I found the simpler solution. Now I can convert M4A, MP3, and OGG files to FLAC ones using ffmpeg and sox:

Code:
ffmpeg -y -i file.m4a -ac 2 -ar 48000 -acodec flac file.flac
Code:
sox file.mp3 -t wav - | flac - -o file.flac
Code:
sox file.ogg -t wav - | flac - -o file.flac
Thank you guys for your assistance. The problem is solved.
 
Old 06-29-2011, 12:04 PM   #6
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
I simplified ffmpeg command removing unnecessary switches:

Code:
ffmpeg -y -i file.m4a -acodec flac file.flac
 
Old 06-29-2011, 01:14 PM   #7
Sjonnie48
Member
 
Registered: Jun 2005
Location: Earth
Distribution: Ubuntu10.04
Posts: 308

Rep: Reputation: 43
As I mentioned before it makes no sense to transcode mp3 audio to flac. In fact it is a crime for audiophiles.
 
Old 06-29-2011, 02:03 PM   #8
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
As I mentioned before I’m not here to argue whether these or the other conversions have or haven’t point. I prepared the tool for the users. I leave the decision which conversions they’ll use to them.
 
Old 06-30-2011, 04:27 AM   #9
cascade9
Senior Member
 
Registered: Mar 2011
Location: Brisneyland
Distribution: Debian, aptosid
Posts: 3,753

Rep: Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935
Quote:
Originally Posted by Sjonnie48 View Post
It makes no sense to convert an mp3 file to flac.
If you think flac sounds better than mp3: no, because with the mp3 encoding part of the musical information is cut in favour of a high compression rate, an irreversible process. The resulting flac audio will sound as limited as the mp3 version did, but it will take more disk space.
Exactly.

@ w1k0- Why do you want to convert lossy to lossless?
 
Old 06-30-2011, 09:27 AM   #10
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
I don’t want to convert MP3, or OGG, or the other lossy format files to lossless FLAC ones except for the testing purposes. I mentioned for the two times I wrote a script converting from different formats to FLAC, MP3, OGG, and WAV ones. It performs thirty one conversions in total. I don’t deliberate which conversions have point and which haven’t it. I prepared the tool. I left the decision how to use it to the users.

The hammer is the tool too. Most people don’t use the hammer to hit their heads. Some people do that. The producer of the hammers is aware some people will use them in an inappropriate way. He produces the hammers despite of that.

In an old French comic strip its hero named Pif tries autosuggestion. He repeats for the many times: “I have the head of wood. I have the head of wood”. Then he hits his head with a hammer. As a result a big bump appears. Pif says: “Here’s the wooden bump”.

FLAC file get from MP3 or OGG one is a wooden bump.
 
Old 06-30-2011, 07:33 PM   #11
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
Maybe I should mention that sox reads MP3 files when compiled with lame and mad libraries support. Usually it requires the recompilation of sox with the following patch:

Code:
--- CMakeLists.txt      2009-02-12 21:33:57.000000000 +0100
+++ CMakeLists.txt      2011-05-21 17:00:47.000000000 +0200
@@ -65,6 +65,7 @@
 optional(NEED_LIBM math.h m pow "")
 if(NEED_LIBM)
   set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -lm)
+  set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} mpglib)
 endif(NEED_LIBM)
 optional(EXTERNAL_GSM gsm/gsm.h gsm gsm_create "")
 optional(EXTERNAL_LPC10 lpc10/lpc10.h lpc10 lpc10_create "")
Linux Mint users should install libsox-fmt-mp3 library instead of compiling patched sox.

Last edited by w1k0; 07-01-2011 at 02:28 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard input error business_kid Slackware 3 09-20-2010 03:16 AM
DDD and standard input Bassy Programming 0 09-02-2008 06:28 AM
reading from standard input in java spank Programming 3 10-17-2006 06:58 PM
parsing standard input with bash arosales Programming 3 07-16-2005 10:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration