4 Running the SunVideo Demonstration Program





The SunVideo release includes a compiled demonstration program that provides a simple window interface to many of the SunVideo subsystem's features. You can use this program (SunVideo) to capture, compress, and display video images on 8-bit or 24-bit displays [2]) and to record and play back audio. (The source code for the SunVideo demonstration software is not included in this release of the software.)

From the window interface, you can select the input port and type of compression and choose whether you want to display an image or save it to a file.

Starting the SunVideo Demonstration Program

Take the following steps to start the SunVideo demonstration program.

    1. Connect a video source to one of the SunVideo card's input ports.
    2. Go to a directory to which you have write access.

    For example:

    % cd /home/video_files

    3. Type the following command:

    % /opt/SUNWits/Graphics-sw/xil/examples/test/SunVideo

The demonstration program's main and parameters windows are displayed (Figure 4-1).

    Figure 4-1 SunVideo Tool Startup Windows

The Main Window

The demonstration program's main window displays the initial (default) parameters. This window has two modes: capture and playback. These two modes are described in the examples in this chapter.

You can record or play back audio by selecting the Audio checkbox. To adjust the volume of audio, move the slider up and down. Up makes the audio louder.

The Audio Options Window

When you click SELECT on the + button at the bottom of the slider in the main window, the Audio Options window appears (Figure 4-2)

.

    Figure 4-2 SunVideo Audio Options

The Audio Options window displays the default settings for the following choices:

The initial settings for Output and Input may be different than the default settings. The initial settings depend on the current audio device settings when the SunVideo demonstration program is started, and the current audio device settings depend on other audio-related applications, such as audiotool, or a previous invocation of the SunVideo demonstration program. For Active when, the default and initial settings are the same.

Click the MENU button on the menus to display and make selections (Table 4-2).

    Table 4-1 SunVideo Audio Options

-----------------------------------------------------------------
Menu Choices Default -----------------------------------------------------------------
                                                       
Output       Type of output: speaker, headphone, or    Speaker
             line out.                                             
                                                       
Input        Type of input: microphone or line in.     Microphone
                                                       
Active when  Determine when the audio is heard:        Always
             always or when the cursor is in the                   
             display window (Pointed At).                          

-----------------------------------------------------------------

Capture Parameters Window

The Capture Parameters window shows the initial (default) parameters. Click the MENU button on the menus to display and make selections (Table 4-2).

    Table 4-2 SunVideo Capture Parameters

----------------------------------------------------------------------------------
Menu Choices Default ----------------------------------------------------------------------------------
                                                          
Board Select  Device names for the SunVideo cards         /dev/rtvc0
              that the demonstration program detects.                               
                                                          
Source        Several image sizes, adjusted for NTSC      320x240 for NTSC, 
              and PAL.                                    384x288 for PAL1
                                                          
Input         The SunVideo card's input ports: Port 1,    Port 1
              Port 2, or the S-Video port.                                          
                                                          
Mode          Type of compression: Direct (no             Direct
              compression), GrayScale (luminance                                    
              only), CellB, JPEG, MPEG-1, or UYVY                                   
              compression.                                                          
                                                          
Frames/Sec    Several frame rates, adjusted for NTSC      30 fps for NTSC, 25 fps 
              and PAL.                                    for PAL

----------------------------------------------------------------------------------
1. MPEG-1 constant bit rate produces an image size of 320 x 240 for PAL.

The Format line displays either NTSC or PAL, depending on what type of device is connected to the port you have selected. If the SunVideo card cannot detect a video signal, the Format line displays UNKNOWN. In this case, the active video device is probably connected to one of the other ports, and you can change the port selection in the Input menu. Or, you may have more than one SunVideo card in your system. In this case, make sure that you've selected the correct card in the Board Select menu.

Displaying Video from a Video Device

To display video from a video device (such as a video camera or VCR):

    1. Check that the Video Source selection on the main window is set to Capture.

    If the Video Source is set to File, press MENU on Video Source and select Capture.

    2. Check to see that the parameters in the Capture Parameters window are set correctly for your particular configuration.

    Click MENU on the menus to see the available options.

    For example, make sure that the Input is set to the port to which you've connected the active video source. To display an image without compression, select the Mode menu's Direct option.

    3. Click SELECT on the main window's Play button to start displaying the image.

    Figure 4-3 shows an example of a display window. The display window shows the compression type (Direct, in this example) and the display size. You can close and open the display window by clicking SELECT on the Monitor button.

    As the image is displayed, information about video throughput, bits/pixel, and frame rate appears in the main window. The throughput and frame rate will vary as other programs share the system's resources.

    Figure 4-3 Example Video Image

    4. To stop displaying video, click SELECT on the Stop button.

Recording Video and Audio

You can capture a single video frame and store it as a 24-bit RGB or 8-bit grayscale Sun raster file. Or, you can capture and store compressed images into a file (as a movie).

You can record audio along with video; the audio is stored in a separate file as discussed later.

Storing a Frame to a Sun Raster File

To store a video frame as a Sun raster file:

    1. In the Capture Parameters window, press MENU on Mode and drag the mouse to select the Direct or GrayScale choice.

    The File button in the main window changes to Raster File (Figure 4-4).

    Figure 4-4 Setup to Capture a Sun Raster File

    2. Specify a file into which to store the image.

    There are two ways to do this:

      a. In the main window, click SELECT on the Raster File button to display the ControlWindow:Save As window.

      In this window, enter the path and filename of the file into which you want to store the Sun raster image. Click OK.

      b. Or, enter the path and filename into the Raster File field and press Return.

Note - You don't need to supply the conventional .rs extension for the filename; the program appends the .rs extension for you.

    3. In the main window, click SELECT on the Rec button.

    The current frame is captured and stored into the file as a 24-bit RGB or 8-bit grayscale rasterfile.

Capturing and Storing a Compressed Movie

Note - Even compressed movie files can become large. Therefore, make sure that the filesystem into which you are going to store a movie has adequate space.

To store a compressed video sequence into a file:

    1. In the Capture Parameters window, press MENU on Mode and drag the mouse to select a compression type.

    The File button in the main window changes to Record File (Figure 4-5).

    Figure 4-5 Setup to Capture a Movie

    If you select either JPEG or MPEG-1 compression, a parameters window appears (Figure 4-6) that enables you to change various quality attributes.

    The JPEG Parameters window contains two quality sliders, one for compression and one for decompression. The compression quality slider determines the JPEG CIS attribute QUANTIZATION_TABLE (see Jpeg(3) man page). When the slider is at the midpoint (the default), the quantization table values are set to their default values as given in Annex K of the ANSI JPEG specification. When you move the slider to the far left, the lowest compression quality is chosen and all quantization values are set to 255. When you move the slider to the far right, the highest compression quality is chosen and all quantization values are set to 8. For other points in the slider's range, the quantization table values are linearly interpolated over the left and right half of the slider range.

    The decompression quality slider determines the setting of the JPEG CIS attribute DECOMPRESSION_QUALITY (see Jpeg(3) man page) that ranges from 1 to 100 (the default).

    Also, in the JPEG Parameters window there is a Default Quality button that resets both sliders to their default settings.

    The MPEG-1 Parameters window has a quality slider and two menus. The Bit Rate menu enables you to select variable or constant bit rate. When you choose variable bit rate, the quality slider determines the value of the SunVideo device attribute MPEG_FIXED_QUANT (see the section "MPEG_FIXED_QUANT" in Chapter 9). When you choose constant bit rate, the quality slider determines the value of the MPEG-1 CIS attribute COMPRESSOR_BITS_PER_SECOND (see Mpeg1(3) man page).

    The Pattern menu determines the value of the MPEG-1 CIS attribute COMPRESSOR_PATTERN (see Mpeg1(3) man page). For variable bit rate, the only menu choice is I (a pattern of all I frames).

    Figure 4-6 JPEG and MPEG-1 Quality Windows

    2. Specify a file into which to store the movie.

    There are two ways to do this:

      a. In the main window, click SELECT on the Record File button to display the ControlWindow:Save As window.

      In this window, enter the path and filename of the file into which you want to store the compressed movie. Click OK.

      b. Or, enter the path and filename into the Record File field and press Return.

Note - When you store a movie, the SunVideo demonstration program actually creates two or three files (depending on whether you recorded audio with the video), by appending extensions to the filename in the Record File field.

The compressed bitstream is placed into a file with an extension that corresponds to the type of compression (.Jpeg, .Mpeg1, .CellB, or .UYVY). These files contain exactly the compressed bitstreams; the SunVideo demonstration program adds no additional information to the bitstream.

The file with the .VCR extension is an ASCII header file that contains the number of frames in the movie along with width and height information. The format of the .VCR header file was not meant to be a standard; it was designed for use with the SunVideo demonstration program. An example .VCR file is shown at the end of this section (page 33).

Audio is placed into a file with an .au extension.

    3. In the main window, specify the number of frames that you want to capture by editing the number to the right of the slider.

    Be sure to press Return at the end of the field. The default is 1000 frames (Figure 4-7).

    Figure 4-7 Setup for Capturing a Compressed Movie

    4. Click SELECT on the Rec button.

    The number of frames that you specified are captured, compressed, and stored into the file. The slider in the main window shows the progress of the capture/compression operation.

    You can click the Stop button at any time to stop the capture/compression operation.

Notes on Capturing Audio in the SunVideo Demonstration Program

For audio to be synchronized with video on playback in the SunVideo demonstration program, it is important that video be captured at a constant rate. This is important because the demonstration program does not create or save time codes for the audio or individual video frames during recording. Therefore, there is no high level or system level timing information that instructs a playback utility on how to synchronize a section of audio with a section of video. For example, no mechanism exists to define that some sections of video were captured at one rate and others sections at a lower rate. If such video is played back at a constant rate, the sections recorded at a slower rate play back too fast. Under these circumstances synchronization of audio and video is impossible. Only if video is recorded at a constant rate will audio and video be synchronized during playback with the SunVideo demonstration program.

If video is not recorded at a constant rate, the SunVideo demonstration program sets the playback frame rate in the .VCR file to the average frame rate. During audio and video playback, the setting of an average frame rate aligns audio and video so that they start and finish at the same time but no guarantee is made about continuous synchronization. Some portions may be synchronized while others are not.

For tips on how to capture video at a constant rate, see the section "Capturing Video at a Constant Rate" on page 102.

Example .VCR File

The following example shows a typical .VCR file that is produced when audio is enabled during recording. If audio is not enabled during recording, no AUDIO section will exist in the file.

-------------------------
VCR AUDIO fps = 30.0 offset=0 name=/tmp/mymovie.au END VIDEO type = CellB frames = 500 fps=0 Width= 320 Height= 240 name=/tmp/mymovie.CellB END END -------------------------

Notice in this example file both the AUDIO section and VIDEO section have
fps = entries. When playing back video with audio turned on, the value of audio fps is used to control how fast video is played back to synchronize the video with the audio. If no fps = line exists in the AUDIO section, the value for the audio fps defaults to the value of the video fps if that value is not zero. If that value is zero, the audio fps defaults to 30.

When playing back video with audio turned off, video is played back at the rate specified by the video fps value. If this value is 0, video is played back as fast as possible.

The audio offset is the amount of audio to skip before starting audio play back at frame 0. This value, n, is the amount of audio in n video frames at the given audio fps rate. For example, if your audio is initially out of synchronization and lags the video by 22 video frames, the audio offset should be set to 22. The audio offset cannot be set to a negative number.

Playing Back a Movie from a File

You can play back a movie by using the windows interface or from the command line. To play back a movie using the windows interface:

    1. Click SELECT on the Video Source menu in the main window and drag the mouse to select the File choice.

    The mode of the main window changes to the playback window (Figure 4-8).

    Figure 4-8 Playback Window

    2. In the main window, click MENU on the Load button to display the ControlWindow:Open window.
    3. In the ControlWindow:Open window, enter the path and filename of the file that contains the compressed movie.

    You can play back JPEG or MPEG-1 movies by loading either the .Jpeg file, the .Mpeg1 file, or the corresponding .VCR file. To play back a CellB or UYVY file, you must load the .VCR file, not the .CellB or .UYVY file. For CellB and UYVY movies, the SunVideo program needs the information in the .VCR file to determine the movie's width and height. This information is not required to play back .Jpeg or .Mpeg1 files, since it is included in these files' bitstreams.

    4. Click OK to start playing the movie.
    5. Click MENU on the main window's Play button to start playing the movie.

    The movie appears in a window as shown in the example in Figure 4-9. You can click the Stop button at any time to stop playing the movie.

    Figure 4-9 Movie-Display Window

Fast Forward and Rewind Buttons

The FFwd (fast forward) and Rew (rewind) buttons enable you to scan a movie in search of a specific frame. Each time you click one of these buttons, the scan operation accelerates, which causes more frames to be skipped in between displayed frames.

Under some circumstances, these buttons may not have the effect that you would expect. When you click the Play button, frames are played back at the rate specified by the fps = lines in the .VCR file (see the section "Example .VCR File" on page 33 for a complete explanation). Depending on compression type, CPU speed, frame buffer type, and movie dimensions, the SunVideo program will either skip frames or pause briefly in order to match the specified frame rate.

When you click the FFwd button, the specified frame rate is ignored, and the SunVideo program plays back frames as fast as it can. If the SunVideo program is already skipping frames to match the specified frame rate, then the perceived frame rate actually will be less after you click on the FFwd button. You can negate this effect by simply clicking the FFwd button multiple times. Each click increments the number of frames that are skipped between displayed frames. (After the first click, no frames are skipped between displayed frames.)

Note that the setting of the Reverse checkbox affects only the play direction. It does not affect the FFwd and Rew buttons.

Playing Back a Movie from the Command Line

You also can play back a movie from the command line. Table 4-3 describes the SunVideo program's arguments.

    Table 4-3 Arguments for the SunVideo Program

--------------------------------------------------------------------------
Argument Description Default --------------------------------------------------------------------------
                                                         
-f <filename'>   Specifies the filename of the movie to   None - a filename 
                play back.                               is required
                                                         
-D <devname'>    Indicates which SunVideo card is the     /dev/rtvc0
                default (if your system has multiple                        
                SunVideo cards installed).                                  

--------------------------------------------------------------------------

For example, the command to display a CellB movie that is stored in the current directory as mymovie.VCR is:

% SunVideo -f mymovie.VCR