Flash (Actionscript 3): Play 2 videos from 1 NetStream? - actionscript-3

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?

If you are playing an FLV file directly (not streaming it from FMS), you should be able to :
Load the file with URLStream
Wait for sufficient data to start copying the data to a ByteArray object
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.

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.

Related

flash: play a movie from half way in

Is it possible to play an MP4/H.264 movie in flash from half way thru?
Currently cant figure out how to seek to a time that hasn't buffered yet. Is there anyway of getting flash to start buffering half way into a movie?
edit:
The moov atom has already been set at the beginning of the MP4 file.
use pseudo-streaming
Normally you need a to use an streaming server which cost $$$ but you can use Pseudo-streaming.
Pseudo-streaming uses server-side scripts/modules where you have the server slice up the movie starting at the point you want to start from and wrap it as an mp4.
Stream your videos with standard HTTP servers
Pseudo-streaming (another article)
Oh yeah, I forgot about red5 as mentioned below in the comments. That is a free media server option for real streaming.
red5.org

My Sound object is using to much memory and causing my application to crash. How can I empty the first half of the objects data?

I'm currently working on a dynamic MP3 player in AS3. The player will also support continuous (in length) radio streams.
Because my player will include a 'seek' bar, I allow the user to seek through the Sound object's data. Now I know that with a continuous stream, data being stored on the users RAM will never stop, as downloading will never stop on a continuous stream. This means, after a few hours of streaming, allot of RAM is being used by my app. I've tested the app on my own machine, running a very high spec, and the app crashes in my browser. When i say the app crashes, I mean the whole of Flash, meaning I have to restart my browser in order to use Flash again. I know my app is the cause as Flash has never crashed in the past. It only does it when my app has been streaming for 2+ hours.
So what I want to do is only allow the user to cache up to an hours worth of audio. After an hour, I want to clear the first half of the sound objects data, meaning that only the most recent half hours audio is stored and available for seeking.
So I have my stream:
var soundObj:Sound = new Sound();
soundObj.load(new URLRequest('stream.mp3'));
//ect ect
and sound is where the data is stored. So my question: How would I clear the first 30 mins of audio from that object?
Perhaps the Sound class is not meant to reliably play "unlimited" MP3 files, which seems to be your case. It is made to play normal MP3 "songs". Two hours of MP3 sound can easily accumulate to be larger than 200 megabytes of data.
But there is a good solution - use NetConnection and NetStream classes to stream audio instead. There are many tutorials out there. You will also be able to stream your MP3s, just a bit differently - a central server will be involved, which will transcode these MP3s on the fly, delivering it to you in a true "streaming" manner. One of such servers is Adobe Flash Media Server, an overpriced piece of work from Adobe. A lot of free and open-source alternatives exist which will work fine for your purposes - Red5, nginx-rtmp to name a few, that I have tested myself.

Is it possible to stream live video to Flash Media Server via NetStream byte access?

So, I'm working with a video source that I'm feeding into my Adobe AIR application via some native extension work, with the goal of ultimately getting it to a Flash Media Server. The video is H.264 encoded and muxed into a FLV container, which aligns me with supported Flash Media Server codecs and NetStream (appendBytes) requirements. I can get the data into AIR just fine.
The mine I stepped onto today, however, is that documentation for NetStream.appendBytes states I must call NetStream.play(null):
Call this method on a NetStream in "Data Generation Mode". To put a NetStream into Data Generation Mode, call NetStream.play(null) on a NetStream created on a NetConnection connected to null. Calling appendBytes() on a NetStream that isn't in Data Generation Mode is an error and raises an exception.
NetStream.play() called with a null parameter yields local FLV playback. I can't publish the stream to FMS in this mode. But my research into Flash seems to indicate NetStream's byte access is my only real hope here when dealing with non-camera or non-web video data.
Q: Can I latch onto the video playback buffer for publish to a FMS? Can I create a sort of pipeline of NetStreams or NetConnections to achieve this? Or is there an alternate approach here for transmitting H.264/FLV data to FMS? (The source of my video cannot communicate with FMS directly.)
The answer to your question is quite simply no. This is apparently implemented as a security feature, which is probably less of a security based issue and more of a sales issue. Adobe likes to block certain capabilities intentionally in order to create the possibility of, or need of another product aka more revenue.
I tried looking into this for you to see if there was some dirty hack where you could attach a camera or something and override the binary data being sent to the stream like you can with Audio but unfortunately, to my knowledge, no such hack is possible. More nfo here: NetStream.appendBytes
Update
You might be able to do something hackish by using ManyCam which is a virtual webcam driver (from what I understand). This will provide a valid camera you can select from flash and you can also select a video file as the source file for ManyCam. See http://manycam.com/user_guide/#HowtoSelectaVideofileasthePictureSourceforManyCam
Update #2
If you're looking for something open source that will do the same thing as manycam, check out the following:
http://code.google.com/p/webcamstudio/wiki/VideoSourceMovie (GPL Licensed)

Post-processing captured video in AS3, creating slow motion

I have an interesting project wherein I need to allow users to capture video of themselves with a webcam at a kiosk, after which I email them a link to their video. The trick is the resulting video needs to be a 'slow motion' version of the captured video. So for example, if someone creates a 2 minute movie, the resulting movie will be 4 minutes.
I'd like to build this in Flex / AS3 if possible. I don't have issues capturing the video and storing it / generating and emailing a link, but slowing down the video is the real mind bender. I'm unsure how to approach 'batch post-processing' a set of videos using Adobe tools.
Has anyone had a project similar to this or have suggestions on routes to take in order to do this?
Thanks!
-Josh
This is absolutely feasible from the client side, contrary to what some may believe. :)
http://code.google.com/p/flvrecorder/
Just adjust the capture rate, which shouldn't be too difficult all the source is there.
Alternatively, you could write an AIR app that launches Adobe Media Encoder after writing a file and launch it with a preset that has FTP info etc. Or you can just use the socket class to connect and upload over FTP.
http://code.google.com/p/fl-ftp/
It is not feasible to do this client-side.
Capture the video and send it to the server.
Use a library like FFMpeg to do your coneversions

Actionscript 3.0 sound chain

Is it possible in actionscript 3.0 to play chain of sounds (i.e. several mp3s)?
Or should I manually start playing first sound, wait for SOUND_COMPLETE event, then start second sound and so on?
You'd need to use SOUND_COMPLETE, but you should be aware that Flash has some latency issues when it comes to playing sounds. Additionally, if you're using mp3s you have to remember that the mp3 file format itself has some blank space at the head of the file such that a continuous loop is not possible without using the 10.0+ Sound APIs to extract only the part of the file that contains actual sound.