I have a directory with many folders containing hundreds of .SPH files. I need to convert all .SPH files into .wav format. I have adopted the following code:
cd %~dp0
mkdir converted
FOR %%A IN (%*) DO sox -t raw -s -2 -r 22050 -c 2 %%A "converted/%%~nA.wav"
pause
However, it doesn't do anything on Windows 7. When I try the code on CMD inside a folder where some of .SPH are:
sox *.SPH output.wav
It embeds all *.SPH into output.wav file, which is not what I want. I need name1.SPH to name1.wav, name2.SPH to name2.wav
Please help.
For Linux consider this:
for f in *.SPH; do sox -t sph "$f" -b 16 -t wav "${f%.*}.wav"; done
In Windows 7, I need to provide the entire path for the destination files, and the mdkir command got a permission error even though I was running as Administrator, so pre-make your destination directory and delete the mkdir command, and then your SOX command should look similar to this (with your own flags based on the conversion or edit you are trying to accomplish):
FOR %%A IN (%*) DO sox -t raw -e mu-law -c 1 -r 8000 %%A c:\converted\%%~nA.wav
The cmd file should not be in the folder where the files are, it should be in the folder where SOX is installed, and then drag the files you want converted onto the cmd (or bat) file.
for %%a in (*.sph) do sox "%%~a" "%%~na.wav"
Make a .bat file in your sox directory with the contents
cd %~dp0
for %%a in (*.sph) do sox "%%~a" "%%~na.wav"
pause
Select and drag the files that you want to convert onto this .bat file and the .wav files with the same names as the .sph files will appear in the same folder as the .sph files.
Related
I'm converting a couple thousand .wem files to .wav format. Since .wem is an obscure file format, I've decided to convert the files with SoX.
The SoX standard installation includes a batch file for use with mass converting raw files, which I've happily used. I've modified the example to remove the need to drag and drop files onto the batch file, using nested loops.
cd %~dp0
mkdir converted
for %%f in (*.wem) do FOR %%A IN (%*) DO sox -t raw -e signed-integer -b 16 -c 1 -r 44100 %%A "converted/%%~nA.wav"
pause
It creates a /converted directory just fine, and then proceeds to output the command, the directory, and then moves on to (supposedly) the next file. Unfortunately, opening the /converted directory reveals that nothing was generated at all, and the conversion took a lot less time than it should have. I've tested it with .wem files prior, and it converts just fine, so I don't think it has anything to do with the format. More likely, it just has something to do with my amateur batch file programming. Any ideas?
Solved, thanks to Mofi.
Finished code:
cd %~dp0
mkdir converted
for %%I in (*.wem) do sox -t raw -e signed-integer -b 16 -c 1 -r 44100 "%%I" "converted\%%~nI.wav"
pause
Seems I really could do it in one loop.
I have a lot of gifs I want converted to webms in many sub directories, and I have this script which will do it, but it will output to the directory where the script is located:
for /r %%a in ("*.gif") do ffmpeg -i "%%a" -c:v libvpx -crf 12 -b:v 4000k "%%~na.webm"
pause
I've tried a bunch of things, but I can't figure out how to get the output to land in the same sub directory as the input file so I can maintain the folder structure.
Edit: it's a Windows batch file I'm using.
You are missing two command modifiers for your output filename.
"%%~dpna.webm"
I wrote this code for HandBrakeCLI as a batch file to manipulate my videos. This code creates output files with input file name plus a "_conv" suffix.
for /R .\test %%F in (*.mov) do HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~pF%%~nF_conv.mp4
Then I want to delete the original file and then remove _conv part of the output file. What should be added to the code above?
I want to delete each file just after converting it, or at least when going from its containing folder to another folder, not wholly after converting all of the file (because lots of files must be converted and I may run out of space)
By the way, how can I add other formats in addition of *.mov in the code?
for /R .\test %%F in (*.mov) do (
HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~dpF%%~nF_conv.mp4"
if exist "%%~dpF%%~nF_conv.mp4" (
del "%%~fF"
ren "%%~dpF%%~nF_conv.mp4" "%%~nxF"
)
)
All the information is inside your original code. All that is needed is to wrap the set of commands in parenthesis so the three commands are executed for each of the input files. Also, an aditional if has been included to only delete the source file if the converted file exists.
After a hard study, I have created a batch file:
for /R D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i %%a -y %%~na.mp3
However, it can't reach my goal since the scenario is a little different here:
Here is my directory structure:
I have several directories under a certain path:D:\storytelling\MusicFiles\ and new directories could be created by another application. And I put ffmpeg.exe file in this path: D:\storytelling\MusicFiles\.
Also, In each directory, I have hundreds of .3gp files, and my target is to convert them to .mp3 in the directory where they used to stay at.
But this script
for /R D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i %%a -y %%~na.mp3
would convert every .3gp file in each directory to the path: D:\storytelling\MusicFiles\
It leads to:
But I want the publicUser_XXX.mp3 files are still in the directory publicUser and after conversion all the files remain in their original directory. The only change is that I got new a media copy with different media format like:
Please help and give me some advise.
Try this:
#echo off
for /R D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i "%%a" -y "%%~dpna.mp3"
i have a folder full of .avi files and i want to use ffmpeg to convert them to .mp4 files. I followed an online tutorial to create a batch file that does just this, here is the code:
"C:\ffmpeg\ffmpeg.exe" -y -i %1 -sameq -ar 22050 -vcodec libx264 "C:\videos\Series 1\S01E01.mp4"
This works fine if i just drag and drop the .avi files onto the createmp4.bat file containing the above code. However i want to be a little bit smarter about this and use another batch file that will iterate through the .avi files in the folder and run createmp4.bat on all of them and copy them to the C:\videos\Series 1\ directory.
I would also like to change the name of the files if possible to S01E01.mp4, S01E02.mp4 and so on if possible.
Any help on this would be greatly appreciated. Oh and just in case you hadn't guessed i am fairly clueless about writing batch files!!
Thanks
try this (example):
#echo off & setlocal
pushd "X:\My AVI folder"
for %%i in (*.avi) do "C:\ffmpeg\ffmpeg.exe" -y -i "%%~fi" -sameq -ar 22050 -vcodec libx264 "C:\videos\Series 1\%%~ni.mp4"
popd