当前位置:网站首页>王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(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的内容的算法
边栏推荐
- vivado闪退或者message无显示
- How to describe multiple paragraphs with different font settings in Open Office XML format
- [219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
- file system design
- SenseTime self-developed robotic arm, the first product is an AI chess-playing robot: Guo Jingjing is also invited as an endorsement
- C# error The 'xmins' attribute is not supported in this context
- PHP 判断文件是否有内容,没有内容则复制另一个文件写入
- 如何完成新媒体产品策划?
- IT小白怎么系统的php学习
- 八大排序总是忘?快来这里~
猜你喜欢

什么?你还不会JVM调优?

Error: Rule can only have one resource source (provided resource and test + include + exclude)

laravel 抛错给钉钉

Short read or OOM loading DB. Unrecoverable error, aborting now

Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth

MySQL interview questions

List集合
WebView的优化与常见问题解决方案

记录几道整型提升的题目

AWS 安全基础知识
随机推荐
CodeForces-834C
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
numpy.meshgrid()理解
Matlab画分段函数「建议收藏」
How is the monthly salary table stored in the database?Ask for a design idea
win2012安装Oraclerac失败
第三方软件测评有什么作用?权威软件检测机构推荐
【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
1004(树状数组+离线操作+离散化)
什么?你还不会JVM调优?
注意力模型---Attention Model
A method that can make large data clustering 2000 times faster
MySQL interview questions
强意识 压责任 安全培训筑牢生产屏障
串口服务器调试助手使用教程,串口调试助手使用教程【操作方式】
Borg Maze (bfs+最小生成树)
作业8.9 构建TCP协议的服务器
C#实现访问OPC UA服务器
Error: Rule can only have one resource source (provided resource and test + include + exclude)
file system design