当前位置:网站首页>王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)
王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)
2022-08-10 14:12:00 【qczg_wxg】
RTMP简介
1,从摄像头得到数据不能直接推到直播服务器,需要编码成h264或h265。
2,影响数据量最大的因素是帧率。音视频直播帧率是很低的。以腾讯直播为例,只有15帧。
3,直播秒开:第一,减少I帧的间隔时间;第二,降低帧率;第三:GOP(两个I帧之间)缓存, 服务端缓存一个最新的GOP。
4,RTMP协议,帮助服务端更好的分发给各个客户端,并且服务器不需要解码h264(h264解码非常消耗资源)。RTMP是用来推流的,从直播推到服务器。
5,RTMP有三种帧类型:1,sps/pps;2,I帧;3,b帧和p帧。
6,第一个字节无法区分关键帧和sps/pps帧,需要借助第二个字节。
7,4字节数据长度:长度存放四个字节,服务器读取这四个字节就可以,不需要读到下一个分割符就知道I帧的长度。这样I帧就传到服务器了。
8,非关键帧(b/p)与关键帧(I)传输同理.
9,sps与pps。因为长度小,存储长度只需要两个字节。上图下半部分说明。
10,RTMP不解析内容只是方便转发。客户端接收到的数据(从服务器来)不是我们推的数据,而是标准的h264。
11,回顾sps
64代表编码等级。
64
15
代码(26节课)
1,native工程。服务器不需要自己搭建,我们用哔哩哔哩的直播服务器。数据源就用录屏的。
2,录屏代码略,前面有录屏代码。
3,我们不可能去手写RTMP协议。联想http协议,我们用httpurlconnection去添加请求头,请求方式等。Rtmpdump就是Rtmp协议的httpurlconnection。
4,Rtmpdump最新的版本是2010年。地址
我们下载最新的
5,录制的时候,sps/pps只会编码一次。编码的内容并不是要发送的内容。要经过处理。
6,我们架构分为编码层和传输层,编码层编码出来的h264数据包直接丢给传输层会出现两种情况,编码快,发送慢,造成卡顿。编码慢发送快造成网络资源浪费。
因为编码层与传输层的速率不一致,所以我们使用队列,也就是生产者模式和消费者模式,编码出来的数据我们丢给队列。传输层从队列取数据。
这是我们的数据包
package com.maniu.rtmpbibili;
public class RTMPPackage {
// 帧数据
private byte[] buffer;
// 时间戳
private long tms;
public RTMPPackage(byte[] buffer, long tms) {
this.buffer = buffer;
this.tms = tms;
}
public byte[] getBuffer() {
return buffer;
}
public void setBuffer(byte[] buffer) {
this.buffer = buffer;
}
public long getTms() {
return tms;
}
public void setTms(long tms) {
this.tms = tms;
}
}
哔哩哔哩直播服务器地址
传输层ScreenLive。
native层
把下载的压缩包解压,把librtmp放到cpp里
在librtmp中 创建CMAKELIST.txt文件
#关闭ssl 不支持rtmps rtmp 加密 传递一变量 进制 加密验证
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_CRYPTO" )
file(GLOB rtmp_source *.c)#要编译的文件,把.c文件赋值给rtmp_source变量。GLOB代表定义全局变量
add_library(rtmp123
STATIC
${rtmp_source})
在系统创建的CMAKELIST中引用我们自己创建的
cmake_minimum_required(VERSION 3.4.1)
add_subdirectory(librtmp)#添加整个目录,在这里查找rtmp
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp )
#从系统目录中查找叫log的库,查找后把log赋值给log-lib中的变量
find_library( # Sets the name of the path variable.
log-lib
log )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
rtmp123)#因为已经添加了目录,所以这里可以查找到我们自己创建的。
API使用流程
sps 与pps的内容的算法
边栏推荐
- YTU 2295: KMP pattern match one (string)
- [Study Notes] Persistence of Redis
- PHP judges whether the file has content, and if there is no content, copy another file to write
- Unfinished mathematics test paper ----- test paper generator (Qt includes source code)
- [JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
- IT小白怎么系统的php学习
- SecureCRTPortable – 破解
- WebView的优化与常见问题解决方案
- “Oracle 封禁了我的账户”
- 【POI 2008, BLO】割点
猜你喜欢
随机推荐
WebView的优化与常见问题解决方案
2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn
[219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
How is the monthly salary table stored in the database?Ask for a design idea
快速了解大端模式和小端模式
注意力模型---Attention Model
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
使用决策树对鸢尾花进行分类
串口服务器调试助手使用教程,串口调试助手使用教程【操作方式】
Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
作业8.9 构建TCP协议的服务器
【MinIO】Using tools
Matlab画分段函数「建议收藏」
Calculate the number of combinations recursively
Open source SPL wipes out tens of thousands of database intermediate tables
Fragment-hide and show
普林斯顿微积分读本05第四章--求解多项式的极限问题
字节终面:CPU 是如何读写内存的?
In the second half of 2012 system architecture designers afternoon paper II