Skip to content

Commit

Permalink
update h264
Browse files Browse the repository at this point in the history
  • Loading branch information
penndev committed Dec 10, 2024
1 parent 3f81b45 commit d927b40
Show file tree
Hide file tree
Showing 9 changed files with 1,934 additions and 1,563 deletions.
6 changes: 3 additions & 3 deletions Linux/FileSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

---

## 概况查看 {#show}
# 概况查看 {#show}
** 查看已经挂载的文件系统 **
```bash
df -hT
```
- `h` --human-readable
- `T` --print-type

** 查看全部设备的文件系统 **
**查看全部设备的文件系统**
```bash
lsblk
lsblk -afp
```
- `a` --all
- `f` --fs
- `p` --paths
** 查看分区表 **
**查看分区表**
- `fdisk -l` 查看分区表
- `parted -l` 查看分区表

Expand Down
2 changes: 1 addition & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@

-----
* [算法](Algo/README.md)
* [指数哥伦布编码](Algo/Exp-Golomb-coding.md)
* [哥伦布编码](Algo/Golomb-coding.md)
* [算数编码](Algo/Arithmetic-coding.md)
46 changes: 33 additions & 13 deletions _code/h26x/h264.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
'CODE logic from <T-REC-H.264-202108-I!!PDF-E.pdf>'
'CODE logic from <T-REC-H.264-202408-I!!PDF-E.pdf>'

from typing import Generator
from h264_nal import NAL
from h264_define import BitStream

from typing import Generator
from h264_bs import BitStream
from h264_sps import SPS
from h264_pps import PPS
from h264_slice import SliceHeader
from h264_define import NalUnitType

class H264():
'''
从h264中拆分出nalu数据,并进行数据预处理
'''
def nal_unit(self, hex):
# self.hex += hex # 调试nalu对比字节用
pass

# nal = NAL(BitStream(hex), sps=self.sps_nalu, pps=self.pps_nalu)
# if nal.nal_unit_type == 7:
# self.sps_nalu = nal
# if nal.nal_unit_type == 8:
# self.pps_nalu = nal
bs = BitStream(hex)
forbidden_zero_bit = bs.read_bits(1)
if forbidden_zero_bit != 0 :
raise("forbidden_zero_bit must zero")
# 当前unit重要程序表示,表示是否可丢弃当前数据。
nal_ref_idc = bs.read_bits(2)
nal_unit_type = bs.read_bits(5)
match nal_unit_type:
case NalUnitType.IDR:
slice_header = SliceHeader(bs, self.sps, self.pps, nal_unit_type, nal_ref_idc)
print(slice_header.__dict__)
case NalUnitType.SPS:
self.sps = SPS(bs)
print(self.sps.__dict__)
case NalUnitType.PPS:
self.pps = PPS(bs, self.sps)
print(self.pps.__dict__)
case _:
print(f'not support nal_unit_type: {nal_unit_type}')

def open(self, size) -> Generator[bytearray, None, None]:
'''
Expand All @@ -42,7 +57,12 @@ def open(self, size) -> Generator[bytearray, None, None]:
def __init__(self, filename):
'filename 输入文件必须是h264文件路径'
self.filename = filename

# --------->
self.hex = bytearray()
self.sps:SPS = None
self.pps:PPS = None
# --------->

current_hex = bytearray() # 当前nalu的数据
# 掐头移除StartCode [000001|00000001]放置open中
Expand Down Expand Up @@ -101,5 +121,5 @@ def __init__(self, filename):

if __name__ == "__main__":
nal = H264("_tmp/baseline.h264")
FILE_OUT = open(nal.filename + 'rbsp', "wb")
FILE_OUT.write(nal.hex)
# FILE_OUT = open(nal.filename + 'rbsp', "wb")
# FILE_OUT.write(nal.hex)
Loading

0 comments on commit d927b40

Please sign in to comment.