Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

requesting script for compressing mp3 files recursively

A collection of useful tutorials for some common tasks.

requesting script for compressing mp3 files recursively

Postby rupeshforu3 » Wed May 03, 2017 7:32 am

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 Windows 8 and Linux 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
1) The script must compress files in each and every directory maintaining directory structure.
2) All files must be compressed to 16 kbps and 11500 samples per second with highest quality.
3) 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.
4) After the process has been completed the system must shutdown.

I want accurate compression. Please try to create a bash script ( linux ) or a batch script ( Windows ) and post the script.

Regards,
Rupesh.
rupeshforu3
 
Posts: 12
Joined: Sun Mar 19, 2017 11:12 am

Re: requesting script for compressing mp3 files recursively

Postby llogan » Wed May 03, 2017 4:46 pm

We do not provide help for scripts here. We only provide help for the direct usage of the FFmpeg tools. Please try a Bash or batch help forum.

I'm assuming you're encoding to MP3. Sample rate of 11500 is not supported by libmp3lame. See output of:
Code: Select all
ffmpeg -h encoder=libmp3lame
Get an answer more quickly by providing your actual ffmpeg command and the complete console output. Use the code button to format your command and output or your question will be ignored.
llogan
 
Posts: 2339
Joined: Fri Jan 25, 2013 9:47 pm
Location: Alaska

Re: requesting script for compressing mp3 files recursively

Postby rupeshforu3 » Fri May 05, 2017 4:59 pm

Hi I have copied code from http://stackoverflow.com/q/42874310/5726027 and created a script of which I am providing below

Code: Select all
@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem // Define constants here:
set "_SOURCE=C:\Rupesh\to convert"
set "_TARGET=E:\Rupesh\ffmpeg out"

rem // Change to source directory temporarily:
pushd "%_SOURCE%" || exit /B 1
rem // Enumerate source files, return paths relative to the source directory:
for /F "delims=" %%F in ('xcopy /L /S /I ".\*.mp3" "%_TARGET%" ^| find ".\"') do (
    echo Currently converting "%%F"...
    rem // Create destination directory, suppress error if it aready exists:
    mkdir "%_TARGET%\%%F\.." 2> nul
    rem // Perform actual file conversion, using paths relative to target directory:
    ffmpeg -i  "%%F" -v quiet -codec:a libmp3lame -b:a 16k -ar 11025 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "%_TARGET%\%%F\..\%%~nF.mp3"
)
echo Completed.
popd

endlocal
exit /B


Upon executing the above script I am able to accomplish what I want but now my question is after encoding by liblame is there any possibility to compress again and create an mp3 file . My target is to create mp3 files with maximum compression ratio. Is there any possibility of specifying audio channels to mono in above code.


Actually what I want to compress mp3 files are originally speeches recorded by someone at 64 kbps and I want to convert to 16 kbps. Someone suggested to use speex codec instead of mp3 and I am asking whether it is feasible or not.

Regards,
Rupesh.
rupeshforu3
 
Posts: 12
Joined: Sun Mar 19, 2017 11:12 am

Re: requesting script for compressing mp3 files recursively

Postby llogan » Fri May 05, 2017 5:45 pm

rupeshforu3 wrote:after encoding by liblame is there any possibility to compress again and create an mp3 file

I don't recommend doing that. It will sound bad and not help at all.

rupeshforu3 wrote:Is there any possibility of specifying audio channels to mono in above code.

Add "-ac 1".

rupeshforu3 wrote:Someone suggested to use speex codec instead of mp3 and I am asking whether it is feasible or not.

Opus has generally replaced the older Speex, and Opus will probably sound better than MP3 at such low bitrates. Basic command example:

Code: Select all
ffmpeg -i input -c:a libopus -ac 1 -b:a 16k output.opus


Some info here:
https://wiki.xiph.org/Opus_Recommended_Settings

See options specific to this encoder:
Code: Select all
ffmpeg -h encoder=libopus
Get an answer more quickly by providing your actual ffmpeg command and the complete console output. Use the code button to format your command and output or your question will be ignored.
llogan
 
Posts: 2339
Joined: Fri Jan 25, 2013 9:47 pm
Location: Alaska

Re: requesting script for compressing mp3 files recursively

Postby rupeshforu3 » Thu May 11, 2017 12:38 pm

When I use sample rate 24000 I am getting same output size as 11500 and so which sample rate is feasible.

In lamexp which is GUI for lame in windows there is an option for quality I mean algorithmic quality and so is there any option for quality in ffmpeg.

Regards,
Rupesh.
rupeshforu3
 
Posts: 12
Joined: Sun Mar 19, 2017 11:12 am


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest