LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-27-2011, 07:33 AM   #1
davidjmcc86
LQ Newbie
 
Registered: Oct 2005
Location: Kanagawa, Japan
Distribution: Fedora 16
Posts: 10

Rep: Reputation: 0
Shell script ffmpeg


Hello,

I have converted my CD collection to .flac

Now I would like to play my music on my ipod and a DSi, so I need to convert my files to .aac

I have written this script

Code:
!/bin/bash
# title holds name of song
for title in *
ffmpeg -i $title $title.aac
done
I get the following error

Code:
$ ./MusicConvert.sh
./MusicConvert.sh: line 4: syntax error near unexpected token `ffmpeg'
./MusicConvert.sh: line 4: `ffmpeg -i $title $title.aac'
I think I may also need to find a way to ensure the correct suffux is on the file. I'm afraid if it does work I will end up with file.flac.aac

Any advice is much appreciated.
Dave

Last edited by davidjmcc86; 08-27-2011 at 07:55 AM. Reason: solved
 
Old 08-27-2011, 07:41 AM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
You missed the 'do'
Also you probably want to use basename:

Code:
!/bin/bash
# title holds name of song
for title in *.flac
do
    ffmpeg -i $title $(basename $title .flac).aac
done

Last edited by dive; 08-27-2011 at 07:43 AM.
 
1 members found this post helpful.
Old 08-27-2011, 07:53 AM   #3
davidjmcc86
LQ Newbie
 
Registered: Oct 2005
Location: Kanagawa, Japan
Distribution: Fedora 16
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks alot for your help. You can tell I don't write scripts often.

Have a great weekend!
Dave
 
Old 08-27-2011, 11:33 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
A few more points.

1) The shabang starts with a "#!".

http://mywiki.wooledge.org/BashGuide...uments#Scripts

2) Always quote variables, to avoid problems with word splitting.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/Quotes

3) Use globbing rules to ensure that you're grabbing only the files you want. For complex cases, use find.

http://mywiki.wooledge.org/glob
http://mywiki.wooledge.org/UsingFind

4) basename is unnecessary when you have parameter expansion. You may want to collect and use both the path and the filename, to make your script more flexible.

http://mywiki.wooledge.org/BashFAQ/073

5) Consistent indentation and similar formatting, among other good practices, helps make scripts easier to read and debug. I think for/while/until loops are more readable when the "do" keyword is also on the same line, for example.

http://mywiki.wooledge.org/BashGuide/Practices

Code:
#!/bin/bash

for title in ./*.flac; do

	path="${title%/*}"
	name="${title##*/}"
	ffmpeg -i "$title" "$path/${name%.*}.aac"

done
 
2 members found this post helpful.
Old 08-28-2011, 06:27 AM   #5
davidjmcc86
LQ Newbie
 
Registered: Oct 2005
Location: Kanagawa, Japan
Distribution: Fedora 16
Posts: 10

Original Poster
Rep: Reputation: 0
David the H, thanks for your help and the website. I will incorporate all into my next script.

R/
Dave
 
  


Reply

Tags
bash, ffmpeg


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] ffmpeg - how to add watermark to a video via shell HajdukJanko Linux - Software 16 01-21-2013 10:42 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
need shell script in ffmpeg yajur Programming 3 09-03-2008 08:30 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:45 PM.

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