About the Encoder Scripting Utility Sample
The Encoder Scripting Utility Sample is a program created using Microsoft® Visual Basic®. The utility adds functionality to Windows Media Encoder that helps users more easily work with script commands. Standard common dialog box, text box, and list controls handle text and other user input. Windows Media Encoder handles the encoding of the ASF stream. Visual Basic code handles the transfer of text and control data between user interface controls and Windows Media Encoder.
Creating a Windows Media Encoder Object
In order to pass text strings and control data to Windows Media Encoder, the Encoder Scripting Utility Sample creates an instance of Windows Media Encoder using Automation. In this sample, methods exposed by Windows Media Encoder are used to load the .asd file, to start and stop encoding, and to send script commands; properties exposed by Windows Media Encoder are used primarily to populate View Properties with read-only encoding data.
The Encoder object in the custom application functions nearly the same as Windows Media Encoder does when it is opened from the executable file (Nsrex.exe). But there are differences. When created as an Automation object, the Encoder user interface is not visible. Also, Automation cannot be used to create an ASF Stream Descriptor (.asd) file, which you need to configure Windows Media Encoder. For these reasons, the sample utility or any custom application using Encoder Automation must supply its own user interface and a procedure for loading an existing .asd file.
For more information about Windows Media Encoder Automation, see the Windows Media Encoder SDK.
Monitoring the Output
A script command monitor is also included in this sample. The monitor is a simple Web page that contains a Windows Media Player control and text boxes, which are used to display script commands after they are sent. You can enhance this page easily to display more of Windows Media Player, so you can view the text and marker areas.
Expanding on this Sample
The feel of a live presentation can extend beyond the small video display of Windows Media Player when you use script commands to control elements on your Web page. The following examples show how you can extend the capabilities of the Encoder Scripting Utility Sample by modifying the Visual Basic code source included in this SDK.
- Create and edit list entries. In the Encoder Scripting Utility Sample, there is no method for creating and editing the script command list within the program. By modifying the code, simple list editing can be added. For example, a command button can be added to the interface that transfers text that the user types in the script command Type and Command boxes to the list. Another command can be added that deletes a selected list item. To implement more advanced editing control, you can replace the list control with a grid control, allowing the user to enter and edit text directly in the control.
- Step through the list. In certain live situations, it can be useful for the user to step through commands in a list one after the other rather than choose list items randomly. You can modify the code to access a list item through its index property. During runtime, a variable holding the next index number advances by one each time a script command is sent.
- Automate script commands. In a live situation, script commands are normally triggered manually, but there are situations where commands must be triggered at a particular time, or where commands must be triggered quickly in a certain order. Another list can be added to the Encoder Scripting Utility Sample that displays commands with corresponding times. When time-of-day equals a time in the list, the command is sent. Macro-like capabilities can also be added to the sample that allow users to group commands and automate common tasks. For example, you can write a procedure that changes four images on a Web page randomly with one button click. The button click can trigger the procedure, which sends four commands separated by one-second gaps.
- Create a marker list. Markers allow users to move to different parts of an on-demand .asf file, so they cannot be used in a live situation. But there are situations where a live presentation is to be archived, and an archived .asf file can contain markers. To create markers during live encoding, you can add procedures to the Encoder Scripting Utility Sample that allow users to create marker lists on the fly. When encoding stops, the marker list can then be added to the .asf file that was created concurrently with the live encoding.
When a user initiates the procedure to add a marker during a live encoding session, a dialog box opens, prompting the user to add a marker name and comments. Each entry is then added to a marker list along with a marker time. For example, while a speaker is giving a talk with slides, an assistant producer can be creating a list on the fly in the Encoder Scripting Utility Sample, adding a marker whenever a new topic begins. Script commands corresponding to slide changes in the presentation are part of the live ASF stream, and are therefore already included in the .asf file.
To add the markers to the finished .asf file, the rebuilt Encoder Scripting Utility Sample calls the ASFChop command-line utility. ASFChop is a component of Windows Media Tools that provides users with a way to perform simple editing tasks in .asf files. To add a marker list to an .asf file, the rebuilt Encoder Scripting Utility Sample first creates a script file containing the markers in the proper format, then calls ASFChop using syntax such as the following:
Asfchop –in raw.asf –out final.asf –script markers.txt
For more information on ASFChop and how to create script files, see the Windows Media Tools Documentation.
- Support multiple encoders. Many of the currently available computers are capable of supporting multiple audio and video capture cards as well as more than one instance of Windows Media Encoder. The sample can be modified to create multiple instances of Windows Media Encoder, and then manage script commands for all of them. For example, during a live rock concert, two cameras set at different angles can be encoded to separate streams with two instances of Windows Media Encoder. If the two Encoder instances are contained in the Encoder Scripting Utility Sample, each stream can receive identical script commands at exactly the same time. The viewer can choose either camera angle and receive all the script commands.
See Also
Using the Encoder Scripting Utility Sample, Windows Media Technologies Solutions Samples
© 1996-1999 Microsoft Corporation. All rights reserved.