Using Mencoder Profiles

Posted by admin on January 21, 2015 under Tech Tips | 5 Comments to Read

Your ad here was suppressed by

AdSense Now! Pro.

Score 0.52 > 0.4

Here’s a quick tip on using Mencoder profiles that serve as shortcuts for all of your favorite settings. This can save you a lot of time, especially when your encoding syntax is lengthy and difficult to remember.

Profiles are stored in the mencoder.conf file located in the appropriate place for your operating system. For Linux users, you can create a personalized file in your own home directory, ~/.mplayer/mencoder.conf.

Here’s the syntax you might use on a single-pass XviD project without using profiles.

mencoder -oac mp3lame -lameopts aq=0:q=0 -ovc xvid -xvidencopts
input.avi -o output.avi

Compare that with the following examples of some of my favorite profiles, and how easy it is to use them.

XviD Single-pass Profile Example

profile-desc="MPEG4/MP3 encoding"

mencoder -profile xvid input.avi -o output.avi

XviD 2-pass Profile Examples

Your ad here was suppressed by

AdSense Now! Pro.

Score 0.52 > 0.4

profile-desc="MPEG4/MP3 encoding - PASS 1"

profile-desc="MPEG4/MP3 encoding - PASS 2"

mencoder -profile xvid-pass1 input.avi
mencoder -profile xvid-pass2 input.avi -o output.avi

x264 2-pass Profile Examples

profile-desc="x264 encoding - PASS 1"

profile-desc="x264 encoding - PASS 2"

mencoder -profile x264-pass1 input.avi
mencoder -profile x264-pass2 input.avi -o output.avi

x264 Single-pass Profile Example

profile-desc="x264 encoding"

mencoder -profile x264 input.avi -o output.avi

Your ad here was suppressed by

AdSense Now! Pro.

Score 0.52 > 0.4

Adding Chapters to Videos Using MKV Containers

Posted by admin on November 4, 2014 under Tech Tips | 4 Comments to Read

If you would like to add chapters to your video files, such as XviD, x264, OGG, etc., simply use the Matroska multimedia container format.

For those of you that have never created Matroska files, visit the Matroska website to find the right software for your platform. If you’re using Ubuntu Linux, install the mkvtoolnix package from the repositories. It contains all the tools you need to start working with MKV files.

sudo apt-get-install mkvtoolnix

The easiest method of creating your chapter definitions is with any text editor, using the following format. Feel free to change the name and time values accordingly. Save the file anywhere you can remember, e.g. chapter.txt.

CHAPTER01NAME=Chapter 01
CHAPTER02NAME=Chapter 02
CHAPTER03NAME=Chapter 03
CHAPTER04NAME=Chapter 04
CHAPTER05NAME=Chapter 05

If you want to create a chapter file from an existing DVD, dvdxchap is a great tool for the job if you’re using Linux. It’s part of the ogmtools package. For more info, check out the OGMtools project web site.

Installation and three examples of how to use the tool are below.

sudo apt-get install ogmtools

dvdxchap /dev/dvd > chapter.txt
dvdxchap ./VIDEO_TS/ > chapter.txt
dvdxchap video.iso > chapter.txt

mkvmerge is the only tool you need to create an MKV file. In the following examples, your source video file is called video.avi, and your destination file is video.mkv.

A simplified version of the mkvmerge syntax is as follows.

mkvmerge video.avi --chapters chapter.txt -o video.mkv

I typically like to set my default language to English, and also turn off header compression for all tracks since some players don’t play nicely with compression enabled. The syntax and example output is displayed below.

mkvmerge video.avi --default-language eng
--compression -1:none --chapters chapter.txt -o video.mkv

mkvmerge v4.2.0 ('No Talking') built on Jul 28 2010 16:47:39
'video.avi': Using the AVI demultiplexer. Opening file. This may take some time depending on the file's size.
'video.avi' track 0: Using the MPEG-4 part 2 video output module.
'video.avi' track 1: Using the MPEG audio output module.
The file 'video.mkv' has been opened for writing.
'video.avi' track 0: Extracted the aspect ratio information from the MPEG4 layer 2 video data and set the display dimensions to 712/416.
Progress: 100%
The cue entries (the index) are being written...
Muxing took 30 seconds.

That’s really all there is to it. Now any media player that supports MKV chapters will allow you to navigate them. My favorites are VLC, Mplayer, and my Western Digital media player, the WD TV Live Plus.

Verify the contents of your MKV using mkvmerge or mkvinfo.

mkvmerge -i video.mkv
File 'video.mkv': container: Matroska
Track ID 1: video (V_MS/VFW/FOURCC, XVID)
Track ID 2: audio (A_MPEG/L3)
Chapters: 13 entries

mkvinfo video.mkv
+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 2
|+ Doc type read version: 2
+ Segment, size 1325519138
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4029)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v1.0.0 + libmatroska v1.0.0
| + Writing application: mkvmerge v4.2.0 ('No Talking') built on Jul 28 2010 16:47:39
| + Duration: 5004.680s (01:23:24.680)
| + Date: Thu Aug 5 00:26:03 2010 UTC
| + Segment UID: 0x81 0x4b 0xc4 0xf1 0xf4 0x5b 0x6d 0xda 0xc5 0x40 0xc1 0x03 0x3f 0x36 0x0f 0xd9
|+ Segment tracks
| + A track
| + Track number: 1
| + Track UID: 1318207700
| + Track type: video
| + Lacing flag: 0
| + MinCache: 1
| + CodecPrivate, length 40 (FourCC: XVID, 0x44495658)
| + Default duration: 40.000ms (25.000 fps for a video track)
| + Video track
| + Pixel width: 480
| + Pixel height: 416
| + Display width: 712
| + Display height: 416
| + A track
| + Track number: 2
| + Track UID: 3206714560
| + Track type: audio
| + Codec ID: A_MPEG/L3
| + Default duration: 24.000ms (41.667 fps for a video track)
| + Audio track
| + Sampling frequency: 48000
| + Channels: 2
|+ EbmlVoid (size: 1099)
|+ Chapters
| + EditionEntry
| + EditionFlagHidden: 0
| + EditionFlagDefault: 0
| + EditionUID: 585228242
| + ChapterAtom
| + ChapterUID: 4059317607
| + ChapterTimeStart: 00:00:00.000000000
| + ChapterFlagHidden: 0
| + ChapterFlagEnabled: 1
| + ChapterDisplay
| + ChapterString: Chapter 01
| + ChapterLanguage: eng
| + ChapterAtom
| + ChapterUID: 3065648262
| + ChapterTimeStart: 00:05:00.000000000
| + ChapterFlagHidden: 0
| + ChapterFlagEnabled: 1
| + ChapterDisplay
| + ChapterString: Chapter 02
| + ChapterLanguage: eng
| + ChapterAtom
| + ChapterUID: 2388361707
| + ChapterTimeStart: 00:10:00.000000000
| + ChapterFlagHidden: 0
| + ChapterFlagEnabled: 1
| + ChapterDisplay
| + ChapterString: Chapter 03
| + ChapterLanguage: eng
| + ChapterAtom
| + ChapterUID: 1448933008
| + ChapterTimeStart: 00:15:00.000000000
| + ChapterFlagHidden: 0
| + ChapterFlagEnabled: 1
| + ChapterDisplay
| + ChapterString: Chapter 04
| + ChapterLanguage: eng
| + ChapterAtom
| + ChapterUID: 1319721142
| + ChapterTimeStart: 00:20:00.000000000
| + ChapterFlagHidden: 0
| + ChapterFlagEnabled: 1
| + ChapterDisplay
| + ChapterString: Chapter 05
| + ChapterLanguage: eng
|+ EbmlVoid (size: 101)
|+ Cluster

Strip All Unwanted MP3 ID3 Tags

Posted by admin on June 20, 2014 under Tech Tips | 14 Comments to Read

A while back, I wanted to find a tool that would go through my entire collection of MP3’s and remove all the extra ID3 tags I didn’t want. For example, when I purchase music from Amazon, Rhapsody, and other online music stores, there are a number of tags in the files that track things like the purchase date and sales transaction ID’s. I also like to get rid of annoying comments and other hidden tags that most editors won’t even show you.

In my search for a tool, I came across this very useful post outlining a similar project. In the authors quest to do the same thing, he came up with a shell script that searches for all MP3 files, and removes tags that are not in his list of “good” tags. I usually don’t like to rehash the work someone else has done, but since I use his script so often, I thought it would be useful to repost it with only minor modifications.

Prerequisite: Install eyeD3

The script requires the eyeD3 tag editor to parse and manipulate the tag data. So be sure to install eyeD3, which should be available in your favorite Linux repository.

sudo apt-get install eyed3

Save and Modify Script

Save the following script as somewhere in your executable path.

# Script name:
# Original Author: Ian of DarkStarShout Blog
# Site:
# Options slightly modified to liking of
#Determine tags present:
find . -iname "*.mp3" -exec eyeD3 --no-color -v {} ; > $indexfile
tagspresent=`sort -u $indexfile | awk -F): '/^<.*$/ {print $1}' 
| uniq | awk -F)> '{print $1}' | awk -F( '{print $(NF)}' 
| awk 'BEGIN {ORS=" "} {print $0}'`
rm $indexfile
#Determine tags to strip:
tostrip=`echo -n $tagspresent $oktags $oktags 
| awk 'BEGIN {RS=" "; ORS="n"} {print $0}' | sort | uniq -u 
| awk 'BEGIN {ORS=" "} {print $0}'`
#Confirm action:
echo The following tags have been found in the mp3s:
echo $tagspresent
echo These tags are to be stripped:
echo $tostrip
echo -n Press enter to confirm, or Ctrl+C to cancel...
read dummy
#Strip 'em
stripstring=`echo $tostrip 
| awk 'BEGIN {FS="n"; RS=" "} {print "--set-text-frame=" $1 ": "}'`
# First pass copies any v1.x tags to v2.3 and strips unwanted tag data.
# Second pass removes v1.x tags, since I don't like to use them.
# Without --no-tagging-time-frame, a new unwanted tag is added.  :-)
find . -iname "*.mp3" 
-exec eyeD3 --to-v2.3 --no-tagging-time-frame $stripstring {} ; 
-exec eyeD3 --remove-v1 --no-tagging-time-frame {} ; 
echo "Script complete!"

To run the script, just execute it from the top level parent directory.

cd ~/Music/

I really didn’t change a whole lot from the original, only making slight tweaks to eyeD3 options. For example, I removed colors from the eyeD3 output when creating the first list of tags, and added a line to remove v1.x ID3 tags since I don’t like to keep them around.

Be sure to edit the list of good tags identified by the “okaytags” variable. My preferred list includes the following:


TALB - Album/Movie/Show title
APIC - Attached picture (Album Art)
TCON - Content type (Genre)
TPE1 - Lead performer(s)/Soloist(s)
TPE2 - Band/orchestra/accompaniment
TPE3 - Conductor/performer refinement
TIT2 - Title/songname/content description
TRCK - Track number/Position in set
TYER - Year
TCOM - Composer
TPOS - Part of a set


Extract AC3 Dolby Digital with FFMpeg

Posted by admin on February 21, 2013 under Tech Tips | Be the First to Comment

If you have a source video file encoded with an AC3 Dolby Digital audio stream, you can extract the audio in it’s native format using FFMpeg.

The following example shows how to identify the available audio streams of the file video.avi. Just use ffmpeg without any output options, and you can see there are two streams (0.0 and 0.1), the second is AC3 audio.

ffmpeg -i video.avi
Input #0, avi, from 'video.avi':
Duration: 01:17:57.64, start: 0.000000, bitrate: 1587 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 672x576 (snipped for brevity)
Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
At least one output file must be specified

The following command will extract the AC3 audio stream to a file called audio.ac3.

ffmpeg -i video.avi -acodec copy audio.ac3
Input #0, avi, from 'video.avi':
Duration: 01:17:57.64, start: 0.000000, bitrate: 1587 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 672x576 (snipped for brevity)
Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
Output #0, ac3, to 'audio.ac3':
Stream #0.0: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Press [q] to stop encoding
size= 255799kB time=4677.51 bitrate= 448.0kbits/s
video:0kB audio:255799kB global headers:0kB muxing overhead 0.000000%

Verify the file was created. The output below shows that this stream is about 250Mb.

ls -lh audio.ac3
-rw-r--r-- 1 username gmendoza 250M 2010-02-21 09:47 audio.ac3

You can now use ffmpeg again to show that audio.ac3 only contains the ac3 audio stream.

ffmpeg -i audio.ac3
Input #0, ac3, from 'audio.ac3':
Duration: 01:17:57.46, bitrate: 448 kb/s
Stream #0.0: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
At least one output file must be specified

Now that you have extracted the audio stream, you can do anything you wish with it. Enjoy.

DVD to XviD Encoding with Mencoder

Posted by admin on September 19, 2012 under Tech Tips | 2 Comments to Read

If you would like to copy a DVD to an XviD video file using Linux, doing so from the command line offers a number of flexibility benefits over many graphical tools. Two fantastic tools for the job are lsdvd and mencoder. I like lsdvd because it provides a great deal of information in an easy to read format, and mencoder is just a phenomenal tool for multimedia encoding.

There are some pre-requisite applications you need in order to follow along. Be sure to install mplayer, mencoder, lsdvd, lame, and if your DVD’s are encrypted, the libdvdcss2 libraries. If using Ubuntu, Debian, etc, then all are available in the repositories, except libdvdcss2 which is available in the Medibuntu repositories.

Quick XviD Encoding Examples (For the Impatient)

In the following examples, we’ll use mencoder with the most basic of options, allowing mencoder to decide which video and audio streams to use. Mencoder’s choice may not be what you want, and the audio will also be converted to a high quality VBR stereo MP3. Adjust any settings as you see fit.

Single-Pass Encoding

Fixed Quantizer Value of 4 (Good quality, decent file size)

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0
-ovc xvid -xvidencopts fixed_quant=4:autoaspect -o video.avi

Fixed Quantizer Value of 2 (High quality, larger file size)

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0
-ovc xvid -xvidencopts fixed_quant=2:autoaspect -o video.avi

Two Pass Encoding

Pass 1: (no need for audio or quality settings such as bitrate)

mencoder dvd:// -nosound -passlogfile pass1.log
-ovc xvid -xvidencopts pass=1:turbo:autoaspect -o /dev/null

Pass 2 Option 1: (VBR ~ 1500 kbps)

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log
-ovc xvid -xvidencopts pass=2:autoaspect:bitrate=1500 -o video.avi

Pass 2 Option 2: (VBR ~ Restrict final video size to 1.5 Gb)

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log
-ovc xvid -xvidencopts pass=2:autoaspect:bitrate=-1500000 -o video.avi

Basic Source Selection Examples

If you are copying a DVD directly from a physical disc as the examples throughout this post will assume, the following two examples will work. The first automatically selects title 1, and the second specifies title 2.

mencoder dvd:// (other options)
mencoder dvd://2 (other options)

If you’re encoding a DVD from an ISO or similar image file, or have the contents of a DVD extracted to directory, use the -dvd-device option as shown below.

mencoder dvd:// -dvd-device video.iso (other options)
mencoder dvd:// -dvd-device /path/to/dvd_directory/ (other options)

Basic Audio Examples

To encode the selected audio stream to a high quality VBR stereo MP3 format.

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 (other options)

If the source audio stream is encoded as AC3 or DTS 5.1 (6 Channels), you can simply copy the stream, but remember to specify 6 channels. The default is 2.

mencoder dvd:// -oac copy -channels 6 (other options)

To exclude all sound, which is useful for the first pass of a two-pass job, or if you prefer to multiplex the audio later, use the -nosound option.

mencoder dvd:// -nosound (other options)

Gathering Source Video Information for Informed Encoding Decisions

First you should identify which DVD title tracks are available, so you can determine which one you want to copy. Most DVDs will place the movie as the first track, but you may not always be that lucky. You can use lsdvd to list the number of titles, chapters, and audio tracks on your DVD.

lsdvd /dev/dvd
Disc Title: DVD_TITLE
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01
Title: 02, Length: 00:02:01.120 Chapters: 01, Cells: 01, Audio streams: 02, Subpictures: 01
Title: 03, Length: 00:02:26.120 Chapters: 01, Cells: 01, Audio streams: 02, Subpictures: 01
Longest track: 01

In the example above, we found that Title 01 is the longest at 1 hour 26 minutes, has 13 chapters and 2 audio streams.

Use lsdvd again to gather additional information about video properties of this specific title.

lsdvd -v -t 1 /dev/dvd
Disc Title: DVD_TITLE
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01
VTS: 01, TTN: 01, FPS: 25.00, Format: PAL, Aspect ratio: 4/3, Width: 720, Height: 576, DF: ?

From the output above, we see that this video is in the PAL format at 25.00 frames per second and an aspect ratio of 4/3. Use mplayer to play this title and verify it’s the one you want.

mplayer dvd://1

Gathering Source Audio Information

Use lsdvd to give you more detail on the available audio streams for the title you’re working on.

lsdvd -a -t 1 /dev/dvd
Disc Title: DVD_TITLE
Title: 01, Length: 01:26:08.200 Chapters: 13, Cells: 13, Audio streams: 02, Subpictures: 01
Audio: 1, Language: nl - Nederlands, Format: ac3, Frequency: 48000, Quantization: drc, Channels: 2, AP: 0, Content: Undefined, Stream id: 0x80
Audio: 2, Language: en - English, Format: ac3, Frequency: 48000, Quantization: drc, Channels: 2, AP: 0, Content: Undefined, Stream id: 0x81

The output above shows that there are two audio streams, both AC3 Dolby Digital, however only the second one is in English. Mencoder and mplayer allow you to specify your desired audio stream by language as shown in the following example.

mencoder dvd://1 -alang eng (other options)

If your source has multiple English streams, you can specify which particular audio ID (aid) you want. Mplayer can be used to display all available audio identifiers of a DVD. The following command is a little long but it should serve you well.

mplayer dvd://1 -identify -frames 0 -vo null 2>&1 | grep aid
audio stream: 0 format: ac3 (stereo) language: nl aid: 128.
audio stream: 1 format: ac3 (stereo) language: en aid: 129.

From the output above, the English AC3 audio stream we want is identified by aid 129. It can be specified when using mplayer and mencoder as shown below.

mencoder dvd://1 -aid 129 (other options)

Advanced Single-Pass XviD Encoding

As mentioned before, you can encode your video using a single-pass fixed quantizer mode. It may not be as efficient in size and quality as opposed to a two-pass method, but it can save some time and complexity. Here’s the more advanced encoding options I tend to use for virtually all of my XviD encoding jobs, coupled with the information we gathered from above. A fixed_quant value between 2 and 4 work very well. The lower the number the higher the quality and larger the resulting file size.

mencoder dvd://1 -alang eng -oac mp3lame -lameopts q=0:aq=0
-ovc xvid -xvidencopts fixed_quant=4:autoaspect:max_key_interval=25:
-o video.avi

I added a number of quality settings as discussed both in the mencoder man page and this useful link here.

One option that seems to lack a lot of documentation is the max_key_interval setting. It influences the seekability of the encoded video. By default, the max_key_interval is set to a value of 250, which adds an I-frame at a maximum interval of 250 frames. This equates to approximately every 10 seconds depending on the frame rate of your source video. I like to set the value to 25 which is pretty low and results in a slightly larger file, but provides a seek accuracy of about 1 second. That’s just my preference, so feel free to change it as you wish.

Advanced Two-Pass XviD Encoding

Using the same advanced XviD encoding options as above, here’s what a two pass encoding job would look like.

mencoder dvd:// -nosound -passlogfile pass1.log
-ovc xvid -xvidencopts pass=1:turbo:autoaspect:vhq=0:max_key_interval=25
-o /dev/null

mencoder dvd:// -oac mp3lame -lameopts q=0:aq=0 -passlogfile pass1.log
-ovc xvid -xvidencopts pass=2:autoaspect:max_key_interval=25:bitrate=1500:
vhq=2:bvhq=1:trellis:hq_ac:chroma_me:chroma_opt:quant_type=mpeg -o video.avi

Cropping Black Borders

If your video source has black borders, you can crop them out to reduce the overall size of your video. For example, you video may resemble the following diagram.

movie uncropped

Video with black borders



These borders can be cropped with a video filter -vf crop=w:h:x:y where w, h, x and y are the width, height, x and y coordinates. To help determine which crop values are appropriate, first play your video with mplayer using the -vf cropdetect option, and seek through the movie to bright points of the movie where the black borders are clearly visible. Dark opening scenes may give you inaccurate edge readings.

mencoder dvd:// -vf cropdetect
(snipped for brevity)
[CROP] Crop area: X: 6..711 Y: 0..575 (-vf crop=704:576:8:0).0 0
[CROP] Crop area: X: 6..711 Y: 0..575 (-vf crop=704:576:8:0).0 0
[CROP] Crop area: X: 6..711 Y: 0..575 (-vf crop=704:576:8:0).0 0
[CROP] Crop area: X: 6..711 Y: 0..575 (-vf crop=704:576:8:0).0 0
[CROP] Crop area: X: 6..711 Y: 0..575 (-vf crop=704:576:8:0).0 0

Copy the values that mplayer displays in the background terminal as the example above shows and use them like the following.

mencoder dvd:// -vf crop=704:576:8:0 (other options)


I hope this post provides you with detail that helps you with your DVD encoding endeavors. Please feel free to post your comments, questions and tips. If needed, I’ll adjust the post to include your valuable input!