DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 2nd August 2015
thomasw_ thomasw_ is offline
Real Name: thomas
Port Guard
 
Join Date: Feb 2013
Location: kimberley
Posts: 30
Question flac to alac script help

Hi,

I have a problem with an audio conversion script -- from FLAC to ALAC.

I want to convert some of my library from FLAC to ALAC for ease of use on a Mac OSX box. I wrote a little script which works as expected on OSX just fine, but I'd like to know how I screwed up the script so that it doesn't run on OpenBSD 5.7. Both my OpenBSD 5.7 box and OSX box both use KSH for the shell. I get this error message on OpenBSD ...

Quote:
$/home/thomasw/bin/Flac2Alac.sh
/home/thomasw/bin/Flac2Alac.sh[6]: ${f/%flac/m4a}": bad substitution
... when running this script:

Code:
#!/bin/sh
#script using ffmpeg to convert FLAC to ALAC and use AtomicParsley to #merge the cover.jpg into the converted ALAC files.

for f in *.flac; do ffmpeg -i "$f" -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac "${f/%flac/m4a}" "${f/%flac/jpg}" && \
AtomicParsley "${f/%flac/m4a}" --artwork "${f/%flac/jpg}" --overWrite && \
rm "${f/%flac/jpg}"; done
I know a simple answer would be to use the script on OSX, but my entire audio library is on OpenBSD and copying the FLACs to run the script on the OSX is a tiresome task I'd like to avoid.

If anyone can hit me with a cluebat I'd appreciate it.

Thanks in advance --

thomasw
Reply With Quote
  #2   (View Single Post)  
Old 4th August 2015
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Code:
${f/%flac/m4a}
This will only work in certain shells, such as Bash or ksh.

1. Make sure you're using bash or ksh. I don't quite recall what /bin/sh in OpenBSD is, but IIRC is comes with *some* flavour of ksh by default.
2. Use ${f%.flac}.m4a, which will work in all Bourne shells.

I also don't quite understand why you put everything on a single line. Don't you agree that the following is much more readable :-)

Code:
#!/bin/sh
# script using ffmpeg to convert FLAC to ALAC and use AtomicParsley to #merge
# the cover.jpg into the converted ALAC files.

for f in *.flac; do
    new_file="${f%.flac}.m4a"
    image="${f%.flac}.jpg"

    ffmpeg \
        -i "$f" \
        -vf "crop=((in_w/2)*2):((in_h/2)*2)" \
        -c:a alac "$new_file" \
        "$image"

    AtomicParsley "$new_file" --artwork "$image" --overWrite
    rm "$image"
done
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #3   (View Single Post)  
Old 4th August 2015
thomasw_ thomasw_ is offline
Real Name: thomas
Port Guard
 
Join Date: Feb 2013
Location: kimberley
Posts: 30
Default

Use ${f%.flac}.m4a, which will work in all Bourne shells.

Thanks very much for this bit, Martin.


Also I appreciate the point regarding my script formatting
Reply With Quote
Reply

Thread Tools
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with flac files playback on cmus. sepuku OpenBSD Packages and Ports 7 20th November 2011 02:28 PM
Apple open sources its ALAC lossless audio codec J65nko News 2 29th October 2011 12:09 AM
ask for a shell script Simon Programming 5 27th April 2010 01:07 AM
flac to mp3 sniper007 FreeBSD General 6 20th October 2008 06:49 AM
my 1st sh script graudeejs Programming 12 18th August 2008 10:25 PM


All times are GMT. The time now is 05:18 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick