how can I convert all of the mp4 files in a given folder to mp3 using ffmpeg.
Almost all of the links I have seen on google is all about converting mp4 video to mp3.
I can do this via VLC player but I have got huge collection ~ 1000 mp4 audio files and want this to be done over command line by some script or command.
Is it possible to do it via gstreamer?
Asked
Active
Viewed 2.3k times
25
Raulp
- 7,758
- 20
- 93
- 155
-
Are they all in the same directory? – llogan Jul 19 '16 at 15:59
-
Yes.Any way I found the way by calling the ffmpeg.exe using a C# code and using Linq and iterating over each file. – Raulp Jul 20 '16 at 04:14
2 Answers
40
One method is a bash for loop.
For converting only .mp4 files:
mkdir outputs
for f in *.mp4; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.mp4}.mp3"; done
For converting .m4a, .mov, and .flac:
mkdir outputs
for f in *.{m4a,mov,flac}; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.*}.mp3"; done
For converting anything use the "*" wildcard:
mkdir outputs
for f in *; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.*}.mp3"; done
llogan
- 121,796
- 28
- 232
- 243
-
what if I have to extend the above script for more different number of files ( like .m4a,.mov etc) Like I did : FileInfo[] Files = d.GetFiles("*.mp4").Union(d.GetFiles("*.
")).ToArray(); . – Raulp Jul 21 '16 at 05:59
3
FileInfo[] Files = d.GetFiles("*.mp4").Union(d.GetFiles("*.<any other file extension>")).ToArray();
foreach (FileInfo file in Files)
{
// str = str + ", " + file.Name;
builder.Append(Path.GetFileNameWithoutExtension(file.Name));
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "ffmpeg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = !string.IsNullOrEmpty("test");
startInfo.Arguments = "-i " + filename + ".mp4 -q:a 0 -map a " + filename + ".mp3";
}
Raulp
- 7,758
- 20
- 93
- 155