Add a "Right-click on a .WAV file, Convert to MP3" extension to Explorer

2

1

I created a key in the Windows registry:

HKEY_CLASSES_ROOT\*\Shell\Convert to MP3\command

with:

"D:\tools\ffmpeg.exe" -i "%1" -acodec libmp3lame -vn -ar 44100 -ac 2 -ab 256k "%1.mp3"

It works, except that the filename is not exactly what I want:

Input: test.wav, Output: test.wav.mp3

whereas I'd like the output filename to be test.mp3.

I also tried with:

"D:\tools\ffmpeg.exe" ... "%~n1.mp3"

like in this answer, but it doesn't work: the output is %~n1.mp3 then!

How to remove the original extension like this, and replace by .mp3?

PS: I'm looking for a solution without involving a .bat file, but only the registry. If not possible, it's ok to use a bat file.

Basj

Posted 2018-04-07T19:13:45.967

Reputation: 1 356

Use a .cmd file and do it from there. It should work then. – LPChip – 2018-04-07T19:17:29.210

@LPChip Isn't there a way to do it just from a single line in registry? Are %~n1 things supported only in cmd/bat file? – Basj – 2018-04-07T19:18:47.237

As far as I know, yes. – LPChip – 2018-04-07T20:49:51.423

Answers

1

Assumed that ffmpeg.exe is included by path variable, use

cmd /q /c for %%I in ("%1") do ffmpeg -i %%I -acodec libmp3lame -vn -ar 44100 -ac 2 -ab 256k "%%~nI.mp3"
as one-liner without bat file.

guest-vm

Posted 2018-04-07T19:13:45.967

Reputation: 2 984

Posted on your request. As a >2k user I should focus on more advanced commands & give chance for newcomers to answer, hence I initially posted in comment. If you'd award this bounty to me, I'll refund it to you by sponsoring your next question of interest. – guest-vm – 2018-05-13T22:45:11.977

1

Here is a solution with a .BAT file (don't know if it's possible without a BAT file). The key is to use %~n1.mp3, as explained here.

File ____LameMP3me.bat:

"D:\Documents\software\____PORTABLE\____useful-tools\ffmpeg.exe" -i %1 -acodec libmp3lame -vn -ar 44100 -ac 2 -ab 256k "%~n1.mp3"

In HKEY_CLASSES_ROOT\*\Shell\Lame MP3 me!\command:

"D:\Documents\software\____PORTABLE\____useful-tools\____LameMP3me.bat" "%1"

Basj

Posted 2018-04-07T19:13:45.967

Reputation: 1 356

1

Instead of registry hacking you could just put the .bat file (or a .lnk file pointing to it) into %APPDATA%\Microsoft\Windows\SendTo.

Here's a cygwin + bash solution for the file extension problem, requires exactly one additional line of code thanks to https://www.tldp.org/LDP/abs/html/string-manipulation.html

You would start it by c:\cygwin\bin\bash.exe <scriptname> <filename>

#!/bin/bash

FILE_NAME="${1%.*}"

"/cygdrive/d/tools/ffmpeg.exe" -i "\"$1\"" -acodec libmp3lame -vn -ar 44100 -ac 2 -ab 256k "\"${FILE_NAME}.mp3\""

#keep the console window open, uncomment if not necessary
read

T Nierath

Posted 2018-04-07T19:13:45.967

Reputation: 389

Thank you for your answer, but using SendTo vs. contextual menu command doesn't change anything to the original problem (i.e. having the files named test.wav.mp3 instead of test.mp3). Also using SendTo is longer to do when doing it a lot (right click, click on SendTo, find the right item) than a direct Context menu item. – Basj – 2018-05-11T20:29:28.397

I know, but keep in mind that people may come to this place via searching google. I certainly wish I had known about this little trick much sooner. – T Nierath – 2018-05-11T21:08:26.687

Regarding your filename problem. I never learned power shell, so what I do is install cygwin and run more involved stuff as a bash script. But that's hardly a solution for you I guess. – T Nierath – 2018-05-11T21:16:46.857

@Basj added the bash solution just in case – T Nierath – 2018-05-13T21:34:13.420