You are not logged in.
hard disk is getting crowded, and my FLAC encoded music needs to be transcoded to something lossy that doesn't take so much space. automatically, of course.
so i wrote a script - much deliberation went into it. transcoding is a tricky business.
flac2oggall
converts all .flac to .ogg (vorbis) with either ffmpeg or avconv.
Descends into sub-directories.
Extracts embedded coverart once for each directory to folder.jpg
Optional argument "rmflac" causes the script to remove each .flac after converting.
You can run the script a second time only to remove .flac files.
The .flac will only be removed if the .ogg file is larger than 0.OGG (vorbis) is a free lossy codec with much higher quality than mp3 or even aac.
The encoding quality chosen is "9" (out of 10, so very high) and usually results in a file size reduction of just over 50%.I was able to re-embed coverart into the resulting .oggs, but it made them unseekable. According to a chat on #ffmpeg, this is simply a limitation of ffmpeg/avconv (without going into technical details). The script extracts the coverart (once per folder) to the file "folder.jpg" (name can be changed inside the script)
The "rmflac" option will destroy the original .flac file if ffmpeg succeeds in transcoding it, even with errors! However, this usually means that the .flac file contained errors to begin with.
Last edited by ohnonot (2021-07-04 08:03:07)
Offline
a. You could check for actual duration difference instead of filesize, in this example 200 ms difference will still pass:
https://github.com/brontosaurusrex/post … p3#L81-L86
(line 81)
b. What kind of bitrates do you get with -q 9?
Last edited by brontosaurusrex (2016-01-07 08:37:50)
Offline
...i just thought that there's no reason to be flac2ogg - it could just as well be all media filetypes, although lossless probably makes the most sense.
a. You could check for actual duration difference instead of filesize, in this example 200 ms difference will still pass:
https://github.com/brontosaurusrex/post … ything2mp3
(line 81)
nice, thanks. will check that out. installing mediainfo now.
b. What kind of bitrates do you get with -q 9?
dunno. why does it matter?
Offline
dunno. why does it matter?
No, pure curiosity.
Offline
brontosaurusrex wrote:b. What kind of bitrates do you get with -q 9?
dunno. why does it matter?
Not sure about ogg, but with mp3 it makes a huuuge difference; anything lower than 128kbps is painfully obvious to most listeners. Not sure what the current default is for the lame encoder, but I always use -q 0, which yields maximum bitrate and minimum loss.
Be excellent to each other, and...party on, dudes!
BunsenLabs Forum Rules
Tending and defending the Flame since 2009
Offline
@pvsage: Especially with lame the others have reported that there is no much difference between -V0 (~245 kbps), -V1 (~225 kbps), -V2 (~190 kbps) or -V3 (~175 kbps) at problematic samples, while -V3 is generally transparent for most stuff, not that I care about any of this, just saying and disk space is relatively cheap this days.
Last edited by brontosaurusrex (2016-01-07 08:14:51)
Offline
just saying and disk space is relatively cheap this days.
+1
Lossy compression means you are losing the music.
Forever.
FLAC FTW!
Offline
^ Agreed. If you must go with a lossy format to save space, make sure that the amount of loss is something you can live with. If I'm doing my own transcoding, I never go with anything other than 320kbps mp3; virtually every player can read it, and it's the highest bitrate available in that format.
Be excellent to each other, and...party on, dudes!
BunsenLabs Forum Rules
Tending and defending the Flame since 2009
Offline
p.s. And btw: in specific case of flac2ogg one can skip ffmpeg/avconv.
Oggenc (vorbis-tools) can read flacs directly.
oggenc -q 5 some.flac
Opening with flac module: FLAC file reader
Encoding "some.flac" to
"some.ogg"
at quality 5.00
[100.0%] [ 0m00s remaining] |
Done encoding file "some.ogg"
File length: 4m 18.0s
Elapsed time: 0m 05.3s
Rate: 48.8877
Average bitrate: 145.6 kb/s
(Same with opus - opusenc)
The duration should match exactly then
mediainfo "--Inform=General;%Duration%" some.flac
258333
mediainfo "--Inform=General;%Duration%" some.ogg
258333
Last edited by brontosaurusrex (2016-01-07 09:47:37)
Offline
brontosaurusrex wrote:just saying and disk space is relatively cheap this days.
+1
Lossy compression means you are losing the music.
Forever.
FLAC FTW!
Compression is an euphemism. It's not like tar, which actually compresses stuff. In audio formats compression=deletion. Flac is bearable better than any other losy format though still cuts data at least to a half.
Offline
Flac is bearable better than any other losy format though still cuts data at least to a half.
No.
FLAC is lossless compression and preserves all data
See https://en.wikipedia.org/wiki/Lossless_compression
There is an argument that the increased processor overhead required to decompress the data would result in a slight loss of sound quality but this would only be noticeable in a true audiophile set up.
Offline
@Snap: FLAC actually is lossless compression similar to tar; a FLAC copy of a .wav file expands to an exact bit-for-bit copy of the original.
https://xiph.org/flac/documentation.html
EDIT: Ninja'd by Head_on_a_Stick
Last edited by pvsage (2016-01-08 07:59:39)
Be excellent to each other, and...party on, dudes!
BunsenLabs Forum Rules
Tending and defending the Flame since 2009
Offline
guys, i know what the script is doing (transcoding a lossless format to a lossy format).
in any case, for me automatization & recursiveness was an important part.
plus, salvaging the coverart (because neither ffmpeg nor oggenc manage to keep it).
ok, just to clarify about those bitrates - plus, there's still variable and constant to consider - the ogg quality scale goes from 1-10, so 9 is almost best, roughly on a par with 320kbps mp3 (both in filesize and my ears). libvorbis + ffmpeg doesn't seem to make a distinction between fixed + variable bitrates - my guess is it's all variable.
i guess i could have used oggenc just as well as ffmpeg, or would there be a quality/speed difference?
also, is it true i can encode to opus, but it's still an .ogg? would that result in a file that is widely readable (browser, android phone)?
Last edited by ohnonot (2016-01-08 08:19:54)
Offline
Opus will be/is probably better supported than vorbis (educated guess).
Android supports the Opus audio codec natively since version 5.0.
i guess i could have used oggenc just as well as ffmpeg, or would there be a quality/speed difference?
Probably not, just following the "less moving parts" approach might be wise. For speed: Gnu Parallel.
Last edited by brontosaurusrex (2016-01-08 17:37:49)
Offline