Handbrake is usually my "go-to" tool for a media file conversion, but it no longer supports output to XviD (or more specifically, the AVI container). I could convert the whole file, but I was looking for a way to just transcode the audio and leave the XviD video stream intact. This is ideal because transcoding video is the most time consuming operation of the media file conversion process. Knowing that Handbrake leverages FFmpeg, I decided to do some research to see if it could solve my problem. It looks like I found a solution considering the title of this post. :-) Alright, let's get started.
Get and Install FFmpeg
# Mac OS X
Install MacPorts if needed. Visit http://www.macports.org for all the details.
Sync your local ports tree with the global MacPorts ports repository to be sure you have the latest and greatest. Run this command from Terminal.app:
$ sudo port -d selfupdate
Now let's grab the FFmpeg port source and compile. This will also grab the required dependency packages like LAME, XviD, x264, etc. if you don't already have them installed. Run this command from Terminal.app:
$ sudo port -v install ffmpeg
# Ubuntu
The FFmpeg package included in the default repository is somewhat restricted, so we will grab our FFmpeg package from the
Refer to Compile FFmpeg on Ubuntu, Debian, or Mint for the latest information of how to install FFmpeg on Ubuntu.
# Fedora
Fedora does not include the FFmpeg package in the default repositories. Like Ubuntu, we will have to configure a third party repo for our distribution. I will use the ATrpms repository in this example.
Import the ATrpms' public signing key. We will need to execute the following instructions under the root account. Run this command from the terminal:
$ su -
# rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
Create and add the atrpms.repo file to the /etc/yum.repos.d directory. Run this command from the terminal:
# vim /etc/yum.repos.d/atrpms.repo
Add the following information to the file:
[atrpms]
name=Fedora Core $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/f$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
Save the file and exit Vim.
:wq
We are finally ready to grab FFmpeg and the dependency packages. Run this command from the terminal:
# yum install ffmpeg
Unleash FFmpeg
This is a snapshot of the original file's attributes before conversion.
We will now execute the FFmpeg command with all the required options and arguments.
$ ffmpeg -i "/Users/marc/Movies/example_101.avi" -vcodec copy \
-acodec libmp3lame -ab 160k -ac 2 -af volume=2.0 \
"/Users/marc/Movies/example_101_mod.avi"
Dissection of our FFmpeg command syntax:
| Option | Value | Description |
|---|---|---|
| -i | "/Users/marc/Movies/example_101.avi" | The absolute path for the input file |
| -vcodec | copy | Force video codec to copy our original XviD stream |
| -acodec | libmp3lame | Use the LAME MP3 encoder for the audio stream |
| -ab | 160k | The bitrate of our MP3 audio stream |
| -ac | 2 | The number of audio channels |
| -af | volume=2.0 | The volume of the audio stream |
| "/Users/marc/Movies/example_101_mod.avi" | The absolute path for the output file |
This is how it should look if FFmpeg was able to successfully convert the file.
Let's take this a step further and automate the conversion process for a directory of files. I created a shell script that takes a source directory and target directory as arguments.
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 | #!/usr/bin/env bash# convert-xvid-audio - Converts AC3 audio stream to MP3 for XviD files # Set a value for the audio quality and volumeBITRATE=160 # 128,160,192,224,256,320VOLUME='volume=2.0' # The default is 1.0 (examples: 0.5,1.5,2.0) if [ -d "$1" ] && [ -d "$2" ]; then find "$1" -type f -maxdepth 1 -iname '*.avi' | sed 's:.*/::' | while read FN do ffmpeg -i "$1"/"$FN" -vcodec copy -acodec libmp3lame \ -ab ${BITRATE}k -ac 2 -af $VOLUME \ "$2"/"${FN%.*}_mod.avi" < /dev/null; done exit 0else echo "usage: $(basename $0) source_directory target_directory" >&2 exit 1fi |
Save the script as convert-xvid-audio.sh.
Give the script the execute permission.
$ chmod u+x convert-xvid-audio.sh
Run the script. The following command will process all the orignal XviD files in FolderY and output them to FolderZ after the conversion.
$ ./convert-xvid-audio.sh ~/Movies/FolderY ~/Movies/FolderZ
0 comments:
Post a Comment