Binary Nature where the analog and digital bits of nature connect

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 12 June 2010

Convert AC3 audio to MP3 for XviD files with FFmpeg

Posted on 17:15 by Unknown
I recently ran into an issue where I wanted to play a movie on one of my portable devices, but the file's audio stream was encoded in the AC3 (Dolby Digital) format. Of course the device doesn't support AC3, so I would need to convert it to a compatible format. MP3 was supported.

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 Medibuntu repository.

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:

OptionValueDescription
-i"/Users/marc/Movies/example_101.avi"The absolute path for the input file
-vcodeccopyForce video codec to copy our original XviD stream
-acodeclibmp3lameUse the LAME MP3 encoder for the audio stream
-ab160kThe bitrate of our MP3 audio stream
-ac2The number of audio channels
-afvolume=2.0The 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
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in FFmpeg, Linux, Mac | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Integrate VMware Fusion with GNS3 on your Mac
    At long last, we can finally integrate VMware Fusion with GNS3. VMware Workstation for Windows and Linux has had this capability for quite s...
  • Zenoss Core 4 Installation
    Zenoss Core 4 was recently released, so I thought I would document a sample installation process for it. My single server installation clo...
  • Enable sudo for RHEL and CentOS
    Sudo is an arguably safer alternative to logging in (or using the su command) to the root account. Sudo allows you to partition and delegat...
  • SSL VPN configuration on Cisco ASA with AnyConnect VPN client
    This post will describe how to setup a Cisco Adaptive Security Appliance (ASA) device to perform remote access SSL VPN with the stand-alone ...
  • Measure Internet Connection Speed from the Linux Command Line
    This is a sample solution of how to test the Internet connection speed for an Amazon Web Services (AWS) EC2 Linux instance from the command ...
  • Install and configure GNS3 with TunTap on the Mac
    [ 10/30/2013 : Post has been updated to reflect configuration with GNS3 v0.8.6 and Mac OS X 10.9 (Mavericks) ] A virtual network has many ...
  • First Post!!!
    I thought I would submit my solution for the FizzBuzz test. I've used PowerShell and VBScript for the solution since the majority of m...
  • SSH using Public-Key Authentication
    Lately, I've been implementing a solution to make SSH connections more secure and manageable (i.e., getting away from password authentic...
  • Configure an Active Directory authoritative time source
    One of the most fundamental tasks in a network is to keep the clocks on all computers (and network devices) synchronized with world time. Th...
  • PowerShell Function for Windows System Memory Statistics
    Memory is one of the four primary hardware resources an operating system manages. The other three are cpu, disk, and network. Analysis of sy...

Categories

  • AD
  • Apache
  • AWS
  • Cisco
  • Exchange
  • FFmpeg
  • GNS3
  • Linux
  • Mac
  • MariaDB
  • MySQL
  • PowerShell
  • RT
  • Security
  • SSH
  • VMware
  • Windows
  • Zenoss

Blog Archive

  • ►  2013 (8)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (3)
    • ►  December (1)
    • ►  November (1)
    • ►  April (1)
  • ►  2011 (3)
    • ►  June (1)
    • ►  May (2)
  • ▼  2010 (8)
    • ►  August (1)
    • ►  July (1)
    • ▼  June (1)
      • Convert AC3 audio to MP3 for XviD files with FFmpeg
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (3)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
Powered by Blogger.

About Me

Unknown
View my complete profile