Zoozy |
NULL
Zoozy 最近回复了
| 回复了 shuaijinchao 创建的主题 › 一行代码,让 Claude Code / Gemini / Codex 接入任意 LLM4 月 20 日 |
支持一个
| 回复了 wodong 创建的主题 › 大疆 PSDK 获取视频流技术求助2023 年 4 月 14 日 |
在这个函数中,您需要使用 RTMP 协议将 H264 编码的裸流数据推送到 RTMP 服务器上,以便在视频播放器中显示。
以下是可能的实现方式:
```c++
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <sstream>
#include "librtmp/rtmp.h"
#define RTMP_HEAD_SIZE (sizeof(RTMPPacket)+RTMP_MAX_HEADER_SIZE)
static void LiveviewConvertH264ToRgbCallback(E_DjiLiveViewCameraPosition position, const uint8_t* buf, uint32_t bufLen) {
static RTMP *rtmp = NULL;
static char *url = "rtmp://your-rtpm-server-url.com/live/stream";
static int fps = 30;
static int width = 1280;
static int height = 720;
if (!rtmp) {
rtmp = RTMP_Alloc();
RTMP_Init(rtmp);
rtmp->Link.timeout = 5; // Timeout in seconds
RTMP_SetupURL(rtmp, url);
RTMP_EnableWrite(rtmp);
RTMP_SetBufferMS(rtmp, 3600*1000); // Set the buffer size to 1 hour
if (!RTMP_Connect(rtmp, NULL) || !RTMP_ConnectStream(rtmp, 0)) {
RTMP_Free(rtmp);
rtmp = NULL;
std::cerr << "Failed to connect to RTMP server" << std::endl;
return;
}
}
// Create and initialize RTMP packet
RTMPPacket packet = {0};
RTMPPacket_Alloc(&packet, bufLen + RTMP_HEAD_SIZE);
packet.m_packetType = RTMP_PACKET_TYPE_VIDEO;
packet.m_nChannel = 0x04;
// Fill in the packet headers
char *data_ptr = packet.m_body;
data_ptr[0] = 0x17; // Video codec id: 7 (AVC)
data_ptr[1] = 0x01; // AVCPacketType: 1 (NALU without length field)
*((uint32_t *)(data_ptr + 2)) = 0x01000000; // Composition time offset: 0
std::memcpy(data_ptr + 6, buf, bufLen);
packet.m_nTimeStamp = RTMP_GetTime() - RTMP_GetStartTime(rtmp);
packet.m_nBodySize = bufLen + 5;
if (!RTMP_SendPacket(rtmp, &packet, TRUE)) {
std::cerr << "Failed to send packet to RTMP server" << std::endl;
}
// Free memory used by packet
RTMPPacket_Free(&packet);
}
```
在此实现中,我们使用 librtmp 库来完成 RTMP 协议的推流。在函数中的第一个参数 position 未被使用,因为它不需要对这个问题产生任何影响。
该代码假定你已经熟练掌握了 RTMP 协议和使用方法,并且服务器配置正确。
by gpt
以下是可能的实现方式:
```c++
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <sstream>
#include "librtmp/rtmp.h"
#define RTMP_HEAD_SIZE (sizeof(RTMPPacket)+RTMP_MAX_HEADER_SIZE)
static void LiveviewConvertH264ToRgbCallback(E_DjiLiveViewCameraPosition position, const uint8_t* buf, uint32_t bufLen) {
static RTMP *rtmp = NULL;
static char *url = "rtmp://your-rtpm-server-url.com/live/stream";
static int fps = 30;
static int width = 1280;
static int height = 720;
if (!rtmp) {
rtmp = RTMP_Alloc();
RTMP_Init(rtmp);
rtmp->Link.timeout = 5; // Timeout in seconds
RTMP_SetupURL(rtmp, url);
RTMP_EnableWrite(rtmp);
RTMP_SetBufferMS(rtmp, 3600*1000); // Set the buffer size to 1 hour
if (!RTMP_Connect(rtmp, NULL) || !RTMP_ConnectStream(rtmp, 0)) {
RTMP_Free(rtmp);
rtmp = NULL;
std::cerr << "Failed to connect to RTMP server" << std::endl;
return;
}
}
// Create and initialize RTMP packet
RTMPPacket packet = {0};
RTMPPacket_Alloc(&packet, bufLen + RTMP_HEAD_SIZE);
packet.m_packetType = RTMP_PACKET_TYPE_VIDEO;
packet.m_nChannel = 0x04;
// Fill in the packet headers
char *data_ptr = packet.m_body;
data_ptr[0] = 0x17; // Video codec id: 7 (AVC)
data_ptr[1] = 0x01; // AVCPacketType: 1 (NALU without length field)
*((uint32_t *)(data_ptr + 2)) = 0x01000000; // Composition time offset: 0
std::memcpy(data_ptr + 6, buf, bufLen);
packet.m_nTimeStamp = RTMP_GetTime() - RTMP_GetStartTime(rtmp);
packet.m_nBodySize = bufLen + 5;
if (!RTMP_SendPacket(rtmp, &packet, TRUE)) {
std::cerr << "Failed to send packet to RTMP server" << std::endl;
}
// Free memory used by packet
RTMPPacket_Free(&packet);
}
```
在此实现中,我们使用 librtmp 库来完成 RTMP 协议的推流。在函数中的第一个参数 position 未被使用,因为它不需要对这个问题产生任何影响。
该代码假定你已经熟练掌握了 RTMP 协议和使用方法,并且服务器配置正确。
by gpt
| 回复了 honglei92 创建的主题 › 华为 账号服务 获取 token https://oauth-login.cloud.huawei.com/oauth2/v3/token2020 年 5 月 27 日 |
"hms://redirect_url"
| 回复了 yellowmarlboro 创建的主题 › 有个只返回请求的 ip 地址信息的网站(很干净那种), 有没有人知道?2018 年 12 月 21 日 |
curl ip.sb
| 回复了 mercurylanded 创建的主题 › 七牛又挂了,这个月第二次了。北京联通。2018 年 5 月 22 日 |
已经两个小时了 售后 VIP 群没人理 服气
| 回复了 koor 创建的主题 › 京东自营 48 小时还没收到,什么情况!!2017 年 6 月 13 日 |
@ArthurKing 请原谅我。。笑出声。。。。
| 回复了 carrieflint 创建的主题 › Flint OS for PC 发布第二个公测版本,欢迎下载体验,狠狠吐槽!2017 年 3 月 17 日 |
如果可以的话能说说 toB 怎么盈利的吗?
