Batch Script to Convert to MP3

Useful and helpful Windows specific command line samples and examples.
Post Reply
User avatar
Zeranoe
Site Admin
Posts: 698
Joined: Sat May 07, 2011 7:12 pm
Contact:

Batch Script to Convert to MP3

Post by Zeranoe » Wed Feb 06, 2013 4:17 am

Here is a simple Batch script I have used in the past to convert any file into a mp3 format audio file.

This can be very helpful is you are compressing an entire album from PCM wav to mp3. Or to convert a video file into just the audio from that file.


Place this .bat script in the same directory as ffmpeg.exe and simply select all the files that need converting and drag and drop them onto the .bat script file. FFmpeg will cycle through and encode all of them to mp3 using lame. It will save the output mp3 files to the same directory as the originally selected files.

The script is attached inside the .zip file, but here is the code:

Code: Select all

@ECHO OFF

SET bitrate=320

FOR %%A IN (%*) DO (
  IF NOT EXIST "%%~nA.mp3" %~dp0\ffmpeg.exe -i %%A -vn -c:a libmp3lame -b:a %bitrate%k "%%~nA.mp3"
)
To change the bitrate of the output mp3 file, change the number following "SET bitrate=320" to another bit rate, such as "SET bitrate=192" or "SET bitrate=128".

If there is a interest for more batch scripts let me know, these are only really helpful when dealing with a large number of files.
Attachments
enode-lame.zip
(319 Bytes) Downloaded 3390 times

hydra3333
Posts: 173
Joined: Sun Apr 28, 2013 1:03 pm
Contact:

Re: Batch Script to Convert to MP3

Post by hydra3333 » Sat May 25, 2013 1:45 am

Thanks! A suggestion - added extra quotes for source filenames containing spaces ?

@ECHO OFF

SET bitrate=320

FOR %%A IN (%*) DO (
IF NOT EXIST "%%~nA.mp3" %~dp0\ffmpeg.exe -i "%%A" -vn -c:a libmp3lame -b:a %bitrate%k "%%~nA.mp3"
)

omniplex
Posts: 9
Joined: Mon Jun 06, 2016 9:00 pm

Re: Batch Script to Convert to MP3

Post by omniplex » Sat Jun 11, 2016 9:33 pm

If there is a interest for more batch scripts let me know, these are only really helpful when dealing with a large number of files.
Yes, please, and no, it's not only helpful for many files and Sendto-cases.

Slightly exotic example, get some relevant output with ffprobe for a comparison with MediaInfo in a black-on-white command line window, i.e., either use ansicon -m, or without ansicon.exe try set AV_LOG_FORCE_NOCOLOR=1, or switch to color 0F (ugly). After that always use ffplay/ffprobe/ffmpeg options -hide_banner -err_detect aggressive, because it never hurt me, and together with -v warning (no info) or -v verbose (more info) I typically get what I need.

But for ffprobe I also want normally disabled demuxers or decoders, i.e., -strict experimental. Putting it all togther I (= my ffinfo.cmd script using your ffprobe.exe) arrive at one long line like this:

Code: Select all

ansicon.exe -m ffprobe.exe -hide_banner -err_detect aggressive -v warning -show_entries format=format_name,duration,tags:error:stream=codec_type,codec_name,duration,sample_fmt,sample_rate,channels,channel_layout,pix_fmt,width,height,bit_rate,r_frame_rate,sample_aspect_ratio,display_aspect_ratio -of csv=p=0:svr=? -unit -sexagesimal -strict experimental -probesize 2MiB "input.xyz"

Masutin
Posts: 5
Joined: Mon Jun 18, 2018 8:11 am

Post by Masutin » Mon Jun 18, 2018 9:41 am

Can you include code for VBR?

Post Reply