How can you switch H264 to NetStream?

Take the following code:

m_h264Settings = new H264VideoStreamSettings(); <some configuration in between> m_ns.videoStreamSettings = m_h264Settings; 

What a decent way to switch m_ns videoStreamSettings to still use H264 or not?

I tried to find the videoStreamSettings property in the source documentation for NetStreams ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html ), and Adobe obviously missed this little detail. I know how to effectively control whether NetStream uses H264 or "by default" throughout the entire application, but I want you to be able to click a button so that it switches back and forth without replacing NetStream or doing nothing else crazy .

How is this done right? Thanks!

+4
source share
1 answer

Reading your question, it seems that there are a few questions that you asked, plus a slightly more detailed explanation would be helpful, so I will make some assumptions to try to answer:

Question 1:

What a decent way to switch m_ns video to StreamSettings? Still using H264 or not?

By default, do you mean the use of the On2 VP6 video codec and, therefore, publication in FLV format, not F4V?

I assume your request is related to a connecting application that plays the published stream? Obviously, you can use the variable to keep track of which settings you applied to the stream in the recording application itself otherwise.

I will work with the assumption that you have a separate application that swallows a published stream, and is simply trying to determine if the stream will be published using H264, not On2 VP6. First, the file type will be different, one will be FLV, and one will be F4V. Secondly, you can use the metadata assignment for the stream when publishing:

 protected function sendMetadata():void { var metaData:Object = new Object(); metaData.codec = stream.videoStreamSettings.codec; metaData.profile = m_h264Settings.profile; metaData.level = m_h264Settings.level; metaData.hasMetadata = true; stream.send("@setDataFrame", "onMetaData", metaData); } 

In your playback application, you can use the onMetaData () callback to capture the required information:

 public function onMetaData(infoObject:Object):void {} 

Question 2:

I want to be able to press a button so that it switches back and forth without replacing NetStream or doing anything else crazy like this.

I would recommend reconnecting when switching your settings to unpublish an existing stream and reconnect the camera and publish a new stream with different video settings. This will maintain the integrity of the stream, and to be honest, publishing and republishing the stream is not as crazy as you say.

If you need to go down the route of switching settings, my guess is that what you declare as default will prevent file formats from changing in the already published stream.

I personally will not use the same codec and apply different H264VideoStreamSettings in the middle of the stream publication. H264VideoStreamSettings are checked only when adding a camera to a stream and are applied after compression has begun. As far as I understand, compression begins with the publication of the stream, so to switch, since you assume that you are going to mess with the compression of the already released stream. The resulting flow would lead to too many fluctuations, and I am struggling to understand why this is necessary. However, I may be fixed or may be for testing purposes.

This is completely untested, but you can create an instance of the camera, apply the VideoStreamSettings video settings, attach the camera to the stream instance and then publish. While it publishes to switch settings, you can disconnect your camera instance from the network stream:

 stream.attachCamera(null); 

And then just create a new camera instance, apply the new videoStreamSettings settings and finally attach them to the already published stream.

Usually I send metadata when the status event "NetStream.Publish.Start" was received. You will need to change this and resend each time you re-attach the camera to the stream until the stream is published. I do not know what the consequences of this will be, but your connected player should be happy to receive a callback for changes to the metadata.

+1
source

Source: https://habr.com/ru/post/1441377/


All Articles