- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道可以使用 Wireshark 和 VLC 保存 RTP h264 流。但为了更多地了解视频流,我正在尝试自己做。有几个相关的问题可以很好地阅读这个主题:
How to process raw UDP packets so that they can be decoded by a decoder filter in a directshow source filter
Problem to Decode H264 video over RTP with ffmpeg (libavcodec)
How to convert H.264 UDP packets to playable media stream or file (defragmentation)
以这些为背景,这就是我目前所处的位置:
最佳答案
见 How to process raw UDP packets so that they can be decoded by a decoder filter in a directshow source filter
它有你需要的答案,但过程是这样的:
//Determine if the forbidden bit is set and the type of nal from the first byte
byte firstByte = packetData[offset];
//bool forbiddenZeroBit = ((firstByte & 0x80) >> 7) != 0;
byte nalUnitType = (byte)(firstByte & Common.Binary.FiveBitMaxValue);
//o The F bit MUST be cleared if all F bits of the aggregated NAL units are zero; otherwise, it MUST be set.
//if (forbiddenZeroBit && nalUnitType <= 23 && nalUnitType > 29) throw new InvalidOperationException("Forbidden Zero Bit is Set.");
//Determine what to do
switch (nalUnitType)
{
//Reserved - Ignore
case 0:
case 30:
case 31:
{
return;
}
case 24: //STAP - A
case 25: //STAP - B
case 26: //MTAP - 16
case 27: //MTAP - 24
{
//Move to Nal Data
++offset;
//Todo Determine if need to Order by DON first.
//EAT DON for ALL BUT STAP - A
if (nalUnitType != 24) offset += 2;
//Consume the rest of the data from the packet
while (offset < count)
{
//Determine the nal unit size which does not include the nal header
int tmp_nal_size = Common.Binary.Read16(packetData, offset, BitConverter.IsLittleEndian);
offset += 2;
//If the nal had data then write it
if (tmp_nal_size > 0)
{
//For DOND and TSOFFSET
switch (nalUnitType)
{
case 25:// MTAP - 16
{
//SKIP DOND and TSOFFSET
offset += 3;
goto default;
}
case 26:// MTAP - 24
{
//SKIP DOND and TSOFFSET
offset += 4;
goto default;
}
default:
{
//Read the nal header but don't move the offset
byte nalHeader = (byte)(packetData[offset] & Common.Binary.FiveBitMaxValue);
if (nalHeader > 5)
{
if (nalHeader == 6)
{
Buffer.WriteByte(0);
containsSei = true;
}
else if (nalHeader == 7)
{
Buffer.WriteByte(0);
containsPps = true;
}
else if (nalHeader == 8)
{
Buffer.WriteByte(0);
containsSps = true;
}
}
if (nalHeader == 1) containsSlice = true;
if (nalHeader == 5) isIdr = true;
//Done reading
break;
}
}
//Write the start code
Buffer.Write(NalStart, 0, 3);
//Write the nal header and data
Buffer.Write(packetData, offset, tmp_nal_size);
//Move the offset past the nal
offset += tmp_nal_size;
}
}
return;
}
case 28: //FU - A
case 29: //FU - B
{
/*
Informative note: When an FU-A occurs in interleaved mode, it
always follows an FU-B, which sets its DON.
* Informative note: If a transmitter wants to encapsulate a single
NAL unit per packet and transmit packets out of their decoding
order, STAP-B packet type can be used.
*/
//Need 2 bytes
if (count > 2)
{
//Read the Header
byte FUHeader = packetData[++offset];
bool Start = ((FUHeader & 0x80) >> 7) > 0;
//bool End = ((FUHeader & 0x40) >> 6) > 0;
//bool Receiver = (FUHeader & 0x20) != 0;
//if (Receiver) throw new InvalidOperationException("Receiver Bit Set");
//Move to data
++offset;
//Todo Determine if need to Order by DON first.
//DON Present in FU - B
if (nalUnitType == 29) offset += 2;
//Determine the fragment size
int fragment_size = count - offset;
//If the size was valid
if (fragment_size > 0)
{
//If the start bit was set
if (Start)
{
//Reconstruct the nal header
//Use the first 3 bits of the first byte and last 5 bites of the FU Header
byte nalHeader = (byte)((firstByte & 0xE0) | (FUHeader & Common.Binary.FiveBitMaxValue));
//Could have been SPS / PPS / SEI
if (nalHeader > 5)
{
if (nalHeader == 6)
{
Buffer.WriteByte(0);
containsSei = true;
}
else if (nalHeader == 7)
{
Buffer.WriteByte(0);
containsPps = true;
}
else if (nalHeader == 8)
{
Buffer.WriteByte(0);
containsSps = true;
}
}
if (nalHeader == 1) containsSlice = true;
if (nalHeader == 5) isIdr = true;
//Write the start code
Buffer.Write(NalStart, 0, 3);
//Write the re-construced header
Buffer.WriteByte(nalHeader);
}
//Write the data of the fragment.
Buffer.Write(packetData, offset, fragment_size);
}
}
return;
}
default:
{
// 6 SEI, 7 and 8 are SPS and PPS
if (nalUnitType > 5)
{
if (nalUnitType == 6)
{
Buffer.WriteByte(0);
containsSei = true;
}
else if (nalUnitType == 7)
{
Buffer.WriteByte(0);
containsPps = true;
}
else if (nalUnitType == 8)
{
Buffer.WriteByte(0);
containsSps = true;
}
}
if (nalUnitType == 1) containsSlice = true;
if (nalUnitType == 5) isIdr = true;
//Write the start code
Buffer.Write(NalStart, 0, 3);
//Write the nal heaer and data data
Buffer.Write(packetData, offset, count - offset);
return;
}
关于networking - 以有用的形式保存 H264 RTP 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24670366/
当我开始学习一门新语言时,我总是觉得我没有以实用、标准的方式进行学习。所以这里有一个关于 jQuery 的问题以及我所做的是否可以接受。 我有 3 张图片。 然后我让 jQuery 检测 $('
基本上,我想知道线程是否有用或必要,或者可能更具体地说,您将使用它的用途和情况。我对线程了解不多,也从未使用过它(我主要使用 C#),并且想知道如果使用它们是否会提高性能或稳定性。如果有人愿意解释一下
这个问题在这里已经有了答案: What is The Rule of Three? (8 个答案) 关闭 7 年前。 嘿嘿。我有一个让我很难过的问题。我自定义了一个普通的拷贝构造函数但它只在我初始化
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: Uses for multiple levels of pointer dereferences? 我在 C
我不确定异常在每种语言中的工作方式是否相同,但我使用的是 PHP,我想知道我什么时候做这样的事情: if (!$this->connection[0]->query($this->query)) t
Scala native 是最近发布的,但是他们(现在)使用的垃圾收集器非常rudimentary,因此不适合严肃使用。 所以我想知道:为什么不只将Scala转换为Go (即Scala.js)?这将是
最近,我一直在研究docker及其对SaaS公司的有用性。我花了一些时间学习如何容器化应用程序,并简要了解了什么是docker和容器。我在理解这项技术的实用性时遇到了一些问题。我看过dockercon
我必须根据出现在它们之前的字符串是否是某个关键字“load”从输入文件中读取整数。没有关键数字告诉我们要输入多少个数字。这些数字必须保存到一个数组中。为了避免为扫描的每个附加数字创建和更新新数组,我想
Deferred 对象具有回调池 doneCallbacks、failCallbacks 和 progressCallbacks。 doneCallbacks 和 failCallbacks(以及方法
这个问题在这里已经有了答案: Is there a case where including the same header twice is actually helpful? (6 个答案) 关
我在C++ Programming Language的书上看到了下面的例子 class Ptr { X* operator->( ); }; voide f(Ptr p) { p-
你能不能: template const T &operator[] (unsigned int x) 我的想法是如果你有一个 map如果有一个包装器类可以让您这样做,那就太好了: obj["Int
根据doc这个tutorial , cmp() returns -1 if x y 教程里也说了 cmp() returns the sign of the difference of two nu
我经常读到 It seem that identity monad is useless. It's not... but that's another topic. 那么谁能告诉我它有什么用? 最佳
我已经知道实现和接口(interface)的基础知识。我不明白什么时候使用接口(interface)。有接口(interface)的要求是什么? 例子: /// Interface demo Inte
在一些 R 函数的主体中,例如 lm,我看到对 match.call 函数的调用。正如其帮助页面所述,当在函数内部使用 match.call 时,会返回指定参数名称的调用;这对于将大量参数传递给另一个
在监督学习中,我有典型的训练/测试分割来学习算法,例如回归或分类。关于无监督学习,我的问题是:训练/测试分割是否必要且有用?如果是,为什么? 最佳答案 这取决于问题、数据集的形式以及用于解决特定问题的
我最近接触到 Javascript 模板并变得非常感兴趣。 我正在使用 MVC 模式构建一个大型 PHP 应用程序。模板由相当棒的 Twig 处理. 我最近遇到了一个 javascript imple
我最近在一个我要重构并拥有的项目中遇到了以下代码行: SomeClass someClass = new SomeClass(); 我这辈子都想不通为什么有人会以这种方式使用泛型。我想出的唯一原因是
亲爱的,我正在阅读这篇关于通过 asp.net 4 中的代码动态添加元标记的帖子 - 但我想问一下对 SEO 有什么好处,静态添加它或者在代码后面添加它没有问题 http://weblogs.asp.
我是一名优秀的程序员,十分优秀!