1

I'm streaming a video from an Amazon CloudFront RTMP source with

video.attachNetStream(myNetStream);
myNetStream.play(myVideoFileName,0,-1);

and it's working quite well. Now, what I want to do is something like this:

video1.attachNetStream(myNetStream);
video2.attachNetStream(myNetStream);
myNetStream.play(myVideoFileName,0,-1);

This doesn't work as written because only one of the two videos will play at a time for some unknown reason. I want video1 and video2 to play the same video from a single NetStream (to save bandwidth) and remain completely in-sync with each other. How can I accomplish this?

zakdances
  • 22,285
  • 32
  • 102
  • 173
  • 1
    have you tried using two different netStream objects? probably wouldn't save the bandwidth then though. Worst case, you could just copy raw pixel data from the video every frame and draw it somewhere else on the screen. – BadFeelingAboutThis Sep 11 '12 at 19:43
  • Yeah, I'm thinking the best approach would be to do just that (utilizing appendData()). I'm hoping someone will having some example code and some thoughts about performance. – zakdances Sep 11 '12 at 21:20
  • I have done it before and will post an example if no one has a better way – BadFeelingAboutThis Sep 11 '12 at 21:24
  • @LondonDrugs_MediaServices does it cause much of a performance drop? – zakdances Sep 11 '12 at 21:51
  • depends on the size of the video (and of course the hardware running your swf). And how often you redraw. If you have a webcam size video frame, it will probably be a breeze, if you have a 720p video, it could get sluggish on slow hardware. – BadFeelingAboutThis Sep 11 '12 at 21:55
  • @LondonDrugs_MediaServices the function I'm referencing is actually appendBytes not appendData. Looks like a similar question has been asked here http://stackoverflow.com/questions/4036727/use-one-netstream-object-to-feed-two-video-objects-simultaneously – zakdances Sep 11 '12 at 22:03
  • there seems to be some security restrictions on appendBytes which can't be overcome as the video is being hosted on CloudFront which doesn't allow access to security config files... – zakdances Sep 12 '12 at 00:34
  • @LondonDrugs_MediaServices No... bitmapData can't be accessed at all because of security restrictions. I'm going with plan B which is playing 2 netstreams, but reducing the file size of the one the videos by removing its audio. I'll have to wait until Amazon allow security policy access to use the bitmapData solution. – zakdances Sep 18 '12 at 02:31
  • How does your "myNetStream" object get instantiated? I haven't done this personally, but you might be able to make a single NetConnection instance, attach that to two different streams, and feed each stream into its' own video. The NetConnection is what actually shuffles your data around, isn't it? I thought the NetStream object was just a fancy buffer around the NetConnection. So you'd still save your bandwidth. – meddlingwithfire Sep 21 '12 at 20:32
  • No, NetStream is the actual data coming from the server. NetConnection is just the initial connection. So having 2 NetStreams will double the bandwidth usage. – zakdances Sep 21 '12 at 20:42

2 Answers2

0

If you are playing an FLV file directly (not streaming it from FMS), you should be able to :

  1. Load the file with URLStream
  2. Wait for sufficient data to start copying the data to a ByteArray object
  3. Create as many NetStream objects as you need and use the appendBytes(bytes) method

I haven't actually tested it, and the logic of appendBytes() needs to be looked at, but theoretically it should work.

Also, it deserves a benchmark. But it's probably better than re-drawing a bitmap copy at the same rate as the video, and keep the two videos in sync.

Antoine Lassauzay
  • 1,557
  • 11
  • 12
  • oops, i haven't seen the first line of your post, saying you use RTMP. Not sure what to do then, except using bitmap drawing. – Antoine Lassauzay Sep 12 '12 at 04:18
  • You're probably correct, but I haven't found a bitmap drawing function that doesn't need special tags set in the security policy (which I can't access because its hosted on CloudFront) – zakdances Sep 12 '12 at 04:27
  • As far as I know, the content to be drawn as a bitmap as to come from a trusted domain. When you say you can't access it, you mean you can't change it ? They don' – Antoine Lassauzay Sep 12 '12 at 04:42
  • Sorry. After a bit of googling seems like Amazon won't ley you change any FMS config (Client.videoSampleAccess might be why you can't do the bitmap copy). – Antoine Lassauzay Sep 12 '12 at 04:44
  • Do you know any other methods that don't require security policy changes? – zakdances Sep 12 '12 at 10:18
  • I suppose loading the `crossdomain.xml` from the FMS server domain is required. Try to see if it's not already loaded by the player using a Web Console (like Chrome's buil-in one) and if not, use `Security.loadPolicyFile`. Do you get a `SecurityError` when trying to draw the video object? – Antoine Lassauzay Sep 12 '12 at 12:53
0

bitmapData can't be accessed at all because of security restrictions. I'm going with plan B which is playing 2 netstreams, but reducing the file size of the one the videos by removing its audio. I'll have to wait until Amazon allow security policy access to use the bitmapData solution.

zakdances
  • 22,285
  • 32
  • 102
  • 173