Powerful Multimedia Command-Line Tools, Part II—Transcode
MEncoder has supported video encoding for a long time with the MPlayer Project and FFmpeg, which also now is part of MPlayer. Transcode is a new command-line tool on the horizon for video and audio transformations. Transcode used to give me horrors, but it is much better now. It does take some time to learn its wonderfully unintuitive syntax—the author used all the lowercase and uppercase English alphabet letters for specifying the command-line options. Using longer mnemonic options common in other Linux commands might have made things easier. Anyway, let's get to the meat of the matter.
You can apply certain video filters to smooth, blur, enhance, add or remove logos, apply masks and so on with Transcode. But before we get to all of that, here's a piece of advice from the trenches. Do the following:
$ tcmodinfo -p
Then, go to the directory and see what import modules, export modules and filters came with your Transcode program. Mine did not contain several export modules, and a few filters were missing.
Transcode's error reporting is not very user-friendly. You need to look at the output carefully to figure out whether Transcode understood a certain command switch. Sometimes it hangs, and occasionally it tells you what went wrong on the command line. So, you need to take some time to gain familiarity with using the commands.
Another problem with Transcode is that it supports a huge list of options, so you'll want to do some memorizing. Keep the man page open and make sure you don't miss anything. Once you find a combination that works, you're all set. Some of the most important switches are -x, -y, -J, -i and -o.
The -x and -y switches are for specifying the import and export modules, respectively. Depending on the input/output video/audio formats, you may need to change them. Use the tcprobe tool that comes with Transcode to figure out whether a particular audio or video input is autoprobed by Transcode. If tcprobe is happy with it, you can skip the -x option.
The -J option is the most versatile. It is the filer option, and you use it to specify the filter chain. All video preprocessing and postprocessing is performed with this switch.
The -i and -o options are for video input and output files. Either or both of them could be /dev/null. There also are switches for specifying an external audio file as input (-p) and for dumping the resulting audio after processing to a separate file (-m). You can do a lot of tweaking and add a great deal of filtering subsystems into the chain. Transcode is a young program, and I expect many more filters will be added.
Transcode Commands
It is odd that Transcode supports all kinds of imaginable input and export modules. Its notion of what constitutes a video is very broad. It can take images from the ImageMagick library; it can do audio-only processing; it can take sound files as audio input for the video and redirect the output audio to a different file and so on.
I tested a long list of commands to get an idea of what it could do. Once I figured out the basics, the rest was smooth sailing.
The following is a command to cull out the audio from video.mpg:
$ transcode -i /home/girish/video.mpg -x mpeg2 -y null,ogg -J aclip,resample -m /tmp/foo.ogg -E 22050
I don't have the MP3 export module, so I encoded it into Ogg Vorbis format. The -E 22050 switch specifies the output sample rate. You also can specify the bits per sample and the number of output channels with the same switch.
This next command saves the output audio in AC3 format after resampling to 48,000Hz as per AC3 standard. The -J resample filter option is necessary but is invoked internally by Transcode:
$ transcode -i /home/girish/videos/video.mpg -x mpeg2 -E 48000 -y null,ac3 -m /tmp/foo
The following line dumps the video frames in motion JPEG format along with the audio processing as above:
$ transcode -i /home/girish/videos/video.mpg -x mpeg2 -E 48000 -y mjpeg,ac3 -J aclip,resample -m /tmp/foo -o /tmp/fop.mjpeg
This line dumps the video frames into separate ppm files in the /tmp directory with the prefix ppm:
$ transcode -i /home/girish/videos/video.mpg -x mpeg2 -E 48000 -y ppm,ac3 -m /tmp/foo -o /tmp/ppm
This line does the same but in JPEG format:
$ transcode -i /home/girish/videos/video.mpg -x mpeg2 -E 48000 -y jpeg,ac3 -m /tmp/foo -o /tmp/foo
There also is support for PNG, but I do not have the export module in my transcode install.
Figure 1. Transcode Architecture
DVDs contain videos in a VOB container format that can consist of several audio and video streams, as well as subtitle files, and all are organized into chapters. Transcode can understand DVD titles with the -T switch. There are many on-line resources with further information on DVD handling.
Let's get back to our examples. The following line does the same as the last example command but ignores the audio:
$ transcode -i /home/girish/videos/video.mpg -x vob -y jpg -o /tmp/foo
Note that transcode can use external commands, like ffmpeg or oggenc, for its processing, and you can observe what is going on in the output.
Transcode uses the ANSI terminal color sequences effectively, and you can turn that on or off with a command-line switch. There also are several other switches for exporting a particular profile or aspect ratio. DVD profiles are well supported, by which you can short-circuit some of the other options. There also are switches for flipping, taking a color negative, mirroring and so on.
This command inverts the video colors to take a color negative:
$ transcode -i /home/girish/videos/video.mpg -x vob -y mjpeg,ogg -J invert -o /tmp/foo.mjpeg -m /tmp/foo.ogg
The -J invert filter does this magic. The filtering subsystem is Transcode's most powerful component; take particular note of its power and usage.
The following is an example of applying a huge filter chain. It demonstrates the power of the Linux command line and also the architecture of Transcode that can handle such a filter chain:
$ transcode -i /home/girish/videos/video.mpg -x vob, -y mjpeg, -J mask=lefttop=0x0:rightbot=500x500,msharpen=strength=205:threshold=20,nored,normalize=smooth=0.2,pp=hb/vb/dr/al-o /tmp/foo.mjpeg
Don't be scared by the length. It is simple once you break it down. Most of the switches should be familiar; only the -J switch is so lengthy.
In the above example, first I apply the mask filter. It picks out portions of the video and ignores the rest. I specified rectangular coordinates for masking. I get a square of 500x500 pixels starting at the top-left corner of the screen. The msharpen filter is one of Transcode's sharpening filters. I tweak the algorithm by specifying the threshold and strength of sharpening. The nored and normalize filters remove red components and normalize the audio, respectively.
You can mix audio and video filters in the same chain. The pp filter does the same thing as MPlayer's postprocessing filter subsystem. Here I am using the same options as given in MPlayer's man page section for pp. It does horizontal and vertical deblocking, deringing and automatic brightness/contrast correction.
When dealing with such a long filter chain, observe the effect of each filter before arriving at something as complex as the above.
This example demonstrates the unsharp filter, which is similar to MPlayer's filter of the same name:
$ transcode -i /home/girish/videos/video.mpg -x vob, -y mjpeg, -J unsharp=amount=-1.5:luma=0.6:matrix=7x7 -o /tmp/foo.mjpeg
And, this command is cool:
$ transcode -i /home/girish/videos/video.mpg -x vob, -y mjpeg, -J text=string='transcode is cool':posdef=2:font=/home/girish/.ttffonts/comicbd.ttf -o /tmp/foo.mjpeg
As shown above, you can add text to a video at any position indicated by the pos coordinates or the posdef predefined locations. Transcode also can render ppml subtitles and play with DVD subtitles.
Because I did not have certain filters and modules, I couldn't try much more. But that's something you can fix by compiling Transcode yourself. As you can see here, Transcode is powerful stuff, but it can be unfriendly to beginners. Once you get a firm grip on its power, you can blow the top off GUI tools and commercial alternatives that come with a huge price tag.
Resources
Audio Physics: http://www.harmony-central.com
Audio Engineering: http://www.ee.washington.edu/conselec/CE/kuhn/audio/95x3.htm
HRTF: http://sound.media.mit.edu/KEMAR.html
Transcode: http://www.transcoding.org
See part I of this article HERE.
Girish Venkatachalam is an open-source hacker deeply interested in UNIX. In his free time, he likes to cook vegetarian dishes and actually eat them. He can be contacted at girish1729@gmail.com.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



2 hours 27 min ago
2 hours 45 min ago
4 hours 38 min ago
6 hours 31 min ago
13 hours 25 min ago
13 hours 41 min ago
15 hours 33 min ago
21 hours 25 min ago
1 day 1 hour ago
1 day 1 hour ago