質問

Take the following code:

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

What's a decent way to toggle whether m_ns's videoStreamSettings are still using H264 or not?

I tried looking up the property videoStreamSettings in the primary documentation for NetStreams (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html), and Adobe apparently skipped that little detail. I know how to effectively control whether the NetStream uses H264 or "the default" throughout the whole execution of the application, but I want to be able to keep clicking a button to make it switch back and forth, without replacing the NetStream or doing anything else crazy like that.

How is this properly done? Thanks!

役に立ちましたか?

解決

Reading your question it appears as though there are a couple of questions your asking plus a little more clarification would be helpful so I will make some assumptions to try and answer:

Question 1:

What's a decent way to toggle whether m_ns's videoStreamSettings are still using H264 or not?

By default do you mean using the On2 VP6 video codec and therefore publishing to the FLV format as opposed to F4V?

I presume your query is related to a connecting application which is playing back the published stream? You could obviously use variable to track which settings you applied to the stream within the recording application itself otherwise.

I will run with the assumption you have a separate application that is ingesting the published stream and your simply trying to determine whether the stream is published using H264 and not On2 VP6. Firstly the file type will differ, one will be FLV and one will be F4V. Secondly you can take advantage of assigning metadata to the stream when you publish:

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 then use the onMetaData() callback to grab the information you require:

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

Question 2:

I want to be able to keep clicking a button to make it switch back and forth, without replacing the NetStream or doing anything else crazy like that.

I would recommend a reconnection routine on toggling your settings to unpublish the existing stream and re-connect the camera and publish a new stream with the different video settings. This would maintain the integrity of the stream and to be honest, un-publishing and re-publishing a stream is not all that crazy as you say.

If you must go down the route of toggling settings then my assumption above on what you declare as default would prevent changing file formats on an already publishing stream.

I personally wouldn't use the same codec and apply different H264VideoStreamSettings mid-publish of a stream. H264VideoStreamSettings are only validated on adding the camera to the stream and applied once compression has started. It is my understanding the compression starts on publishing of the stream so to toggle as you suggest your are going to be messing around with compression on an already publishing stream. The resulting stream would result in too many fluctuations in my opinion and I struggle to see why this would be necessary. However, I may stand to be corrected or it may be for testing purposes.

This is completely untested but you could create the camera instance, apply your videoStreamSettings, attach the camera to your stream instance and then publish. Whilst it is publishing to switch the settings you could detach your camera instance from the net stream:

stream.attachCamera(null);

And then simply create a new instance of the camera, apply the new videoStreamSettings and finally attach it to the already published stream.

I typically send the metadata when the status event "NetStream.Publish.Start" has been received. You would have to modify this and re-send every time you re-attach the camera to the stream, so long as the stream is publishing. I do not know what the implications of this would be though, but your connected player should receive the callback on metadata changes hopefully.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top