Video streaming technology for iOS push-to-stream

Source: Internet
Author: User

with the development of network infrastructure and the decline of tariff, in this era of content consumption upgrade, text, pictures can not meet the needs of people's vision, so video broadcast came into being. Live streaming cloud services that host real-time real-time and interactivity are the new drivers of live coverage across all walks of life. NetEase Cloud Letter launched a series of articles on the video broadcast technology in-depth explanation, this article will introduce you to the iOS side of the push stream technology.

Related reading recommendations

theLive Video:Summary of interception and synthesis methods for various kinds of screen sources in Windows"《Key technologies for video streaming: fluency, congestion and delayed catch -up》

Short video Technology :The development of short videos on the Android side

Live architecture

People who must have known the live stream are well aware that the live stream is divided into 3 parts: Streaming media server, push flow, and so on.

And what we need to talk about today is the push-flow section, which mainly includes audio and video capture, audio and video pre-processing, audio and video coding, push-stream and transmission 4 aspects. However, due to the complexity of the network and statistics of big data, the push stream also needs to have global load balancing dispatch GSLB (Global server load Balance), as well as the real-time statistical data escalation server, including providing channel management to the user operation, so the push-stream SDK needs to access GSLB Center scheduling , statistics server, heartbeat server, is used to push stream distribution to the best nodes of the network, with big data statistics and analysis.

Covers all the services related to the live broadcast, the red small line represents the direction of instruction flow, the green small standard line represents the data flow.

Live Technology points

Audio and video capture

Acquisition is the first ring in all links, and we use the system-native framework avfoundation to capture data. Capture video data via the iphone camera (avcapturesession) and capture audio data through a microphone (audiounit). At present, the video collection source mainly comes from the camera acquisition, screen recording (Replaykit), reading the push stream from the video file.

Both audio and video support parameter configuration. Audio can set sample rate, number of channels, frame size, audio bitrate, whether external acquisition is used, whether external audio pre-processing is used, video can set frame rate, bitrate, resolution, front and rear camera, camera acquisition direction, video side display ratio, whether to turn on camera flash, whether to turn on camera response zoom, Whether to mirror the front camera preview, whether to mirror the front camera encoding, whether to turn on the filter function, filter type, whether to turn on watermark support, whether to turn on QoS features, whether to output RGB data, whether to use external video capture.

Audio and video Processing

The pre-processing module is also the main link of subjective influence on the host's viewing effect. At present, the iOS side is more well-known is gpuimage, provides the rich preprocessing effect, we also on this basis carried on the encapsulation development. Video pre-processing includes filters, beauty, watermarks, graffiti and other functions, while in the face recognition and special effects connected to the third-Party vendor Faceu. SDK built-in 4 filters black and white, natural, matte, nostalgic, support 16:9 cropping, support grinding Piete (Gaussian blur plus edge detection), support static watermark, dynamic watermark, graffiti and other functions. Audio pre-processing includes echo suppression, acoustic noise, gain control, and so on. Audio and video support external pre-processing.

Audio and Video coding

The two main difficulties of coding are:

1 Handling hardware compatibility issues

2 Find a balance between high fps, low bitrate, and sound quality.

Because iOS hardware compatibility is better, you can use hard-coding. SDK currently supports software coding openH264, hardware encoding videotoolbox. and the audio Support software encoding FDK-AAC and hardware encoding audiotoolbox.

The core idea of video coding is to remove redundant information:

Spatial redundancy: There is a strong correlation between image neighboring pixels.

Time redundancy: The content is similar between adjacent images of a video sequence.

Coding redundancy: Different pixel values appear in different probabilities.

Visual redundancy: The human visual system is insensitive to certain details.

Audio and video transmission

The streaming media protocol used by the push Stream SDK is rtmp (RealTime Messaging Protocol). The most difficult thing about audio and video transmission is the bandwidth assessment for the network. Because of the complexity of the network from the live to the RTMP server, especially in the 3G and the low-bandwidth WiFi environment, network drops, jitter and latency often occur, resulting in a poor live push stream. RTMP based on TCP transmission, TCP itself to achieve the network congestion under the processing, the internal mechanism is more complex, and the developer is not visible, developers can not be based on the TCP protocol information to determine the network situation, resulting in the transmission code rate is greater than the actual network bandwidth, resulting in more severe network congestion. Therefore, we have developed a real-time QoS algorithm based on network changes, for real-time adjustment of bitrate, frame rate, resolution, and real-time data reporting to the statistical platform.

Module Design & Threading Model

Module design

Since the mainstream of the push stream is divided into 4 parts described above: Audio and video capture, audio and video pre-processing, audio and video coding, audio and video transmission. Therefore, the push-flow SDK module is divided into lsmediacapture layer (external api+ server interaction), Video Fusion module (video capture + video pre-processing), Audio Fusion module (audio acquisition + audio pre-processing), basic service module, audio and video coding module, network sending module.

Threading model

The push-stream SDK contains a total of 10 threads. The video contains the original collection thread of the avcapturesession, the pre-processing thread, the hardware encoding thread, the data flow definition of the acquisition thread, the encoding thread, and the send thread. The audio contains the original collection thread that the AudioUnit contains, the data flow definition of the acquisition thread, the encoding thread, and the send thread. 2 Bufferqueue are created between the data flow definition collection thread, the encoding thread, and the sending thread to cache the audio and video data. The acquisition coding queue can effectively control the coding rate, and the coded send queue can effectively adapt to the network push stream.

qos& Skip Frame

is the main stream of live, user initialization SDK, create thread, start live, audio and video data collection, encode, send. In the sending thread, audio and video data transmission, QoS on, based on the network real-time evaluation of bandwidth, adjust frame rate, Code rate control encoder parameters, while triggering the skip frame, adjust the resolution control acquisition resolution parameters. The user stops the live stream, initializes the SDK, and destroys the thread. qos& jump frame can effectively solve the problem of the user in the network bad situation, the live video lag. In different bitrate and resolution conditions, can be done to allow users to watch the video stream smoothly.

The above is a detailed explanation of the iOS push-stream technology.

In addition, want to read more about the video broadcast technology articles, you can take a look at the netease Cloud Letter Blog .

NetEase Cloud (neteaseyunxin) is a PAAs service product built by NetEase 18 IM and Audio video technology, which is based on the communication and video cloud service of NetEase's core technical architecture, which is stable, easy-to-use and full-featured, and is committed to providing global leading technology capability and scene solution. Developers can quickly implement features such as IM, audio and video calling, live, on-demand, interactive whiteboard, text messaging, and more with the Integrated Client SDK and cloud open API.

Video streaming technology for iOS push-to-stream

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.