I'm wishing to setup a playlist using a single streaming video by segmenting it into shorter clips e.g.
rtmp://myserver/mp4:myVideo (duration 40 minutes)
track1: start time 05:10, end time: 08:30
track2: start time: 08:31, end time: 12:15
track3: start time: 15:00, end time: 16:35
Primarily these clip times will rollover seamlessly (e.g. between track1 and track2) however sometimes there may be gaps (e.g. between track 2 and track 3).
In order to have seamless stream switching I realise I have to share the NetConnection, and probably the NetStream as well. I can easily achieve this in AS3 with my own NetConnection and NetStream code however how is something like this best achieved within OSMF? I'm happy to extend classes and roll my own solution but a brief overview of what/where would be much appreciated please.
1. What is the best way to share a NetConnection between non-standard streaming URLs?
My urls look like this: rtmpe://streaming.client.com/mp4:folder/filename
We're using a CNAME to mask the FMS Application Instance name e.g. rtmpe://streaming.client.com is equal to rtmpe://fms.userID.edgecastcdn.net/userID/streaming/client
I've tried the following with mixed success.
Method 1 - StreamingURLResource - Seems to require a folder as part of the NetConnection path which isn't ideal for me:
var factory:NetConnectionFactory = new NetConnectionFactory(true); // enable sharing NC's
var netLoader:NetLoader = new NetLoader(factory);
// These are less than ideal as they require a folder to connect e.g. rtmpe://streaming.client.com/folder/mp4:video1 instead of rtmpe://streaming.client.com/mp4:folder/video1
var resource1:StreamingURLResource = new StreamingURLResource("rtmpe://streaming.client.com/folder/mp4:video1");
resource1.clipStartTime = 500;
resource1.clipEndTime = 530;
var resource2:StreamingURLResource = new StreamingURLResource("rtmpe://streaming.client.com/folder/mp4:video1");
resource2.clipStartTime = 531;
resource2.clipEndTime = 600;
// resource.urlIncludesFMSApplicationInstance = true; doesn't seem required and breaks the connection so it is not used.
var serial:SerialElement = new SerialElement();
serial.addChild(new VideoElement(resource1, netLoader)); // pass in the NetLoader in order to share the same NetConnection
serial.addChild(new VideoElement(resource2, netLoader));
Method 2 - DynamicStreamingResource - Doesn't require a folder as part of the NetConnection path however was not intended for a single bitrate:
var segment1:DynamicStreamingItem = new DynamicStreamingItem("mp4:folder/video", 700, 640, 360);
// These are better as they allow me to connect to the correct depth without require a folder.
var resource3:DynamicStreamingResource = new DynamicStreamingResource("rtmpe://streaming.client.com", StreamType.RECORDED);
resource3.streamItems = Vector.<DynamicStreamingItem>([segment1]);
resource3.clipStartTime = 500;
resource3.clipEndTime = 530;
var resource4:DynamicStreamingResource = new DynamicStreamingResource("rtmpe://streaming.client.com", StreamType.RECORDED);
resource4.streamItems = Vector.<DynamicStreamingItem>([segment1]);
resource4.clipStartTime = 531;
resource4.clipEndTime = 600;
DynamicStreamingResource seems to work best regardless of the fact I'm not using it as intended (e.g. single bitrate). Also is there an easy way to verify that the same NC is being used at runtime other than manually comparing them?
2. What is the best way to share NetStreams between resources?
By using clip times on the resouces I believe it closes the NetStream and creates a new one which ends up causing a lag of up to 10 seconds between tracks. Is there a way to share the NS if it uses the same URL? I've done it before in custom AS3 code where I'm instead listening for the ns.time and manually switching resources when my custom end time is reached. In order to have seamless stream switching is using the following code:
var nso:NetStreamPlayOptions = new NetStreamPlayOptions();
nso.streamName = videoName; // shared resource
Does OSMF use netstream.play2() when available?
Cheers for any help you can provide.