Come mostrare video in SL

From Second Life Wiki
Jump to navigation Jump to search


How to set up and play streaming video in Second Life.

Questo articolo copre ognuno dei passi necessari dall'encoding del contenuto video al visualizzarlo in Second Life.

Codificare un Video File

Il video da una qualsiasi sorgente deve prima essere convertito ad un file per computer da qualsiasi fonte esso proviene. Ci sono una varietà di programmi e dispositivi che possono fare questo. Una volta che il video è dentro al computer deve essere codificato in un formato che Quicktime può leggere. Le seguenti sono le impostazioni usate in Quicktime Pro per creare un movie che Second Life può leggere. Ci possono essere altre combinazioni che possono andare bene ma per questo esempio si sono scelte queste:

Impostazioni per Quicktime Pro

Standard Video Compression Settings

 Compression Type: MPEG-4 Video
 Frame Rate: 30 fps
 Key Frames: Every 24 frames

 Data Rate: Restrict to 436 kbits/sec
 Optimized for: Download
 Compressor Quality: Best

Sound Settings

 Format: AAC
 Channels: Stereo (L R)
 Rate: 44.100 kHz
Render Settings:
 Quality: Best
AAC Encoder Settings:
 Target Bit Rate: 64 kbps

Movie Settings

 Video
  Compression: MPEG-4 Video
  Quality: Best
  Bitrate: 436 kbits / sec
  Dimensions: 320 x 240
 
 Sound
  Format: AAC
  Sample Rate: 44.100 kHz
  Channels: Stereo (L R)
  Bit Rate: 64 kbps

Prepare for Internet Streaming

  Fast Start

A questo punto il programma farà partire l'encoding del video e produrrà un file .MOV. Ora è pronto per essere inserito nel tuo web server.

Configurationi di un Web Server

Avrai bisogno di accedere ad un web server, o un normale sito web o un server di streaming specializzato che è configurato per supportare http access. Una volta che il file è inserito determina il suo indirizzo URL. Se puoi vedere il video in Quicktime sul tuo computer usando l'indirizzo URL, ci sono buone possibilità che sarà visibile anche in SL.

Impostazioni per la Land

Le impostazioni della land per i video richiedono che devi essere un land owner oppure membro di un gruppo che ha i privilegi di impostare i Media per "streammare" video. A questa opzione si può accedere cliccando co destro sulla terra e selezionando il menù About Land. Apri la scheda Media.

CI sono due oggetti da impostare qua per i video. Una texture che sarà sostituita dal video quando sarà avviato e l'indirizzo URL per il file video. La texture può essere ogni immagine, ma è meglio impostare una texture che indica che un video è disponile. È mia opinione che la texture dovrebbe avvertire che esiste un video così come alcune instruzioni su come avviarlo. Una volta che la texture e l'URL sono impostati sei pronto/a ad avviare lo spettacolo.

All devices that can play a video can only display the URL set in the Land Media settings. If any change is made to that URL all playing devices in that parcel are immediately changed. Each visitor does not see the same portion of the video that anyone else may be seeing. This is the result of each client independently connecting to the URL. If the video is started using the display device, all present and equipped to see it will all start seeing it at the same time. Confused? I certainly was at first! See article Streaming Media for more information on how video is implemented in SL.

Scripting a Display

There are a number of free, and paid, "TV" (or video display) devices available in SL, but if you wanted to create your own display device here are some tips in getting it done!

The size (width and height dimensions not file size) of the video does not control how big you can make your display unit in SL, it establishes a standard ratio between width and height. Any multiple of those numbers will have the correct aspect ratio and will display undistorted video. Anything not matching that ratio will cause the video to display stretched or squished. A convenient size can be made by making your display prim from a cube set to X=2.0, Y=1.5 (This is four 0.5m units by three 0.5m units!) The z value can be set to whatever your device will need for depth. This resulting arrangement has the display facing up. The display surface just happens to be face 0 (zero) of the cube. This is important in having a correct orientation so your picture is not showing sideways! Remove any texture on face zero and set to a dark gray or black color. This will be the "off" setting for the TV. Now you are ready for a bit of simple scripting to start showing the movie!

Basic Video Display Script

The following script will run but you will soon find it inconvenient to use. It is to illustrate these commands:

llParcelMediaQuery() Get Land parcel media settings for video
llSetPrimitiveParams() To display the video on a surface making the device appear to turn on and off.
llParcelMediaCommandList() To control activating the media stream through the device.
Code: Basic video display script
// This script would be used in the prim that will show the video on surface zero.
// Touching the prim will start or stop the video display set in Land Media: Video.
 
// Global Variable declarations
key DefTexture;
vector DefColor;
list data;
key texture;
integer IsPlaying;
 
default {
    state_entry() {
        DefTexture = llGetTexture(0);                   // Save default texture set on prim surface zero.
        DefColor = llGetColor(0);                       // Save default color of prim surface zero
        IsPlaying = FALSE;                              // Set playing flag to FALSE.
    }

    touch_start(integer total_number) {
        // Read land parcel media settings
        data = llParcelMediaQuery([PARCEL_MEDIA_COMMAND_TEXTURE, PARCEL_MEDIA_COMMAND_URL]);
        texture = (key) llList2String(data, 0);         // Get texture for parcel to display
        if (IsPlaying) {                                // Player has video active
            llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP]);     // Stop streaming to the device.
            llSetPrimitiveParams([PRIM_TEXTURE,0,DefTexture,<1,1,0>,ZERO_VECTOR,0.0,PRIM_COLOR,0,DefColor,1.0,PRIM_FULLBRIGHT,0,TRUE]);
            IsPlaying = FALSE;
        }
        else {                                          // Check if Parcel Video is available
            if (llList2String(data, 0) == "") {         // Not a landowner or land group member error display
                key ErrTexture = llGetInventoryKey("ErrMsg");         // Get texture by name from inventory
                llSetPrimitiveParams([PRIM_TEXTURE,0,ErrTexture,<1,1,0>,ZERO_VECTOR,0.0,PRIM_COLOR,0,<1,1,1>,1.0,PRIM_FULLBRIGHT,0,TRUE]);
            }
            else {                                      // Set texture
                llSetPrimitiveParams([PRIM_TEXTURE,0,texture,<1,1,0>,ZERO_VECTOR,0.0,PRIM_COLOR,0,<1,1,1>,1.0,PRIM_FULLBRIGHT,0,TRUE]);
                llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]); // Start media playing to this device
                IsPlaying = TRUE;
            }
        }
    }
}

NOTE: The use of the ErrMsg texture is is a useful reminder if the device cannot function due to permissions not available to the owner. This is the text I used in white on blue:

  You are not a land owner or land group member; or parcel does not have media set. Cannot connect to parcel media.

It gives the basic idea as to why the video is not playing.