Save your FREE seat for Streaming Media Connect this August. Register Now!


Computers are great at automating repetitive tasks, right? But many of us encoding professionals spend a great deal of time repeating the same actions again and again. We point-and-click to set the encoding parameters, select the input file, name the output file, start the encoding, open an FTP program, connect to the streaming media server, transfer the files, etc. There are lots of reasons to use scripts to automate the encoding and file transfer process. We'll briefly touch upon a few of those, then we'll get into some working examples you can put to use right away.

Scripting lets the computer do more of the boring tasks so you can spend your energies on the really cool stuff. Wouldn't you rather spend your time learning SMIL 2.0 than waiting for an encoding job to finish, just so you can start the next one? Scripting can also let you work faster and with fewer opportunities for mistakes. Scripting allows you to schedule daily encoding jobs that run unattended. For example, in one streaming video encoding facility I visited, all the new video content is encoded from videotape as high bit rate MPEG. Each night, scripted processes are used to create streaming files at various bit rates and formats. The process really paid off when a new and improved version of the video codec became available. The only thing the encoding staff had to do to update all of their content was to rerun the scripts with the new encoder -- a completely hands-off process.

At the heart of the scripting process is the command-line interface. Unix and Linux have their various shells, Windows has the venerable DOS prompt. You can control both RealProducerPlus 8 and Windows Media Encoder 8 from the command-line. FTP can also be run from the command-line and scripted, allowing for automated processes for distributing content to your servers. In general, these batch processes are useful mainly for encoding your streaming media files from other source files, such as AVIs or MPGs. With RealProducerPlus, however, you can also control live encoding processes with command-line scripts.

Batch Video Encoding

RealProducerPlus 8 and Windows Media Encoder 8 each provide their own command-line syntax to control the encoding process. These two tools have many features and capabilities in common. First, you have to open a command prompt. With RealProducer on Linux or Unix, simply open a shell and navigate to the directory where you installed RealProducer. On Windows systems, you can do this by clicking the Start menu, selecting Programs->Accessories->Command Prompt. You can navigate to your media encoder directory by typing 'cd c:\program files\real\realproducerplus' or 'cd c:\program files\windows media components\tools' ('cd' stands for 'change directory'). With both tools, you can specify input and output file names, encoding parameters such as bit rate, codec, frame rate, and others. Here's a sample command for encoding a single .avi file to streaming format: -- RealProducerPlus --

RMBatch /I C:\videos\foo.avi /O C:\videos_coded\foo.rm /T 0,1 /A 0 /V 0 /F 1 /B "My Clip"

This will encode the input file [/I c:\videos\foo.avi] into an output file [/O C:\videos\foo.rm]. The other switches on the line set parameters for target audience (/T) (from the profiles included in the GUI version of the tool), video (/V) and audio (/A) quality, and the clip title (/B). The target audience numbers refer to the player bandwidth settings listed below:

Target Audience:

0 - 28 Kbps Modems
1 - 56 Kbps Modems
2 - Single ISDN
3 - Dual ISDN
4 - DSL/Cable Modem
5 - Corporate LAN
6 - 256K DSL/Cable Modem
7 - 384K DSL/Cable Modem
8 - 512K DSL/Cable Modem

To create a SureStream file that smoothly scales bandwidth between various connection speeds, we specified multiple target audiences, along with the '/F 1' switch. Click here for full documentation of the command-line options(scroll down to Section 7 and click 'RMBatch'). Or, to display a quick command reference [Click Here to View Quick Command References], just type 'RMBatch' at the command prompt.

-- WME8 --

wm8eutil -input c:\videos\foo.avi -output c:\videos_coded\foo.wmv -profile av100 -title "My Clip"

This one encodes the same video into .wmv format. The -profile references one of the preset encoding configurations included with WME8. The preset profiles describe the bitrate, size, codec, and other adjustable encoding parameters. To view the full command-line documentation installed with WME8, type 'wm8eutil -help?' at the command prompt.

Encoding Entire Directories

Both tools also offer the ability to encode entire directories of files with a single command.

-- RealProducerPlus --

RMBatch /D C:\videos\ /O C:\videos_coded\ /T 0,4 /A 0 /V 0 /F 1 /B "My Clip"

Here, we've used '/D directoryname' in place of '/I filename' to encode all the files in the directory. The /O switch specifies the output directory.

-- WME8 --

wm8eutil -input c:\videos\ -output c:\videos_coded\ -profile av100 -title "My Clip"

Here, we've specified a directory name after the '-input' switch. WME8 will encode all the video and audio files in that directory to the directory named after the '-output' switch.

Encoder Configuration Files

With both RealProducerPlus and WME8, you can specify dozens of settings in the command. If you have a few groups of settings used often, you can create configuration files that can be called from the command-line. WME8 actually has slightly greater flexibility than RealProducerPlus 8.51 in this area. Here are the contents of an example configuration file for WME8. It's a plain text file you can create with Notepad or any text editor. We'll name it broadband_settings.weu:

-input c:\videos\
-output c:\videos_coded\
-a_setting 48_44_2
-v_bitrate 350000
-v_codec WMV8
-title "My Clip"

Now our encoding command would look like this:

wm8eutil -config broadband_settings.weu

With RealProducerPlus 8, we can also create our own encoding profile. The profile can contain only a subset of the encoding parameters. Specifically, we can redefine the codec, frame rate and bit rate parameters for our target audiences. Here's a sample profile for RealProducerPlus, which we'll save as broadband_settings.txt:


We'll use the '/M' switch to tell RealProducerPlus which profile file to use. Now our encoding command would look like this:

RMBatch /I C:\videos\foo.avi /O C:\videos_coded\foo.rm /M broadband_settings.txt /V 0 /F 1 /B "My Clip" Batch Jobs

Suppose we want to create both RealMedia and WindowsMedia versions of all the files in our 'c:\videos' directory. We'll write a simple batch file that will run the encoder commands for us. The simplest kind of DOS batch file (.BAT) or Unix shell script (.sh, .csh, etc) contains a simple list of the commands you want to run. So, our batch file to encode both sets of media files would look like this:

# you can use the '#' sign on Unix or 'REM' on Windows to begin comment lines
# begin batch file encoding
RMBatch /D C:\videos\ /O C:\videos_coded\ /T 0,4 /A 0 /V 0 /F 1 /B "My Clip"
wm8eutil -input c:\videos\ -output c:\videos_coded\ -profile av100 -title "My Clip"
# end encoding

Simply save this file as encode_both_formats.bat. Now you can double-click it, start it from the command line, or start it with a scheduler like cron or the Windows Scheduled Tasks utility. The commands listed will run one after another until the last command finishes.

Scripted file transfer

So, now we've created all of these video files. It sure would be nice to move them to our media servers automatically, too. Well, the command-line comes to the rescue again. Windows and Linux/Unix systems include a command-line version of an ftp (file transfer protocol) client. Naturally, this can be scripted, too. Lets look at the commands it would take to move all of our RealMedia files to our server. From a command prompt (and this is essentially the same in Windows or Unix), simply type 'ftp -i'. From here, we'd follow the following sequence of steps:

open myrealserver.mydomain.com # open a connection to the server
myusername # login with username/password at the promptsmypassword
bin # switch to binary mode transfer since we're not transferring text files
lcd c:\videos_coded # change directory on the local system to where our encoded videos live
cd /the/path/to/my/video/directory/ontheserver # change directory on the server to where videos are served from
mput *.rm # transfer the .rm files (mput means "put multiple files")
quit # we're done

To run this as a script on Windows, simply save the above command sequence as a text file. For this example, we'll call it real_transfer.ftp. Now from the command line, we can type 'ftp -i -s:video_transfer.ftp' and the entire sequence will run itself. We'll create another ftp file for the transfer to our Windows Media Server. Now we place the ftp commands at the end of our encoding batch file like this:

# begin batch file encoding
RMBatch /D C:\videos\ /O C:\videos_coded\ /T 0,4 /A 0 /V 0 /F 1 /B "My Clip"
wm8eutil -input c:\videos\ -output c:\videos_coded\ -profile av100 -title "My Clip"
# end encoding, now transfer the files
ftp -i -s:real_transfer.ftp
ftp -i -s:wm_transfer.ftp
# done transferring files

Scripting ftp on Unix is slightly different. A Unix shell script for the above example looks like this:

#!/usr/bin/sh ftp -in <
user myusername mypassword # login with username/password
bin # switch to binary mode transfer since we're not transferring text files
lcd /videos_coded #change directory on the local system to where our encoded videos live
cd /the/path/to/my/video/directory/ontheserver # change directory on the server to where videos are served from
mput *.rm # transfer the .rm files (mput means "put multiple files" quit # we're done

Scripted encoding does have a downside. A video compression specialist will be quick to point out that the highest quality encodings require careful analysis of the source material, painstaking attention to detail, and good judgment. If you automate this process, you'll sacrifice individual attention to each video. You'll have to decide if that's a problem for your particular business model and content.

So now you've learned how to take advantage of the command-line capabilities of the major video encoders. You've set up scripts that will help you achieve a more scalable and efficient encoding process. The only remaining question is; what in the world will you do with all the free time you've gained?

Interested in this topic? Check out the Streaming Media Europe 2001 Technology conference track!

Streaming Covers
for qualified subscribers
Subscribe Now Current Issue Past Issues