Research on iOS streaming media based on the IJKPlayer framework of site B
1. Streaming Media
Streaming Media Technology can be divided into progressive download and implementation of streaming media.
1. Progressive download
It is a playback mode between real-time playback and local playback. incremental download does not have to wait until all the downloads are completed before playing. You can download and play the video. After playing, the entire file is saved. The user experience shows that incremental download is no different from Real-Time Streaming Media, but incremental download retains files locally. The following describes the differences between the progressive download development API and the local playback API. You can use MediaPlayerController and MediaPlayerViewController in the MediaPlayer framework for playback, you can also use AVPlayer in the AVFoundation framework for playback. There is an Apache HTTP Server in mac OS. First, open the service and run the command line: sudo apachectl-v enter the password, and then enter sudo apachectl start. Then, put the file to be played under/Library/WebServer/documents.
2. Real-Time Streaming Media
Real-Time Streaming Media is played while receiving data packets. Local files are not retained, and data is always transmitted in real time. Users can fast forward and return. However, Real-Time Streaming Media Playback must ensure that the transmission speed of data packets is higher than the playback speed of files; otherwise, the playback effect is affected.
Real-Time Streaming Media transmission protocols include RTSP, HLS, and MMS. HLS is proposed by Apple. It only requests basic HTTP packets. Unlike RTSP and MMS, HLS can pass through any firewall that allows HTTP data to pass through. In addition, HLS has no special requirements on the server, as long as it can provide HTTP Services.
HLS solution: first through the audio or video acquisition equipment to collect data, and then the data is transmitted to the Server to encode the audio or video, encoding requires the use of MPEG-2 format, after the encoding is complete, use the media file separation tool to split the files, and then publish the split files and their index files to the Publishing Server. Then the client can access them.
Ii. HLS
HTTP Live Streaming (HLS) is Apple Inc .) the HTTP-based streaming media transmission protocol enables live and on-demand streaming media. It is mainly used in iOS systems and provides audio and video live and on-demand solutions for iOS devices (such as iPhone and iPad. Hls vod is basically a common multipart http vod. The difference is that its segmentation is very small. To implement HLS on-demand, the focus is on the segmentation of media files. Currently, many open-source tools are available. I will not discuss it here. I will only talk about HLS live broadcast technology.
HLS implementation principle
VczlzsS8/users + 1xM/users + o6zS8s6qt/users + users/7O8cb3u/users + o6y + users/ybz7o6y7 + bG + yc +/ydLUyM/users + keys/Nu6e2y7/J0tS63L/keys + 3M9bz + keys/keys + DQo8cD64 + keys/LXjPC9wPg0KPHA + keys/b7dPGJyIC8 + keys/keys + keys + 3bfi17DOqk1QRUctVFOw/dxiciavpg0kkdq1_xtt9a2zsn6s8my38luvlbtm3u4y/fS/blank = "Three streaming media solutions based on B station ijkplayer framework"> 3. ijkplayer framework of B-station-based Streaming Media Solution
Recently, I am paying attention to the live streaming media. After the ijkplayer framework of Site B recommended by the Technical leader, I started a difficult journey ......
(1) The first step is to download the open-source ijkplayer framework of Site B from github.
(2) follow the instructions to perform various operations before compilation. In fact, it is not difficult to take three steps.
Note:Annotations with # numbers are not required in the console.
Step 1:Set up the runtime environment (ruby, home-brew, git, yams, and other environments are required). Open the terminal and input the following statements without starting.
# Install homebrew, git, yasm
Ruby-e "$ (curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"
Brew install git
Brew install yasm
# Add these lines to your ~ /. Bash_profile or ~ /. Profile # export ANDROID_SDK = # export ANDROID_NDK = # on Cygwin (unmaintained) # install git, make, yams
Step 2:Clone the ijkplayer project to a local machine and integrate ffmpeg into ijkplayer (this step is time-consuming and requires patience). Enter the following command on the terminal ..
Git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
Cd ijkplayer-ios
Git checkout-B latest
/Init-ios.sh
Cd ios
./Compile-ffmpeg.sh clean
./Compile-ffmpeg.sh all
Step 3:Open IJKMedioDemo In the ios file under ijkplayer-iOS
The following two official sentences mean to import IJKMediaPlayer to your project.
# Import ios/IJKMediaPlayer for MediaPlayer. framework-like interface (recommended) # open ios/IJKMediaDemo. xcodeproj with Xcode
Drag the IJKMediaPlayer to the file.
In this way, you can open the demo sample program officially provided.
Running:
The above is an official demo, which can be implemented by many functions in the demo. The question is, how can I integrate IJKPlayer into my own project? I encountered a lot of difficulties in integration ......
Integrate ijkplayer into your project:
Create your own project:
Step 1:Add the IJKMediaFrameWork. framework static library and IJKMediaPlayer to the project file.
Second, no:Open the project to add the two files to the home directory, and then open Build Phases to add the following libraries
This is perfect, and you can easily and happily develop streaming media ........
Iv. M3U8
What is M3U8?
M3U8 files are M3U files in UTF-8 encoding format. The M3U File records an indexed text file. When it is opened, the playing software does not play it, but finds the network address of the corresponding audio/video file based on its index for online playback.
M3U File labels and attributes
The M3U file can contain multiple tags. The functions and attributes of each tag are as follows:
# EXTM3U
This tag must be the first line of each M3U File.
# EXT-X-MEDIA-SEQUENCE: 140651513
Each media URI only has a unique sequence number in PlayList. The number of adjacent media Uris is plus 1. A media URI is not required to be included. If not, the default value is 0.
# EXTINF :,
Duration specifies the duration (in seconds) of each media segment (ts), which is only valid for the URI following it. title is the url of the download resource.
# EXT-X-TARGETDURATION
Specifies the maximum media segment length (in seconds ). Therefore, the time length specified in # EXTINF must be smaller than or equal to the maximum value. This tag can only appear once in the entire PlayList file (in the case of nesting, m3u8 with a real ts url will usually appear)
# EXT-X-KEY
Indicates how to decode media segments. It applies to all media Uris before the next occurrence of the tag, with the property NONE or AES-128. NONE indicates that the URI and IV (Initialization Vector) properties must not exist, the AES-128 (Advanced EncryptionStandard) indicates that the URI must exist, and the IV can not exist.
For the AES-128, The keytag and URI attributes represent a key file, which can be obtained through URI. If there is no IV (Initialization Vector), the serial number is used as the IV encoding and decoding, assign a high value of the serial number to the buffer of 16 bytes, and add 0 to the left. If there is IV, the value is changed to the hexadecimal number of 16 bytes.
# EXT-X-PROGRAM-DATE-TIME
Associate an absolute time or date with the first sample in a media segment, valid only for the next meida URI, in the format of # EXT-X-PROGRAM-DATE-TIME:
For example: # EXT-X-PROGRAM-DATE-TIME: 2010-02-19T14: 54: 23.031 + 08: 00
# EXT-X-ALLOW-CACHE
Whether to enable cache. This can appear anywhere in the PlayList file and can appear at most once. The effect is on all media segments. Format: # EXT-X-ALLOW-CACHE:
# EXT-X-PLAYLIST-TYPE
Provides information about the variability of PlayList, which is valid for the entire PlayList file and optional in the following format: # EXT-X-PLAYLIST-TYPE: If it is VOD, the server cannot change the PlayList file; if it is an EVENT, the server cannot change or delete any part of the PlayList file, but you can add a new row to the file.
# EXT-X-ENDLIST
It indicates the end of PlayList, which can appear at any position in PlayList, but only one, the format is as follows: # EXT-X-ENDLIST
# EXT-X-MEDIA
It is used to represent versions without languages/translations of the same content in PlayList. For example, three tags can be used to represent audios not used in 3, alternatively, you can use two tags to indicate that videos of different angles are in PlayLists. This tag exists independently and has the following attributes:
URI: if not, it indicates that the selectable version of the tag description exists in the EXT-X-STREAM-INF of the primary PlayList;
TYPE: AUDIO and VIDEO;
GROUP-ID: MEDIAtag with the same ID, forming a GROUP of styles;
LANGUAGE: determine the main LANGUAGE used
NAME: Translation of human readable languages
DEFAULT: YES or NO. The DEFAULT value is No. If YES, the client uses this option to play the video unless you select it.
AUTOSELECT: YES or NO. The default value is No. If YES, the client selects the value based on the current playback environment (the user does not select the value based on his/her preference ).
# EXT-X-STREAM-INF
Specify a media URI containing multimedia information as PlayList, generally used for M3U8 nesting, it is only effective for followed by the URI, the format is as follows: # EXT-X-STREAM-INF: has the following attributes:
BANDWIDTH: Required BANDWIDTH.
PROGRAM-ID: this value is a decimal integer that uniquely identifies a specific description within the PlayList file range. A PlayList file may contain multiple tags with the same ID.
CODECS: not required.
RESOLUTION: RESOLUTION.
AUDIO: This value must match the GROUP-ID attribute value in the EXT-X-MEDIA tab of the AUDIO category.
VIDEO: Same as above