mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
Parse H264 Profile Level
This commit is contained in:
parent
6f723b0035
commit
cc0dd4718c
|
@ -1,21 +1,75 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace BililiveRecorder.FlvProcessor
|
||||
{
|
||||
public class FlvTag : IFlvTag
|
||||
{
|
||||
private int _IsVideoKeyframe = -1;
|
||||
|
||||
public TagType TagType { get; set; } = 0;
|
||||
public int TagSize { get; set; } = 0;
|
||||
public int TimeStamp { get; private set; } = 0;
|
||||
public byte[] StreamId { get; set; } = new byte[3];
|
||||
public bool IsVideoKeyframe => _IsVideoKeyframe != -1 ? _IsVideoKeyframe == 1 : 1 == (_IsVideoKeyframe = _ParseIsVideoKeyframe());
|
||||
public byte[] Data { get; set; } = null;
|
||||
|
||||
public bool IsVideoKeyframe { get; private set; }// _IsVideoKeyframe != -1 ? _IsVideoKeyframe == 1 : 1 == (_IsVideoKeyframe = _ParseIsVideoKeyframe());
|
||||
public int Profile { get; private set; } = -1;
|
||||
public int Level { get; private set; } = -1;
|
||||
|
||||
public byte[] Data { get => _data; set { _data = value; ParseInfo(); } }
|
||||
private byte[] _data = null;
|
||||
|
||||
public void SetTimeStamp(int timestamp) => TimeStamp = timestamp;
|
||||
|
||||
private void ParseInfo()
|
||||
{
|
||||
/**
|
||||
* VIDEODATA:
|
||||
* 0x17 (1 byte)
|
||||
* 1 = AVC Keyframe
|
||||
* 7 = AVC Codec
|
||||
* AVCVIDEOPACKET:
|
||||
* 0x00 (1 byte)
|
||||
* 0 = AVC Header
|
||||
* 1 = AVC NALU
|
||||
* 0x00
|
||||
* 0x00
|
||||
* 0x00 (3 bytes)
|
||||
* if(AVC_HEADER) then always 0
|
||||
* AVCDecoderConfigurationRecord:
|
||||
* 0x01 (1 byte)
|
||||
* configurationVersion must be 1
|
||||
* 0x00 (1 byte)
|
||||
* AVCProfileIndication
|
||||
* 0x00 (1 byte)
|
||||
* profile_compatibility
|
||||
* 0x00 (1 byte)
|
||||
* AVCLevelIndication
|
||||
* */
|
||||
|
||||
IsVideoKeyframe = false;
|
||||
Profile = -1;
|
||||
Level = -1;
|
||||
|
||||
if (TagType != TagType.VIDEO) { return; }
|
||||
if (Data.Length < 9) { return; }
|
||||
|
||||
// Not AVC Keyframe
|
||||
if (Data[0] != 0x17) { return; }
|
||||
|
||||
IsVideoKeyframe = true;
|
||||
|
||||
// Isn't AVCDecoderConfigurationRecord
|
||||
if (Data[1] != 0x00) { return; }
|
||||
// version is not 1
|
||||
if (Data[5] != 0x01) { return; }
|
||||
|
||||
Profile = Data[6];
|
||||
Level = Data[8];
|
||||
#if DEBUG
|
||||
Debug.WriteLine("Video Profile: " + Profile + ", Level: " + Level);
|
||||
#endif
|
||||
}
|
||||
|
||||
public byte[] ToBytes(bool useDataSize, int offset = 0)
|
||||
{
|
||||
var tag = new byte[11];
|
||||
|
|
Loading…
Reference in New Issue
Block a user