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.
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.
Audio Physics: http://www.harmony-central.com
Audio Engineering: http://www.ee.washington.edu/conselec/CE/kuhn/audio/95x3.htm
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 firstname.lastname@example.org.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Parsing an RSS News Feed with a Bash Script
- Tech Tip: Really Simple HTTP Server with Python
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide