Hi I am Rupesh from India. I have a directory of size 65 GB which contains 2500 folders and 7000 mp3 files with 64 kbps bitrate.
I have installed opensuse with ffmpeg on my system.
I want to convert all these files to 16 kbps recursively I mean maintain folder structure of source. I have searched web for script and found some code but none of them provided what I want. I have searched even GUI frontend for ffmpeg and found some software but they don’t have option to convert all these files recursively and some don’t have option to convert to lower bitrate.
I have read ffmpeg manual pages and those was difficult to understand and even I don’t have scripting experience.
Can you create a script to perform the following steps
The script must compress files in each and every directory maintaining directory structure.
All files must be compressed to 16 kbps and 11500 samples per second with highest quality.
If any errors are encountered during the process the corresponding file information ie., file name with path must be stored in a seperate text file for future viewing.
After the process has been completed the system must shutdown.
I want accurate compression. Please try to create a bash script and post the script.
This is not a shop were you can order: “Please try to create a bash script and post the script”. Nor Are we the pupils in a class were you can ask so for home work.
We can however offer you some hints on the path to walk to a solution. But in the end you must do the hard work of coding (and understanding what you code and why) ;).
I think you should split the task into two things:
find the paths to all files that should be converted (which is a task that does not involve any knowledge on how to handle the conversion);
do the conversion on each of the files found (which will include all the things that requires knowledge on how to use ffmpeg or whatever to do the conversion).
On 1. you should first decide how it can be detected that the file is of the kind you want to convert. Let us assume that that can be determined from the fact that the file name ends in .mp3 (this being an assumption, the rest of my story can be nuts from here on when the assumption is wrong).
Also the next is just a starter to put our mind in a certain direction. This is not tested by me for any sort of errors.
#!/bin/bash
TOPDIR="/absolute/path/to/the/top/directory/of/the/mp3/files"
cd $TOPDIR
find . -name '*.mp3' | while read MP3FILE
do
echo $MP3FILE
done
When this works in giving you the names of all files wanted, you can replace the
OK sorry as I don’t have any script and shell programming experience I am unable to create a simple script. Is there any place in the current forum or other place where I can get help or other wise is there any GUI tool which is front end for ffmpeg for recursively compressing.
I have tried tragtor which is nice front end for ffmpeg and it has several options like bitrate, frequency etc., for converting single file but there is no option to load even two files in a single directory.
Why not soundkonverter? https://software.opensuse.org/package/soundkonverter
I’ve never had to recursively convert any of my sound files, but it would be very easy to simply drag and drop those files that need converting into soundKonerter’s window.
I did not say it wasn’t the right place. Well for the part “How to convert MP3 from type a to type b”, this Multimedia is. But for the part, how to let something work on all files of a special type found in a directory tree above a certain directory", there is a better place: Development > Programming and Scripting.
What I said was, that the simple request "Please try to create a bash script and post the script. " is not the best way to ask for help. We do try to provide help. We are not a bureau that you can ask to make ready solutions to your wish.
So when somebody has a ready solution (s)he will probably glad to post it here. But otherwise you will get offered suggestions like “look here”, “try and adopt this”, etc. And you can always come back then with something like"I tried and this happened, we are almost there, but I need a little help at this point".
Thus when you now say you have no knowledge whatsoever about bash programming, that is a new fact. And does not make it easier. But there are a few more suggestions already above.
your request seams simple enough until you thing about it
you say you have a lot of mp3 files you want to reencode to mp3 at 16k
the result would be bad especially as the input is already a lossy compressed mp3
hccv’s example is a good starting point
here’s a block I use to reencode video tweaked for mp3 output
for i in *.mp3;
do name=`echo $i | cut -d'.' -f1`;
echo $name;
ffmpeg -i "$i" -ab 16k "${name}-16k.mp3";
done
I’m not an expert at using ffmpeg but the following might help you.
What I use to find a keyword in multiple text files inside a directory is:
find . -name *.txt -exec grep -H “keyword” {} ;
So basically you can use the find command to grab all the files that you want to process (in your case *.mp3) and then use the -exec option to apply a command to those files (in my case it’s just a grep).
the snippet I gave you does more or less the same thing
it just doesn’t go thru folders
make a sh file paste the text in it
put it in the folder you want processed and click on it
the windows batch fule moves processed mp3’s to a %_target% folder
“_TARGET=E:\Rupesh\ffmpeg out”
here’s the script again modified to create a processed subdir in the current dir and move allready processed mp3’s there so they can be reviewed for deletion
md _done
for i in *.mp3;
do name=`echo $i | cut -d'.' -f1`;
echo $name;
ffmpeg -i "$i" -codec:a libmp3lame -ab 16k -ar 11025 "${name}-16k.mp3";
mv "$i" _done
done
the script will append -16k to the mp3’s name so you know they’ve been reencoded with 16k
hcvv’s script works even better as it will find all mp3’s in all sub-directories you just need to edit the part after