To add custom metadata to the beginning of a live webcam stream published from Flash Media Server, use the NetStream.send() to publish the metadata in client-side ActionScript. However, if Flash Media Server records the live stream, the custom metadata is not stored in the file. This issue has been filed as bug 2548763.
When you record a live video stream (F4V/FLV file or DVR applications), Flash Media Server requires that the metadata is available before it flushes the first segment. There are two ways you can ensure that the metadata is available before the first segment flush:
Bad network conditions can still delay delivery of custom metadata. In cases of network inefficiencies, the server administrator can increase either the <MaxFlushTime> tag or the <MaxFlushSize> tag in server.xml.
The following code blocks provide examples of the recommended workarounds:
To ensure that the metadata is sent before the server flushes the first segments to disk, send the metadata immediately after calling publish. Do not wait for the "NetStream.Publish.Start" to send the metadata. Modify the typical publishing flow with the following example code that runs inside an event handler for the NetConnection.
private function onNetStatus(event:NetStatusEvent):void { switch(event.info.code) { case "NetConnection.Connect.Success": //nc is the existing NetConnection object ns = new NetStream(nc); nc.client = this; //Attach event handlers to the NetStream object ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); //Create camera and microphone objects cam = Camera.getCamera(); mic = Microphone.getMicrophone(); //Attach camera and microphone objects to the NetStream ns.attachCamera(cam); ns.attachAudio(mic); //Publish and record the stream on Flash Media Server ns.publish("myLiveStream", "record"); //Immediately send metadata objects to the server ns.send("@setDataFrame", "onMetaData", myMetaDataObj); break; case "NetStream.Publish.Start": trace("Camera is publishing...."); break; } }
Configure the application on the server to start recording the stream after a configured delay. The delay allows the server to wait for the custom metadata before starting the recording. Modify the following example code to run on your server:
application.onPublish = function(clientObj, streamObj) { //Get the published stream name streamName = streamObj.name; if(streamName) { //Create a local stream object on the server myStream = Stream.get(streamName); //Play the published stream locally for any subscribers myStream.play(streamName); //Create a delay to allow client to send metadata setInterval(function(){trace("Pausing for 1 second");}, 1000); //Initiate the recording of published stream with metadata myStream.record(); } }