RTMP streaming with OSMF - AS3 - actionscript-3

New to OSMF and trying to play a streaming mp4 on our limelight server. According to this tutorial http://www.adobe.com/devnet/flash/articles/video_osmf_streaming.html, you simply pass the RTMP link to the URLResource. I've tried that and it isn't working. It plays fine if I pass a local URL. I am using OSMF 1.5 SWC and my code is
package
{
import flash.display.*;
import flash.events.*;
import org.osmf.media.*;
public class Main extends Sprite
{
private var mps:MediaPlayerSprite;
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
mps = new MediaPlayerSprite();
mps.width = 640;
mps.height = 360;
mps.resource = new URLResource("rtmp://my.limelight.host.net/mp4:dyk_seatbelts_high.mp4");
addChild(mps);
}
}
}
I dont get any errors just a blank canvas. Any ideas?

You should add streamer and video url for RTMP streaming. For example:
var resource:DynamicStreamingResource = new DynamicStreamingResource(videoStreamer);
resource.urlIncludesFMSApplicationInstance = true;
var vector:Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem>(1);
vector[0] = new DynamicStreamingItem(videoUrl, 1200);
resource.streamItems = vector;
element = new VideoElement(resource);
player.media = element;
You can add few dynamic streaming items. Video files with different bitrate.
Example for videoStreamer: rtmp://streamer_url
Example for videoUrl: mp4:path_to_video.mp4

This is just an update. The DynamicStreamingItem is not available anymore. You can simply add your rtmp stream url to a StreamingURLResource. Plays like a charm. (Correct me if i'm wrong....i'm new to OSMF)
var videoElement:VideoElement = new VideoElement();
videoElement.resource = new StreamingURLResource("rtmp://cp140972.XXXXX",StreamType.LIVE,NaN,NaN,null,false);
player.media = videoElement;

Related

Play mp4 sound in flex

I am working on audio player which play sound of mp4 file format.
This audio file are of recorded files by user, which will play in audio player later.
And another thing is mp4 file url is rtmp not http which is like:
rtmp://domain/vod/mp4:foldername/filname.mp4
I have done following things:
<s:Button id="btnPlay" label="Play" click="Play_clickHandler(event)" />
AS:
public var sound:Sound;
public var mySoundChannel:SoundChannel;
protected function Play_clickHandler(event:MouseEvent):void
{
sound = new Sound();
sound.addEventListener(Event.SOUND_COMPLETE, soundComplete);
var req:URLRequest = new URLRequest("rtmp://domain/vod/mp4:foldername/filname.mp4");
sound.load(req);
mySoundChannel = sound.play();
}
private function soundComplete(event:Event):void {
sound.load(new URLRequest("rtmp://domain/vod/mp4:foldername/filname.mp4"));
mySoundChannel = sound.play();
}
I Have tried above code but didn't succeed. It played only mp3 file format.
Any way i can play this file?
Note: I do not want to convert file to mp3 file format using any method.
I have tried to play this file in VideoPlayer. It works but design looks bad.
FYI:
Audio file format is:
Any help is greatly appreciated.
You can not use a Sound object to play the audio of an RTMP stream like that.
But to do that, I think that the easiest way is to use a NetStream object and with its receiveVideo() function, you can receive just the audio stream, also you don't even need any video player to be attached to it.
Take a look on this example :
var server:String = 'rtmp://localhost/vod',
stream:String = 'mp4:video.mp4',
nc:NetConnection,
ns:NetStream;
function init(): void
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, on_NetStatus);
nc.connect(server);
}
function on_NetStatus(e:NetStatusEvent): void
{
if(e.info.code == 'NetConnection.Connect.Success'){
ns = new NetStream(nc);
ns.receiveVideo(false);
ns.play(stream);
}
}
init();
Hope that can help.

Recording Flash Webcam FMS 4.5 to Mp4 results in terrible quality

I have successfully setup recording webcam to FLV using FMS 4.5 developer edition, so I wanted to attempt recording to an Mp4 next. I am doing a silent save of the video file because the goal here is to be able to have these videos playable outside of Flash/FMS. I set the program up to save the Mp4 file generated by FMS, but the quality is terrible. I am seeing green distortion when movement is captured, and heavy pixelation. Here is my test application code that saves the video file after 5 seconds of recording. Can anyone please point out where I am going wrong? Any help is greatly appreciated.
package com
{
import flash.display.*;
import flash.net.*;
import flash.utils.Timer;
import flash.events.*;
import flash.filesystem.File;
import flash.media.*;
public class Main extends MovieClip
{
private var nc:NetConnection;
private var ns:NetStream;
private var nsPlayer:NetStream;
private var vid:Video;
private var vidPlayer:Video;
private var cam:Camera;
private var mic:Microphone;
private static const LOCAL_VIDEO:String = "myCamera";
private static const VIDEO_FPS:uint = 30;
private static const SAVE_FOLDER_NAME:String = "Saved_Videos";
private static const PATH_TO_FMS:String = "C:/Program Files/Adobe/Flash Media Server 4.5";
private var timer:Timer = new Timer(5000, 1);
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://localhost/PublishLive/myCamera");
}
function onNetStatus(evt:NetStatusEvent):void
{
if(evt.info.code == "NetConnection.Connect.Success")
{
publishCamera();
displayPublishingVideo();
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleted);
timer.start();
}
}
private function timerCompleted(evt:TimerEvent)
{
trace("timer completed");
timer.stop();
ns.close();
ns = null;
var saveFile:File = new File(PATH_TO_FMS + "/applications/PublishLive/streams/" + LOCAL_VIDEO + "/" + LOCAL_VIDEO + ".mp4");
var fileName:String = "Video" + ".mp4";
var dir:File = File.documentsDirectory.resolvePath(SAVE_FOLDER_NAME);
dir.createDirectory();
var fileToSave = dir.resolvePath(fileName);
if(fileToSave.exists)
{
fileToSave.deleteFile();
}
saveFile.copyTo(fileToSave, true);
}
private function publishCamera()
{
var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();
h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3_1);
cam = Camera.getCamera();
cam.setMode(stage.stageWidth, stage.stageHeight, VIDEO_FPS, true);
cam.setQuality(0, 90);
cam.setKeyFrameInterval(15);
cam.setMotionLevel(100);
mic = Microphone.getMicrophone();
mic.setSilenceLevel(0);
mic.rate = 11;
ns = new NetStream(nc);
ns.videoStreamSettings = h264Settings;
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish("mp4:myCamera.mp4", "record");
}
private function displayPublishingVideo():void
{
vid = new Video();
vid.width = stage.stageWidth;
vid.height = stage.stageHeight;
vid.attachCamera(cam);
addChild(vid);
}
}
}
Ok, so I am answering my own question. I found the answer here along with the link to the tool to process: adobe help site
You must convert the files after recording them using a post-processing tool so they can be viewed in other video players.
Edit: VLC can actually play the unprocessed file, so I thought it was a quality issue at first!
You could try to change the quality of the video stream VideoStreamSettings.setQuality(bandwidth:int, quality:int) (link).
You only set one of the bandwidth or quality values and leave the other to 0. I would try to set bandwidth (measured in bytes per second) to 750000 (6 Mbps), which should be plenty for anything less than full HD.
So, in your case, you could try:
h264Settings.setQuality(750000, 0);

Flex playing mp3 stream doesn't work

I've copied the sample code from Adobe for playing an mp3 stream in Flex mobile but it doesn't seem to work.
The stream i used as an example works perfectly fine in Winamp.
This is my code:
import flash.net.*;
import flash.media.*;
private var req:URLRequest;
private var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
private var s:Sound;
private var channel:SoundChannel = new SoundChannel();
private function AudioOn():void
{
req = new URLRequest("http://stream2.srr.ro:8000");
s = new Sound(req,context);
channel=s.play();
}
private function onInit() : void {
AudionOn();
}
Using the debbuger the s (sound) object has the following state:
s.isBuffering is true;
s.isURLInaccesible is false;
s.bytesLoaded = 0
s.bytesTotal = 0;
This seems to be an easy task but why doensn't this example work ?
Thanks a lot!
Dan
Have you ever tried to modified your sound file by
Remove all metadata in the sound file.
Export it to a new MP3 file.
Is it too large to load? Try to add error event to listen.

loading external movie as2 wrapper

Load AS2 SWF Into AS3 SWF and pass vars in URL
I'm trying to load in a as3 file an external as2 swf file (of which I dont have access to fla file). According to the explanation given in the link above, the solution would be to use a as2 wrapper to the original as2 file (and establish a localconnection between the the as3 and as2 files). I've tried to do that, but although the movie seems to load in my as3 file, it doesnt start, doesnt play and gets stuck in the first frame. How do I play the movie (as well as load it)? Thanks for your help.
My as3 file is:
import com.gskinner.utils.SWFBridgeAS3;
var loader = new Loader()
loader.load(new URLRequest("as2_test.swf"));
addChild(loader);
var sb1:SWFBridgeAS3 = new SWFBridgeAS3("test",this);
my as2 file is:
import com.gskinner.utils.SWFBridgeAS2;
var sb1 = new SWFBridgeAS2("test",this);
sb1.addEventListener("connect",this);
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(this);
loader.loadClip("digestive.swf", mainLoader_mc);
EDIT: I keep having this problem. This is what I have so far:
as2 file - as2test.fla (this needs to download another as2 file -digestive.sfw and acts as wrapper to establish connection between the original as2 file and the main as3 file)
import com.gskinner.utils.SWFBridgeAS2;
var sb1 = new SWFBridgeAS2("test",this);
sb1.addEventListener("connect",this);
var my_pb:mx.controls.ProgressBar;
my_pb.mode = "manual";
this.createEmptyMovieClip("img_mc22", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
my_pb.label = "loading: " + target_mc._name;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
var pctLoaded:Number = Math.ceil(100 * (numBytesLoaded / numBytesTotal));
my_pb.setProgress(numBytesLoaded, numBytesTotal);
trace(pctLoaded);
};
my_mcl.addListener(mclListener);
my_mcl.loadClip("digestive.swf", img_mc22);
stop();
as3 file (this plays the as2 wrapper):
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("as2test.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
stop();
In the as2 wrapper file, the original movie plays until a certain frame; in the as3 file, the as2 wrapper file only plays the first frame. What do I have to do?????

Live streaming of .flv format movie is not working if the directory is moved into other place

I can play the .flv movie after compilation through FlashDevelop but its not working if I move the whole directory into another PC or another Directory in the same PC. Your help will be much appreciated...Thanks
package
{
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
public class Main extends Sprite {
private var nc:NetConnection;
private var ns:NetStream;
private var vid:Video;
private var client:Object;
public function Main () {
// Initialize net stream
nc = new NetConnection();
nc.connect (null); // Not using a media server.
ns = new NetStream(nc);
// Add video to stage
vid = new Video(320,240);
addChild (vid);
//vid.x = ( stage.stageWidth / 2) - ( vid.width / 2 );
//vid.y = ( stage.stageHeight / 2) - ( vid.height / 2 );
// Changed since when deployed the
// above set the video player nearly off the screen
// Since I am lazy, I am just going to 0 them
// out for now. Apparently, I have a lot more
// to learn.
vid.x = 0;
vid.y = 0;
// Add callback method for listening on
// NetStream meta data
client = new Object();
ns.client = client;
client.onMetaData = nsMetaDataCallback;
// Play video
vid.attachNetStream ( ns );
ns.play ( 'dancinggirl_1.flv' );
}
//MetaData
private function nsMetaDataCallback (mdata:Object):void {
trace (mdata.duration);
}
}
}
You have to specify the path where your flv is located and asure the flv is located in this relative path to your swf.
ns.play ( 'path/to/dancinggirl_1.flv' );
If you embed the swf into a HTML page. The path has to be relative to the HTML, not the swf file.