Posts Tagged ‘batch’

Convert any audio/video files to mp3 for free

Tuesday, November 24th, 2009

It seems that there is some confusion about audio conversion tools and some people even pay for them.

The truth is that most encoders, even ones you pay for, use ffmpeg internally to do all of the actual work and ffmpeg is free and open source.

You can even get it pre-compiled for Windows, though the version isn’t great.

The only problem with using ffmpeg directly is that it has a command line interface and most novices find it hard to use.

Here’s a batch file for use on Windows which will convert anything you drop onto the file into a 320kbps mp3:

ffmpeg -i %1 -ab 320k -y %1.mp3
@if errorlevel 1 @pause

To create this file, open notepad. Copy and paste the above 2 lines in. Save it as “convert.bat” or something similar (the .bat is important) and select “All files” from the drop down list.

Put the bat file in the same directory as ffmpeg.exe and simply drag anything you want converted on top of the bat file.

You can use almost anything. wav, m4a, m4v, mov, mpg, avi, etc. If you use a file with both audio and video, such as a movie, it will just extract the audio and save that as an mp3 file.

Die thumbs.db, die!

Saturday, January 31st, 2009

Someone just told me that they were going to download a program that would clean their windows hard drive of “thumbs.db” files, so I gave them this command line instead:

for /f "tokens=*" %a in ('dir /b /s /aSH thumbs.db') do @(
  echo %a
  del /f /aSH "%a"
)

This very quickly (under 1 minute for my whole C: drive) scans directories recursively for thumbs.db files, removes the “hidden” and “system” attributes and then deletes them, forcing deletion even if the files are read-only.

Of course, you would “cd” to the correct directory first (e.g. cd \ to do the whole drive), if you want to put it in a batch file you need to double up the percent symbols (%a becomes %%a) and you will need appropriate permissions to delete the files it finds (and maybe to change their attributes), so you may need to run this from an elevated command prompt if you are not running it in a directory that you own.

You should also note that the “/aSH” part of the “dir” command (there is no space, as this may also match files and directories called “sh”) assumes that the files are hidden and system files (as they are by default but probably not if you have extracted them from something like a zip file where someone has left them in). If the files are just hidden, just system or neither (just normal files) they will not appear in the list and will not be deleted. An alternative implementation could either run it once with this set and once with just “dir /b /s thumbs.db” or could run it once to remove the S and H attributes (or separately for each of these) and then after they are all “normal” files, run it through again to delete them.

The “echo” line is optional and just shows a verbose output as it deletes things. If you remove it you can also remove the parenthesis and put the whole thing on 1 line if you so wish.

Update:
Better:

for /f "tokens=*" %a in ('dir /b /s /aS thumbs.db') do @attrib -S "%a"
for /f "tokens=*" %a in ('dir /b /s /aH thumbs.db') do @attrib -H "%a"
for /f "tokens=*" %a in ('dir /b /s /aSH thumbs.db') do @attrib -S -H "%a"
 
for /f "tokens=*" %a in ('dir /b /s thumbs.db') do @(
  echo %a
  del /f "%a"
)