Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting all the mp4 audio files in a folder to mp3 using ffmpeg [duplicate]

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?

like image 726
Raulp Avatar asked Jul 19 '16 03:07

Raulp


People also ask

Can FFmpeg convert to MP3?

FFmpeg can be used to convert a huge WAV file into a tiny MP3 file that allows the user to listen to the same song but downloading just a portion of the original size of the WAV file.

Can FFmpeg convert MP4 to MP3?

In this example, we are going to use ffmpeg to convert MP4 to MP3. FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. A stream specifier can match several stream, the option is then applied to all of them.


2 Answers

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";

}
like image 27
Raulp Avatar answered Oct 22 '22 13:10

Raulp


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
like image 75
llogan Avatar answered Oct 22 '22 11:10

llogan