Μηνιαία αρχεία: Δεκέμβριος 2014


ffmpeg: Extract audio from .MP4 to .OGG 1

If you need to extract the audio from an .MP4 movie file to an .OGG audio file you can  execute the following:

FILE="the-file-you-want-to-process.mp4";
ffmpeg -i "${FILE}" -vn -acodec libvorbis -y "${FILE%.mp4}.ogg"

The first command will assign the file name to a variable, we do this to avoid typing errors in the second command where we might want to use the same name for the audio file.

The second command, will use ffmpeg to extract the audio. The -i flag, indicates the file name of the input. We used the flag -vn that will instruct ffmpeg to disable video recording. The -acodec flag will set the output audio codec to vorbis. The -y flag will overwrite output file without asking, so be careful when you use it.

In case we want to automatically process (batch process) all .MP4 video files in a folder we can use the following:

for FILE in *.mp4;
do
    echo -e "Processing video '\e[32m$FILE\e[0m'";
    ffmpeg -i "${FILE}" -vn -acodec libvorbis -y "${FILE%.mp4}.ogg";
done

The above script will find all .MP4 files in the folder and process them one after the other.

 

UPDATE:

The following command will find all mp4 files that are in the current directory and in all sub-folders and extract the audio to ogg format.

find . -type f -iname "*.mp4" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -acodec libvorbis -y "${FILE%.mp4}.ogg";' _ '{}' \;

The filename of the audio file will be the same as the mp4 video with the correct extension. The mp4 extension will be removed and replaced by the ogg extension e.g hi.mp4 will become hi.ogg