How to implement an FLV video-on-demand system with C/s mode

Source: Internet
Author: User
Tags flv file

First, write in front

Video on demand, is a once very hot, is still very hot today, a video service technology. I recently committed to research the application of various video formats in the VOD system, has now studied the successful FLV, f4v, MP4, TS format video-on-demand solutions, fully support the above format for storage The situation of encoded video and will continue to study other formats.

One thing to note here is that F4V originally referred to Adobe's video format based on the ISO/IEC 14496-12 standard, which is the same as the MP4 format, but because many video sites in the country store the FLV of the encoded video The file is labeled. f4v format, and the on-demand implementation of this file is different from the normal FLV , so in order to avoid more confusion, I followed their naming, so "FLV" will only refer to not including h.264/ AAC-encoded general FLV video.

This article briefly describes how to implement a simple FLV-based video-on-demand system.

Second, FLV format

  FLV (Flash video) is a video format introduced by Adobe and is a video storage container format designed to be transmitted over a network. The format is relatively simple and does not require large media header information, so the loading speed is very fast. Domestic major video sites, have adopted the FLV format as its on-demand, even live video format. The main feature of the FLV container format is tag, the entire FLV consists of video tag, Audio tag and other tags, no mapping table.

Basically, the FLV format can be briefly drawn to the following form:

  

Among them, the FLV header refers to the FLV head, only 9 bytes, and the regular MP4 file header compared to this small too much. FLV metadata stores the media information for the entire video file, including the author, video width, length, keyframe list, etc., which are of course important for parsing video files, but unfortunately, because the metadata of FLV is optional, So there are a lot of flv do not metadata, and even if there is, the information in its metadata is not correct, which leads to metadata is very untrustworthy. Therefore, when parsing flv, the FLV metadata part should be ignored and the corresponding media information can be obtained by traversing all the tags of the FLV.

Third, the programme

On-demand system implementation, there are several key points, the most important should be "play network stream" and "drag" the two points. Among them, about "drag", because the whole system is based on the network, the client after the drag, you must re-send the server-side request, the server based on the client's drag request, find the closest drag point , return the data stream can play, thus complete on-demand drag.

For FLV, because of its simple format, the head is very small, and metadata can not, so only need to find the key frame, and then spell the FLV Header, you can form a playable video file. As shown in the following:

According to the features of the FLV format and the method of generating new playable files after dragging, the FLV on-demand system can be designed as follows:

1. Server-side

First, parse the FLV file to generate a list of FLV video keyframes, indicating the correspondence between time and the inexpensive amount. Then, when receiving the data request from the client, according to the point-in-time request of the client, find out the closest keyframe, according to the offset, read the FLV file data, and then splice the FLV 9-byte file header (plus 4 bytes of all zeros of the pre tag size, a total of 13 bytes) Return.

2. Client

The client needs to be particularly aware that, in addition to correctly parsing the video stream and playing it, you need to be careful about the timeline, because the time position that the user drags is not necessarily a keyframe, so you need to reposition the playback progress based on the actual time of the keyframe returned by the server.

Iv. Realization OF

The server can be implemented as an HTTP server, only need to provide HTTP download, before responding to the download, need to complete the previously described logic. Can be fully implemented, you can directly use the existing mature Web server, if the performance requirements are high, strongly recommend Nginx, with the help of nginx powerful processing performance, through the implementation of their own Nginx module, you can complete all your needs.

Client player, for less familiar with the player development technology, can be based on LIBVLC, with the help of VLC good network playing ability, basically can meet the needs.

Here is a demo program that was made a few days ago,

------------------------------------------------------------

Reprint please indicate the author and source, thank you ~

How to implement an FLV video-on-demand system with C/s mode

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.