当前位置:网站首页>王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(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的内容的算法
边栏推荐
- 【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
- Summary of tensorflow installation stepping on the pit
- Existing in the rain of PFAS chemical poses a threat to the safety of drinking water
- Lithium battery technology
- 面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优
- In the second half of 2012 system architecture designers afternoon paper II
- mysql进阶(三十三)MySQL数据表添加字段
- 高数_证明_弧微分公式
- 强意识 压责任 安全培训筑牢生产屏障
- Vivado crashes or the message is not displayed
猜你喜欢
符合信创要求的堡垒机有哪些?支持哪些系统?
Classifying irises using decision trees
Error: Rule can only have one resource source (provided resource and test + include + exclude)
第五讲 测试技术与用例设计
AWS 安全基础知识
laravel throws the error to Dingding
使用决策树对鸢尾花进行分类
Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
系统的安全和应用(不会点安全的东西你怎么睡得着?)
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
随机推荐
numpy.meshgrid()理解
file system design
公网IP和内网IP的区别[通俗易懂]
PHP judges whether the file has content, and if there is no content, copy another file to write
ICML 2022 | 基于随机注意力机制的可解释可泛化图学习
List集合
OpenStack-related commands that need to be recorded _ self-use
WebView的优化与常见问题解决方案
高数_证明_曲率公式
日志@Slf4j介绍使用及配置等级
进程和计划任务管理
A unit test report for CRM One Order Application log
指针(C语言初解)
【剑指offer】---数组中的重复数字
YTU 2295: KMP pattern match one (string)
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
laravel 抛错给钉钉
写不完的数学试卷-----试卷生成器(Qt含源码)