convert multi file in multi folder with ffmpeg - audio

i want to use ffmpeg for convert all file in multi folder
for example
i want to convert all audio on more then 170 folder with ffmpeg at once
..\voice\SP_WL6_kismet1_a_LOC_INT\snd_vo_SP_WL_wav
..\voice\SP_WL6_kismet1_a_LOC_INT\ed_vo_SP_WL_wav
....
....
....
This folder also contains files in other formats
on these folders i have more then 1000, ogg file i want to convert all of them to wav at once

i use this in cmd and it work for me
FOR /R %f IN (*.ogg) DO ffmpeg -i "%f" "%f.wav"

Related

How to define the condition of a corrupted file for audio file in Python

I am using Python 3.6, Jupyter notebook by connecting to a remote machine. I have a large dataset of mp3 files. I use FFmpeg (version is 2.8.14-0ubuntu0.16.04.1.) to convert mp3 files to wav format.
My code below goes over the file path list and if the file is mp3 it converts it to wav format and deletes the mp3 file. The code works but for a few files it stops and gives error. I opened those files and saw that they have no duration and each of them has size 600 looking at the terminal folder size column but it might be a coincidence. The error is file not found for 'temp_name.wav'.
I can see that these corrupted files are not able to be converted to wav. When I delete them manually and run the code again it works. But I have large datasets and cannot know which files are corrupted beforehand. Is there a way to make the code (before converting the file to wav) if the file is corrupted it deletes it and continues to next file. I just don`t know how to define the condition of a corrupted file or if the file cannot be converted to wav.
# npaths is the list of full file paths
for fpath in npaths:
if (fpath.endswith(".mp3")):
cdir=os.path.dirname(fpath) # extract the directory of file
os.chdir(cdir) # change the directory to cdir
filename=os.path.basename(fpath) # extract the filename from the path
os.system("ffmpeg -i {0} temp_name.wav".format(filename))
ofnamepath=os.path.splitext(fpath)[0] # filename without extension
temp_name=os.path.join(cdir, "temp_name.wav")
new_name = os.path.join(ofnamepath+'.wav')
os.rename(temp_name,new_name) # use original filename with wav ext
old_file = os.path.join(ofnamepath+'.mp3') # find and delete the mp3
os.remove(old_file)

Change huge amount of data from NIST to RIFF wav file

So, I am writing a speech recognition program. To do that I downloaded 400MB of data from TIMIT. When I inteded to read the wav files (I tried two libraries) as follow:
import scipy.io.wavfile as wavfile
import wave
(fs, x) = wavfile.read('../data/TIMIT/TRAIN/DR1/FCJF0/SA1.WAV')
w = wave.open('../data/TIMIT/TRAIN/DR1/FCJF0/SA1.WAV')
In both cases they have the problem that the wav file format says 'NIST' and it must be in 'RIFF' format. (Something about sph also I readed but the nist file I donwloaded are .wav, not .sph).
I downloaded then SOX from http://sox.sourceforge.net/
I added the path correctly to my enviromental variables so that my cmd recognize sox. But I can't really find how to use it correctly.
What I need now is a script or something to make sox change EVERY wav file format from NIST to RIFF under certain folder and subfolder.
EDIT:
in reading a WAV file from TIMIT database in python I found a response that worked for me...
Running sph2pipe -f wav input.wav output.wav
What I need is a script or something that searches under a folder, all subfolders that contain a .wav file to apply that line of code.
Since forfiles is a Windows command, here is a solution for unix.
Just cd to the upper folder and type:
find . -name '*.WAV' | parallel -P20 sox {} '{.}.wav'
You need to have installed parallel and sox though, but for Mac you can get both via brew install. Hope this helps.
Ok, I got it finally. Go to the upper folder and run this code:
forfiles /s /m *.wav /c "cmd /c sph2pipe -f wav #file #fnameRIFF.wav"
This code searches for every file and make it readble for the python libs. Hope it helps!

Resample audio file from terminal

I currently have a list of file for which I need to change the sample rate for.
I'recently been aware that this is possible using sox But when I try do it, I keep on getting a error message that sox wav: Premature EOF on .wav input file And causes the audio file to be empty.. it seems like that sox is not able to resample an audio file which input = output... which I kinda need, if I have to convert a whole directory of audio files...
Currently used commands:
~/kaldi-trunk/egs/yesno/s5_k_added$ sox 0_0_0_0_1_1_1_1.wav -r 8000 0_0_0_0_1_1_1_1.wav
sox WARN wav: Premature EOF on .wav input file
:~/kaldi-trunk/egs/yesno/s5_k_added$ play 0_0_0_0_1_1_1_1.wav
0_0_0_0_1_1_1_1.wav:
File Size: 44
Encoding: Signed PCM
Channels: 1 # 16-bit
Samplerate: 8000Hz
Replaygain: off
Duration: unknown
In:0.00% 00:00:00.00 [00:00:00.00] Out:0 [ | ] Clip:0
Done.
How do I resample a directory of audio files?
Try changing the output file name, possible putting it in a different directory if you want to keep the same file name.
For example:
sox 0_0_0_0_1_1_1_1.wav -r 8000 ./out/0_0_0_0_1_1_1_1.wav
I believe sox is attempting to read the file while it is actively changing it, sometimes sox does not create a temporary file to output into.
EDIT: If you have a directory of files you all want to change, use this:
$ mkdir out
$ for file in *; do sox ${file} -r 8000 ./out/${file}; done

Combining all the images in folder into a video

I have a script that takes tons of pictures and names them with a time-stamp. These Images are all put into one folder. I want to create a script that takes all the pictures in the folder, combines them into a 10fps video, saves this video as the date and time it started from to the time it ended, and deletes the original pictures. So far, I've seen some people use Ffmpeg or mencoder but I'm not sure how to use these or do what I want with them. Any help is appreciated! Thanks.
You can use the FFMpeg command line interface. You invoke it from the shell. Download the binary and run it by pointing it at the desired directory. %05d is simply string formatting for numbers. %05d just says pad with 4 leading zeros 0001.jpg or whatever.
# Create a directory and copy the original images there for manipulation:
mkdir temp
cp *.JPG temp/.
# Resize the images:
mogrify -resize 200x200 temp/*.JPG
# Create the morph images
convert temp/*.JPG -delay 10 -morph 5 temp/%05d.jpg
# Stitch them together into a video
ffmpeg -r 50 -qscale 2 -i temp/%05d.jpg output.mp4
from http://www.itforeveryone.co.uk/image-to-video.html

How to convert a mp3wav to uncompressed wav using sox?

how do you convert a mp3wav (a compressed wav in mp3 form) to uncompressed wav (PCM) using sox?
mp3wav sample files can be downloaded here: http://www.clayloomis.com/simsong.html
I would have thought the following would simply work:
sox file.mp3 file.wav
It may be your version of sox doesn't handle MP3 files at all. I think this happened to me with the default RPM for openSUSE recently...

Resources