The development experience of Flash video player

Source: Internet
Author: User

HTTP protocol is more excellent

At present, almost all video-on-demand websites use HTTP protocol to transmit data. Because the HTTP protocol is stateless in relation to protocols such as RTMP, the data is disconnected when it is finished, so the server can release resources to service more users. RTMP will maintain a connection while the user is playing, so the load on the server is very limited. and HTTP server, CDN, etc. are already very mature technology, low-cost performance is good. In addition, HTTP requests can be directly using the browser cookie, easy and web business through. Finally, HTTP can also use browser caching, which is also a disadvantage, the advantage is to request the same resources can be directly from the cache, the disadvantage is that the security of the point.

HTTP has better performance, but it can't transmit things that are too real-time, otherwise performance is not as good as rtmp, such as video chat, live these.

Security

Sometimes the videos we visit may need to be limited, such as anti-theft chains, video charges, and so on. If the use of HTTP protocol, the traditional way of authentication is enough, cookies token what to determine whether there is access to video resources, details I will not say. The only problem is that once the user has access to the video, it is possible to download the video for his use.

Further increase load capacity through fragmentation

In order for HTTP to serve more users while maintaining fewer connections, we need to transmit as quickly as possible. But is this the reason for our segmentation? No, because regardless of fragmentation, a user loading the full portion of video data on the server takes time (assuming the transfer speed is certain) and even consumes a lot more resources to create connections and destroy connections.

But we see that the major video sites are actually segmented video, and here I'll talk about the benefits of video segmentation.

Save Web site traffic, that is, save server resources to improve load capacity. When a user opens a video, there is a good chance that the video will not be read and only part of it. If you do not segment the video, the user opens the site to all the video data loaded, then the flow is a great waste. After segmenting the video, we can load the video for a period of time, and we will load the user to see how much.

More flexible seek (drag), for a video that does not make any segments, such as static video files on HTTP servers, we cannot jump through the NetStream object seek method to the part of the video that is not loaded. So to solve this problem, both Apache and Nginx provide FLV modules that support the start parameter. When the start parameter is specified, we can reload the video from the specified location to solve the problem. But the problem is the flow of waste, may have been loaded in the place to reload again. If we use the segmentation method, we can avoid this problem, the concrete implementation method will be described in detail later.

NetStream objects

How we play video on the Flash side is largely limited by the functionality provided by NetStream. So here's a general introduction to the features and limitations provided by NetStream, which is why the following programs are designed for this reason.

NetStream offers two modes, normal mode and data generation mode that can play HTTP video.

In normal mode, to netstream the HTTP video resource address we want to play, NetStream starts loading the video and starts playing. We can pause the video playback, but we can't pause the loading of the data, we can make a random seek in the part of the data that has already been loaded, but we can't seek the part that is not loaded. After loading the data we can still play, seek and other operations, but if the Close method is called to shut down the stream, if the data is not loaded, it will stop loading, and can not do any playback, seek and other operations, which is equivalent to our original load of data is in vain, can not be used. So if we want to segment the video and then randomly go back and forth in each video segment, we have to have a segmented video that corresponds to a netstream instance, in other words, there are several pieces that need a few netstream to wait on them (for the moment, we'll optimize the problem later).

In data generation mode, NetStream provides a more flexible loading mode. NetStream uses the Appendbytes method to add external binary data to play the video, and the order in which the data is added is the order in which it is played. In this case we can load the video file data through the Urlstream object, theoretically all the loaded data can be reused. But be careful not to plug all the data into memory or the memory will explode. Specific caching policies follow specifically.

Unlike other platform video players, flash cannot access local files directly, but it allows the browser to quickly get video data from the cache by loading the video that has already been loaded. So how to effectively use caching is the key to optimization.

Do not superstitious NetStream netstatusevent events, in different server and browser environment, the timing of this event may be slightly different, so the event can only do a reference, need to make some other prerequisite judgments.

Server support required for video segmentation

Static segmentation: The video can be divided into a set of independent playback of a few paragraphs to save to the server, play when you need to get a video address list. Each static fragment can only start from scratch and cannot request from the middle of the slice. This is the easiest way to perform well.

Static fragment +start parameters: The first scheme can be improved to support the beginning of a slice from the middle to the end of a fragment. That's what Youku potatoes do. This facilitates seek. There are also off-the-shelf nginx and Apache modules that can be supported.

Dynamic fragmentation: Both start and end parameters are provided so that the player can decide how to request fragmentation, more flexible for the player, and more convenient for server file management. This solution server solution Nginx and Apache should also have, have not been checked.

The above three kinds of final request data is a complete independent video file, the server will automatically help you add video file header. If Flash uses a data generation pattern, it actually returns a piece of file data directly and does not require additional file headers.

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.