Build fms2 Streaming Media Server in Linux-Online Video Recording

Source: Internet
Author: User
The source code of video recording seems to be quite a lot on the Internet. Here I declare that I copied the source code from others and modified it to optimize it. I am a little tired. I will not talk about it anymore. paste the source code directly:

VaR server_uri: String = "rtmp: // 215.102.25.xx/gdrc/video ";
// The FMS address, which is the same as that set for the player.

VaR videoname: String = "record"; // specifies the recording file name, which can be passed through parameters.

VaR my_nc: netconnection = new netconnection ();
// Create a connection object to connect to the FMS;

My_nc.connect (server_uri );
// Connect to the FMS;

VaR my_ns: netstream = new netstream (my_nc );
// Create a stream to capture and play a video;

VaR my_cam: Camera = camera. Get ();
Video_r.attachvideo (my_cam );
// Obtain the image head and load the video obtained by the camera to video_r.

// My_cam.setquality (1024, 90 );
// Set the bandwidth and quality;

VaR my_mic: microphone = microphone. Get ();
// Obtain the mic;

My_ns.attachvideo (my_cam );
My_ns.attachaudio (my_mic );
// Load the camera image and MIC sound to the stream.

Video_p. _ visible = false;
// Sets the playback window to invisible.

// The default Internet access mode is ADSL. You need to add someCode.
Updatebandwidth (2 );

Function updatebandwidth (B ){
If (B = 1) {// set the modem connection mode
My_cam.setmode (160,120, 2); 0
My_cam.setquality (0, 75 );
My_cam.setkeyframeinterval (3 );
My_mic.setrate (5 );
Video_r. _ Height = 100;
Video_r. _ width = 150;
}
Else if (B = 2) {// ADSL Internet Access Mode settings
My_cam.setmode (160,120, 5 );
My_cam.setquality (0, 85 );
My_cam.setkeyframeinterval (5 );
My_mic.setrate (11 );
Video_r. _ Height = 130;
Video_r. _ width = 175;
}
Else {// LAN leased line access method settings
My_cam.setmode (160,120, 15 );
My_cam.setquality (0, 90 );
My_cam.setkeyframeinterval (10 );
My_mic.setrate (22 );
Video_r. _ Height = 150;
Video_r. _ width = 200;
}
My_ns.call ('setbandwidth', 0, B );
}
/* A few buttons have been prepared to allow the user to select the Internet access method, but the button is canceled if it is too ugly. You can add it on your own.
Modem_btn.onpress = function (){
Updatebandwidth (1 );
}

Dsl_btn.onpress = function (){
Updatebandwidth (2 );
}

Lan_btn.onpress = function (){
Updatebandwidth (3 );
}
*/

My_nc.onstatus = function (thisobj: Object)
{
// Trace (thisobj. Code );
If (thisobj. Code = "netconnection. Connect. Success ")
{
Recordstop ("idle ");
}
Else
{
Trace ("error: Server not started or Uri input error .");
}
}

Function record ()
{
Video_r. _ visible = true;
Video_p. _ visible = false;
My_ns.publish (videoname, "record ");
Streaminfo ("nowrecord ");
Btn_pr.btn_text.text = "stop ";
Recordinterval = setinterval (recordtime, 1000 );
Txt_videoname.text = "video name:" + videoname;
}

VaR timenum: Number = 0;

Function recordtime ()
{
Timenum ++;
Txt_status.text = "Recording" + "" + "time:" + math. Floor (timenum/60) + "Minute" + (timenum % 60) + "second ";
}

Function recordstop (_ Status: string)
{
Txt_status.text = "Current status:" + _ status;
Btn_pr.btn_text.text = "Recording ";
Streaminfo ("nowstop ");
Clearinterval (recordinterval );
Timenum = 0;
If (_ Status = "Recording completed ")
{
Finished ();
}
Else
{
Trace ("");
}
}

Function finished ()
{
My_ns.close ();
Video_r.clear ();
VaR thisobj = this;
VaR finishalert: movieclip = _ root. attachmovie ("alert", "finishalert", 100 );
With (finishalert)
{
Alerttitle.html = true;
Alerttitle.html text = "<B>" + "the recording is complete! "+" </B> ";
_ X = video_r. _ x + (video_r. _ width-_ width)/2;
_ Y = video_r. _ y + (video_r. _ height-_ height)/2;
Info. Text = "Recording completed... Please select next operation ."
Btn_sub.btn_txt.text = "play ";
Btn_cln.btn_txt.text = "record ";
Btn_sub.onrelease = function ()
{
Thisobj. playvideo ();
Thisobj. closealert (finishalert );
}
Btn_cln.onrelease = function ()
{
Thisobj. Record ();
Thisobj. closealert (finishalert );
}
Closed. onrelease = function ()
{
Thisobj. closealert (finishalert );
}
}
Btn_pr.enabled = false;
}

Function closealert (_ alert: movieclip)
{
Btn_pr.enabled = true;
Unloadmovie (_ alert );
}

function streaminfo (_ Status: string)
{< br> btn_pr.onrelease = function ()
{< br> If (_ Status = "nowrecord")
{< br> recordstop ("Recording completed ");
}< br> else if (_ Status = "nowstop")
{< br> record ();
}< br> else if (_ Status = "nowplay")
{< br> record ();
}< BR >}

Function playvideo ()
{
Txt_status.text = "Current status:" + "playing ...";
Streaminfo ("nowplay ")
Video_r. _ visible = false;
Video_p. _ visible = true;
Video_p.attachvideo (my_ns );
My_ns.play ("record ");
Btn_pr.btn_text.text = "record ";
My_ns.onstatus = function (playinfo)
{
If (playinfo. Code = "netstream. Play. Stop ")
{
My_ns.seek (0 );
My_ns.pause ();
Txt_status.text = "Current status:" + "playback completed ...";
}
}
}

Complete content added by main. ASC on the server:

Load ("components. ASC ");

Application. onappstart = function (){};
Application. onconnect = function (client ){
Application. acceptconnection (client );
Client. getfilelength = function (filename ){
VaR tlen = stream. Length (filename );
Return tlen;
};
 
Client. Prototype. setbandwidth = function (BW ){
If (BW = 1) {// modem settings
This. setbandwidthlimit (35000/8, 22000/8 );
}
Else if (BW = 2) {// DSL settings
This. setbandwidthlimit (800000/8, 100000/8 );
}
Else {// LAN Settings
This. setbandwidthlimit (400000,400 000 );
}
};
};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.