LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 12-28-2012, 08:37 AM   #1
tsitras
Member
 
Registered: Mar 2003
Distribution: Debian Squeeze
Posts: 182

Rep: Reputation: 30
file convert


hi. i am looking to convert files (manually) for my asterisk. i do have some files in .gsm, .wav, .alaw, .ulaw format. i need to change the format between them.
in another box that i have that runs centos 6 the command is
file convert name.wav file.ulaw
same applies for all other formats.
unfortunately i cannot see how to make it work in debian.
 
Old 12-28-2012, 10:37 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Sorry, you run
Code:
file convert foo.wav bah.ulaw
and it converts the file "foo.wav" to the file "bah.ulaw"?

What version of 'file' do you have on your CentOS box?

I would write a shell script for this - I would expect that to convert between each pair of formats, you will need to run a different command, so I would write a script to work out the format of the files (based on their extensions) and then run the appropriate command. Does that answer your question, or were you looking for something more specific?
 
Old 12-28-2012, 11:00 AM   #3
tsitras
Member
 
Registered: Mar 2003
Distribution: Debian Squeeze
Posts: 182

Original Poster
Rep: Reputation: 30
could you post the script please?
the file formats that i would like to convert between them are:
wav, mp3, gsm, g729, alaw, ulaw
 
Old 12-29-2012, 09:58 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
You're lucky it's a Saturday normally it's better for you to try it yourself: I and the other people on the forum will often not have time to write and test a script for you, and you will learn a lot more doing it yourself! However, here it is:

Code:
#!/usr/bin/env bash

#####################
# Edit this section #
#####################

# Edit this section to add new formats:
# commands["extension_from extension_to"]="convert_command"
# INFILE and OUTFILE in the conversion command are replaced with the appropriate filenames
declare -A commands
commands["wav mp3"]="ffmpeg -i INFILE OUTFILE"
commands["mp3 wav"]="ffmpeg -i INFILE OUTFILE"
commands["wav gsm"]="sox INFILE -r 8000 -c 1 OUTFILE resample -ql"
commands["mp3 gsm"]="sox INFILE -r 8000 -c 1 OUTFILE resample -ql"
commands["gsm mp3"]="lame -V 9 INFILE OUTFILE"

#####################
# Stop editing here #
#####################
if [ ! $# -eq 2 ]; then
    echo "Usage: $0 inputfile outputfile"
    exit 1
fi
ext1=${1##*.}
ext2=${2##*.}

command=${commands["$ext1 $ext2"]-"NULL"}
if [ "$command" == "NULL" ]; then
    echo "Error: No rule for converting .$ext1 to .$ext2"
    exit 1
fi
command=$(echo "$command" | sed "s/INFILE/'$1'/g; s/OUTFILE/'$2'/g")
eval $command
Hope this helps,
 
1 members found this post helpful.
Old 12-29-2012, 10:10 AM   #5
tsitras
Member
 
Registered: Mar 2003
Distribution: Debian Squeeze
Posts: 182

Original Poster
Rep: Reputation: 30
thanks a lot.
 
Old 12-29-2012, 10:11 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
If it works for you, then please remember to come back and mark the thread as 'SOLVED'.

Thanks,
 
  


Reply


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
how to find free software to convert an imported .dst file to a .pes file. seabee 2 Linux - Software 3 08-28-2012 03:01 PM
Utility/Tool to convert .f4v file to file PC can view rhbegin Linux - Software 5 02-09-2012 08:51 AM
[SOLVED] How would I convert an arbitrary binary file into a Linux executable file? ootawata Programming 8 02-21-2010 11:21 PM
howto convert .flw (koffice/kivio file) into windows readable type of file? rahmmandel Linux - Desktop 7 01-30-2007 04:12 PM
Howto convert bin file to a executable DOS file lilzz Linux - Newbie 5 08-04-2006 12:03 AM


All times are GMT -5. The time now is 11:28 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration