Bash – avconv, converting files mp3 to ogg and vice versa.
Home page Ubuntu C++ Hardware HTML i javascript Java Software SQL

Bash – avconv, converting files mp3 to ogg and vice versa.

Added: 2012-06-16

Are many programs to conversion file audio and video, good tool for terminal is avconv, in past of ffmpeg. Documentation of avconv.

If you want to use avconv, and you do not have it in system, install it by typing command:

sudo apt-get install avconv

In case of conversion ogg to mp3, you can have problem with not existing codecs. These codecs are not installed by default because, they have not compatible license with Ubuntu License Policy. On this page restricted formats, you can read, why that packages are not installed default.

You can install that package by typing command:

sudo apt-get install ubuntu-restricted-extras

Below is script, who performs the conversion of files mp3 to ogg and vice versa. Script must be in folder where are files to convert. The script requires a single parameter.

drukowanie kodu zaznaczanie kodu

#!/bin/bash

echo "The script convert mp3->ogg or ogg->mp3.";
echo "The script takes one parameter: ";
echo "[mp3ogg] - converting mp3->ogg";
echo "[oggmp3] - converting ogg->mp3";


if [ "$1" = "" ]; then
	echo "";
	echo "Argument does not exist!!!";
	exit 102;
fi


if [ "$1" = "mp3ogg" ]; then
	for file in *.mp3; do
		 avconv -i "$file" "`echo ${file%.mp3}.ogg`";
	done
	exit 0;
fi

if [ "$1" = "oggmp3" ]; then
	for file in *.ogg; do
		 avconv -i "$file" -acodec libmp3lame "`echo ${file%.ogg}.mp3`";
	done
	exit 0;
fi


exit 104;