加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash + FMS 发布 录制 接受 h264视频

发布时间:2020-12-15 07:02:34 所属栏目:百科 来源:网络整理
导读:发布端 ?xml version="1.0" encoding="utf-8"? s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ????? xmlns:s="library://ns.adobe.com/flex/spark" ????? xmlns:mx="library://ns.adobe.com/flex/mx" ????? width="800" height="600" ????? ?????

发布端

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
????? xmlns:s="library://ns.adobe.com/flex/spark"
????? xmlns:mx="library://ns.adobe.com/flex/mx"
????? width="800" height="600"
?????
????? creationComplete="init()">
?<fx:Declarations>
??<!-- 将非可视元素(例如服务、值对象)放在此处 -->
?</fx:Declarations>
?<fx:Script>
??<![CDATA[
???
???private var nc:NetConnection;
???
???private var ns:NetStream;
???
???private var camera:Camera;
???private var microphone:Microphone;
???private var video:Video;
???
???private var h264:H264VideoStreamSettings = new H264VideoStreamSettings();
???
???private function init():void
???{
????initCameraAndMicrophone();
???}
???
???private function initNet():void
???{
????
????nc = new NetConnection();
????nc.connect("rtmp://localhost/testH264");
????nc.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
????nc.client =?this;
???}
???
???private function initCameraAndMicrophone():void
???{
????camera = Camera.getCamera();
????microphone = Microphone.getMicrophone();
????trace(camera);
????if(Camera.isSupported)
????{
?????if(camera)
?????{
??????
??????if(camera.muted)
??????{
???????camera.addEventListener(StatusEvent.STATUS,cameraStatusEventHandler);
???????camera.addEventListener(ActivityEvent.ACTIVITY,activityEventHandler);
??????}
??????camera.setMode(320,240,15);
??????video = new Video();
??????video.smoothing = true;
??????video.attachCamera(camera);
??????this.videoDisplay.addChild(video);
?????}
?????else
?????{
??????trace("No Camera is installed.")
?????}
????}
???}
???
???private function onStatusEvent(event:NetStatusEvent):void
???{
????trace(event.info.code);
????var code:String = event.info.code;
????switch(code)
????{
?????case "NetConnection.Connect.Success":
??????creatStream();
??????break;
????}
???}
???
???private function cameraStatusEventHandler(event:StatusEvent):void
???{
????trace(event.code);
????switch(event.code){
?????case "Camera.Muted":
??????break;
?????case "Camera.Unmuted":
??????initNet();
??????break;
????}
???}
???
???private function activityEventHandler(event:ActivityEvent):void
???{
?????
???}
???
???private function creatStream():void
???{
????ns = new NetStream(nc);
????ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
????var h264Stream:H264VideoStreamSettings = new H264VideoStreamSettings();
????h264Stream.setProfileLevel(H264Profile.BASELINE,H264Level.LEVEL_5_1);
????h264Stream.setMode(1280,720,25);
????h264Stream.setQuality(0,80);
????ns.videoStreamSettings = h264Stream;
????ns.attachCamera(camera);
????ns.attachAudio(microphone);
????ns.publish("mp4:testH264_1.mp4","record");
???}
???
???private function onMetaDataHandler(info:Object):void
???{
????
???}
???
??]]>
?</fx:Script>
?<s:VideoDisplay id="videoDisplay" width="320" height="240" horizontalCenter="0"
?????verticalCenter="0"/>
</s:Application>

?

接收端

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
????? xmlns:s="library://ns.adobe.com/flex/spark"
????? xmlns:mx="library://ns.adobe.com/flex/mx"
????? width="800" height="600"
?????
????? creationComplete="init()">
?<fx:Declarations>
??<!-- 将非可视元素(例如服务、值对象)放在此处 -->
?</fx:Declarations>
?<fx:Script>
??<![CDATA[
???
???private var nc:NetConnection;
???
???private var ns:NetStream;
???
???private var camera:Camera;
???private var microphone:Microphone;
???private var video:Video;
???
???private var h264:H264VideoStreamSettings = new H264VideoStreamSettings();
???
???private function init():void
???{
????//initCameraAndMicrophone();
????initNet();
???}
???
???private function initNet():void
???{
????
????nc = new NetConnection();
????nc.connect("rtmp://localhost/testH264");
????nc.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
????nc.client =?this;
???}
???
???
???private function onStatusEvent(event:NetStatusEvent):void
???{
????trace(event.info.code);
????var code:String = event.info.code;
????switch(code)
????{
?????case "NetConnection.Connect.Success":
??????creatStream();
??????break;
????}
???}
???
???private function creatStream():void
???{
????var nsClient:Object = {};
????nsClient.onMetaData = onMetaDataHandler;
????
????ns = new NetStream(nc);
????ns.client = nsClient;
????
????ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
???????
????ns.play("mp4:testH264_1.mp4");
????video = new Video(320,240);
????video.attachNetStream(ns);
????this.videoDisplay.addChild(video);
???}
???
???private function onMetaDataHandler(info:Object):void
???{
????trace(info.duration);
???}
???
??]]>
?</fx:Script>
?<s:VideoDisplay id="videoDisplay" width="320" height="240" horizontalCenter="0"
?????verticalCenter="0"/>
</s:Application>

?

FMS服务器最好是4.5版本,

在应用服务器里面(application目录)新建一个testH264目录即可。


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读