You are not logged in.

#1 2012-05-19 23:11:40

songandsilence
Member
From: Burlingame, KS, USA
Registered: 2010-12-01
Posts: 28

Batch re-encoding of music??

I've got an older laptop that I use Arch on, using it mostly as the home DJ box. However, the hard drive on it is pretty small, and now I often find myself going through ~/ and searching for things (old source tarballs and such) that are just taking up space on the partition.

Then, it hit me. A good chunk of my music is encoded @ 320 kbps, making the files larger than they need to be. 192 kbps would be a high enough quality for what I need, while respecting the need for a space constraint.

The problem, however, is that my music folder is well sorted (artist, album, disc), and going through each individual folder doing this would be an all-day thing. I need a solution that's automated (so I can start it when I go to bed) and recursive from ~/Music/

Any ideas? I'm somewhat competent with bash scripting if need be, but a GUI program would be rather nice.

TL;DR: Need to change 320 kbps songs into 192 kbps songs in one folder that consists of many subfolders, with many sub-subfolders.

Offline

#2 2012-05-19 23:28:59

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Batch re-encoding of music??

I would define a function/script that wraps ffmpeg or mencoder and then gets called by "find -exec ...".

find ~/Music -type f -regex ".*\.ogg" -exec oggsquasher {} \;
#! /bin/bash
# oggsquasher: re-encodes an ogg at 192kbps.
dir=$(dirname "$@")
name=$(basename "$@")

[[ "x$(file \"$name\" | awk -F': ' '{print $2}')" = "xOgg data, FLAC audio" ]] \
&& ffmpeg -i "$@" -ab 192k /tmp/"$name" \
&& mv /tmp/"$name" "$dir"

... or the like.

Edit: parallelisation is also possible, but there is small incentive and some disincentive. It's only small incentive because I suppose all the music is on the one drive, so you will face a bottleneck of read/write speeds no matter how many cpus you have. There is some disincentive because looping over files that may contain spaces in their names makes it easy to introduce bugs. Dealing with files one at a time lets you not worry too much if files have spaces in their names.

Last edited by /dev/zero (2012-05-19 23:47:10)

Offline

#3 2012-05-19 23:49:42

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Batch re-encoding of music??

Of course you're going to compress already compressed files if you do this. You won't end up with the 192 kbps version like if you were working off of the original source material. The sound quality may diminish significantly.

Offline

#4 2012-05-20 00:08:41

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Batch re-encoding of music??

skottish wrote:

Of course you're going to compress already compressed files if you do this. You won't end up with the 192 kbps version like if you were working off of the original source material. The sound quality may diminish significantly.

I did a test, converting an ogg at 452kbps to 192kbps, and the two files sound exactly the same to my (non-audiophillic) ears.

Offline

#5 2012-05-20 00:22:46

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Batch re-encoding of music??

/dev/zero wrote:
skottish wrote:

Of course you're going to compress already compressed files if you do this. You won't end up with the 192 kbps version like if you were working off of the original source material. The sound quality may diminish significantly.

I did a test, converting an ogg at 452kbps to 192kbps, and the two files sound exactly the same to my (non-audiophillic) ears.

If one is sticking with the same format, then the troubles get minimized quite a bit as it's the same algorithm used to do the work. Transcoding between formats is quite destructive and when the source is already highly compressed, it can make the quality much worse. The main thing that happens is that files get degraded enough where the audio starts to become either distorted, muffled, or 'thin' sounding. This is most evident with good amplifiers and speakers at a decent volume. On the other hand, many people don't hear the difference and really don't care.

Offline

#6 2012-05-20 01:30:44

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Batch re-encoding of music??

songandsilence wrote:

Any ideas? I'm somewhat competent with bash scripting if need be, but a GUI program would be rather nice.

Install soundconverter from [community], change the settings to how you want them to be, dump all your songs into it, press the Convert button, go to sleep, wake up, and enjoy your new collection.

Please don't write your own solution. It's already been done so many times. There are so many other things in life to enjoy besides rewritting the same programs for Linux over and over. Like, enjoying an avocado. Or going swimming. You can't really listen to your newly converted music while swimming, but I suppose you could while eating an avocado...

Offline

#7 2012-05-20 04:17:27

songandsilence
Member
From: Burlingame, KS, USA
Registered: 2010-12-01
Posts: 28

Re: Batch re-encoding of music??

Thanks much. I'll try soundconverter. Will mark as solved if it works.

Oh, and I could totally listen to my newly converted music while swimming.

Of course, it helps if I could actually swim first. I suppose I could just get some SCUBA gear and chill out at the bottom of a pool for a few hours instead.

Last edited by songandsilence (2012-05-20 04:21:26)

Offline

#8 2012-05-20 10:20:18

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Batch re-encoding of music??

@op - to avoid the issue of transcoding lossy --> lossy you could change your music storage paradigm and do you initial rips to flac (a lossless format),  Then use one of many flac-->whatever scripts to produce "portable" copies to whatever format/bitrate you wish without the quality losses others have already mentioned.  For example, flac2all.

Offline

Board footer

Powered by FluxBB