標籤

C (1) maple (2) Matlab (11) paper (1) python (14)

2014年12月19日 星期五

H264 Syntax 與 .264檔案基本對照

H.264  bitstream 分析
使用工具: H264VISAUltraEditJM,以及H264 spec.
就用JM裡面附的foreman_part_qcif.yuv 編碼變成 test.264.
使用H264VISAUltraEdit分別打開test.264

UltraEdit





































H264VISA畫面




































可以在UltraEdit搜尋(Ctrl+F) 00 00 00 01 這是每個NAL unit 的啟始碼,一共可以找到5個對應到 H264VISA Header Info的五個NAL unit.
接下來我們從UltraEditbitstream搭配spec. 看能不能跟H264VISA搭上.

首先看到前幾個NAL unit

#1 .  00 00 00 01 67 64 00 28   AC E6 0B 13 90
去掉起始碼後 將之轉換成2進位
01100111 01100100 00000000 00101000 10101100 11100110 00001011 00010011 10010000
然後看到Spec 7.3.1 NAL unit syntax可以將之對應上
forbidden_zero_bit = 0 f(1)  ->  0
nal_ref_idx = 11      u(2)  ->  3 : 最高安全性
nal_unit_type = 00111 u(5)  ->  7 : 標明這個NAL unit 是個Sequence parameter set (PPS)
(Table 7-1 – NAL unit type codes)
所以其後面就會跟上seq_parameter_set_rbsp()的內容 (7.3.2.1)
profile_idc = 01100100 u(8) -> 100
constraint_set0_flag = 0 u(1) -> 0
constraint_set1_flag = 0 u(1) -> 0
constraint_set2_flag = 0 u(1) -> 0
constraint_set3_flag = 0 u(1) -> 0
reserved_zero_4bits = 0000 u(4) -> 0
level_idc = 00101000 u(8) -> 40

seq_parameter_set_id = 1 ue(v) -> 0    ue(v): Exp-Golomb_coded 可以在 wiki找到、書中也有
((因為profile_idc = 100 所以會到 if))
Chroma_format_idc = 010 ue(v) -> 1
bit_depth_luma_minus8 = 1 ue(v) -> 0
bit_depth_chroma_minus8 = 1 ue(v) -> 0
qpprime_y_zero_transform_bypass_flag = 0 u(1) -> 0
seq_caling_matrix_present_flag = 0 u(1) -> 0

log2_max_frame_num_minus4 = 1 ue(v) -> 0
pic_order_cnt_type = 1 ue(v) -> 0
log2_max_pic_order_cnt_lsb_minus4 = 1 ue(v) -> 0
num_ref_frames = 00110 ue(v) -> 5

gaps_in_frame_num_value_allowed_flag = 0 u(1) -> 0
pic_width_in_mbs_minus1 = 0001011 ue(v) -> 10
pic_height_in_map_units_minus1 = 0001001 ue(v) ->8
frame_mbs_only_flag = 1 u(1) -> 1
direct_8x8_inference_flag = 1 u(1) -> 1
frame_cropping_flag = 0 u(1) -> 0
vui_parameter_present_flag = 0 u(1) -> 0

rbsp_trailing_bits 會補到最末位為8bits, 所以補上 10000
再對照 H264VISA







































NALU done!
接下來下一個是
00 00 00 01 68 E9 4A 38 B0
一樣去掉起始碼之後轉成2進位
01101000 11101001 01001010 00111000 10110000
先看前8bits  (01101000)
forbidden_zero_bit = 0 -> 0
nal_ref_idc = 11 -> 3
nal_unit_type = 01000 -> 8 表示此NAUL type Picture parameter set 即後面跟的rbsp
                                                      pic_parameter_set_rbsp()
接下來看到(7.3.2.2 Picture parameter set RBSP syntax)
pic_parameter_set_id = 1 ue(v) -> 0
seq_parameter_set_id =1 ue(v) -> 0
entropy_coding_mode_flag = 1 u(1) -> 1
pic_order_present_flag = 0 u(1) -> 0
num_slice_groups_minus1 = 1 ue(v) -> 0
num_ref_idx_l0_active_minus1 = 00101 ue(v) ->4
num_ref_idx_l1_active_minus1 = 00101 ue(v) ->4
weighted_pred_flag = 0 u(1) -> 0
weighted_bipred_idc = 00 u(2) -> 0
pic_init_qp_minus26 = 1 se(v) -> 0
pic_init_qs_minus26 = 1 se(v) -> 0
chroma_qp_index_offset = 1 se(v) -> 0
deblocking_filtr_control_present_flag = 0 u(1) ->0
constrained_intra_pred_flag = 0 u(1) -> 0
redundant_pic_cnt_present_flag = 0 u(1) -> 0
transform_8x8_mode_flag = 1 u(1) -> 1
pic_scaling_matrix_present_flag = 0 u(1) -> 0
second_chroma_qp_index_offset = 1 se(v) ->0
rbsp_trailing_bits = (rbsp_stop_one_bit) 1 (rbsp_alignment_zero_bit) 0000


























只有在second_chroma_qp_index_offset的時候他沒有標出來,不知道是沒寫好還是怎麼了?

接下來看第三個NALU 00000010h 00 00 00 01 開始 00000a30h 00 00 00 01 之前都是第三個NALU
我們從前面開始看起
00 00 00 01 65 88 84 02 7F EA …
看看除了起始碼之後的轉成二進位的前八碼 也就是 0x65 -> 01100101
forbidden_zero_bit = 0 f(1) -> 0
nal_ref_idc = 11 u(2) -> 3
nal_unit_type = 00101 -> 5 (Coded slice of an IDR picture)
所以後面跟的rbsp slice_layer_without_partitioning_rbsp() (就是 7.3.2.8)
內容如下:
slice_layer_without_partitioning_rbsp(){
slice_header() <-7.3.3
slice_data() <-7.3.4
rbsp_slice_trailing_bits()<-7.3.2.10
}
接下來看 slice_header()的部分
65之後的轉成二進位變成 10001000 10000100 00000010 01111111 11101010然後對照7.3.3
first_mb_in_slice = 1 ue(v) -> 0
slice_type = 0001000 ue(v) -> 7 (Table 7-6 I slice )
pic_parameter_set_id = 1 ue(v) -> 0
frame_num = 0000 u(v) -> 0     
<<這邊frame_numu(v)長度要看log2_max_frame_num_minus4+4>>
然後後面要跟上一大陀東西, 然後接著要跟slice_data()
slice_data中又有macroblock_layer 7.3.5macroblock_layer中又有sub_mb_pred 7.3.5.2mb_pred 7.3.5.1residual 7.3.5.3residual中又分為residual_block_cavlc 7.3.5.3.1residual_block_cabac 7.3.5.3.2

我們就把每個NALU(slice)的前面的nal_ref_idcnal_unit_typefirst_mb_in_sliceslice_typepic_parameter_set_idframe_num給解析一下就好.

接下來看到第四個NALU的開頭 : 41 9A 29 92 7F … 對應到 pic 3 (Dec 2)
01000001 10011010 00101001 10010010 01111111
fobidden_zero_bit = 0 f(1) -> 0
nal_ref_idc = 10 u(2) -> 2
nal_unit_type = 00001 u(5) -> 1 (Coded slice of a non-IDR picture)
後面rbspslice_layer_without_patitioning_rbsp()
frst_mb_in_slice = 1 ue(v) -> 0
slice_type = 00110 ue(v) -> 5 (P slice)
pic_parameter_set_id = 1 ue(v) -> 0
frame_num = 0001 u(v) -> 1

第五個NALU開頭 01 9E 45 A9 …   對應到pic 2(Dec 3)
00000001 10011110 01000101 10101001
fobidden_zero_bit = 0 f(1) ->0
nal_ref_idc = 00 u(2) -> 0
nal_unit_type = 00001 u(5) ->1 (Coded slice of a non-IDR picture)
first_mb_in_slice = 1 ue(v) -> 0
slice_type = 00111 ue(v) -> 6 (B slice)
pic_parameter_set_id = 1 ue(v) -> 0

frame_num = 0010 u(v) -> 2
...

比較簡單的 H264 elemantary stream大概就長成這個樣子,
還會有multislice可能要用多個NALU才能拼成一個Frame,
可以從slice data的header中某些數值去判斷.

詳細的在參照H.264 Spec. 會有更深的了解.

2014年7月1日 星期二

Sublime text 2 trace code 工具

Sublime Text
在OSX, Linux, Window 皆有支援.

官方網站: http://www.sublimetext.com/2

好用的插件:

1. package control
先裝了這個之後一切都好辦.
安裝方法: https://sublime.wbond.net/installation#st2

接下來的插件只要在sublime text2 中
按下"ctrl+shift+p"
然後鍵入 pci (package control install的簡寫)再按enter
之後就會跑出package list

就可以鍵入下列想要安裝的package name.

2. filediff
可以看兩個檔案之間的差別.

3. Ctags
可以使用 navigate to definition, trace code非常好用.


2014年6月19日 星期四

liunx "Make" parameters

Cleaning targets:

  clean  - Remove most generated files but keep the config and

                    enough build support to build external modules
// 移除 *.o (不會清除 ".config")
  mrproper  - Remove all generated files + config + various backup files
// 移除 *.o ,也移除.config
  distclean  - mrproper + remove editor backup and patch files
// 連備份檔都清除掉.

// clean < mrproper < distclean

補充一下為什麼會叫做 mrproper
"make mrproper" is a command in the Linux kernel build system, used to "clean up" all files from past builds and restore the build directory to its original clean state. The reason "make mrproper" is used instead of "make mrclean" is because Linus Torvalds, the father of Linux, was familiar with the name "Mr. Proper" as this is the brand widely known in Europe."


Configuration targets:

  config  - Update current config utilising a line-oriented program

  nconfig         - Update current config utilising a ncurses menu based program

  menuconfig  - Update current config utilising a menu based program

  xconfig  - Update current config utilising a QT based front-end

  gconfig  - Update current config utilising a GTK based front-end

  oldconfig  - Update current config utilising a provided .config as base

  localmodconfig  - Update current config disabling modules not loaded

  localyesconfig  - Update current config converting local mods to core

  silentoldconfig - Same as oldconfig, but quietly, additionally update deps

  defconfig  - New config with default from ARCH supplied defconfig

  savedefconfig   - Save current config as ./defconfig (minimal config)

  allnoconfig  - New config where all options are answered with no

  allyesconfig  - New config where all options are accepted with yes

  allmodconfig  - New config selecting modules when possible

  alldefconfig    - New config with all symbols set to default

  randconfig  - New config with random answer to all options

  listnewconfig   - List new options

  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)



Other generic targets:

  all  - Build all targets marked with [*]

* vmlinux  - Build the bare kernel

* modules  - Build all modules

  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)

  firmware_install- Install all firmware to INSTALL_FW_PATH

                    (default: $(INSTALL_MOD_PATH)/lib/firmware)

  dir/            - Build all files in dir and below

  dir/file.[oisS] - Build specified target only

  dir/file.lst    - Build specified mixed source/assembly target only

                    (requires a recent binutils and recent build (System.map))

  dir/file.ko     - Build module including final link

  modules_prepare - Set up for building external modules

  tags/TAGS  - Generate tags file for editors

  cscope  - Generate cscope index

  gtags           - Generate GNU GLOBAL index

  kernelrelease  - Output the release version string

  kernelversion  - Output the version stored in Makefile

  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH

                    (default: /home/hankwu/git/elite_android-VEPD-9-d8f8/usr)



Static analysers

  checkstack      - Generate a list of stack hogs

  namespacecheck  - Name space analysis on compiled kernel

  versioncheck    - Sanity check on version.h usage

  includecheck    - Check for duplicate included header files

  export_report   - List the usages of all exported symbols

  headers_check   - Sanity check on exported headers

  headerdep       - Detect inclusion cycles in headers

  coccicheck      - Check with Coccinelle.



Kernel packaging:

  rpm-pkg             - Build both source and binary RPM kernel packages

  binrpm-pkg          - Build only the binary kernel package

  deb-pkg             - Build the kernel as a deb package

  tar-pkg             - Build the kernel as an uncompressed tarball

  targz-pkg           - Build the kernel as a gzip compressed tarball

  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball

  tarxz-pkg           - Build the kernel as a xz compressed tarball

  perf-tar-src-pkg    - Build perf-3.4.39.tar source tarball

  perf-targz-src-pkg  - Build perf-3.4.39.tar.gz source tarball

  perf-tarbz2-src-pkg - Build perf-3.4.39.tar.bz2 source tarball

  perf-tarxz-src-pkg  - Build perf-3.4.39.tar.xz source tarball



Documentation targets:

 Linux kernel internal documentation in different formats:

  htmldocs        - HTML

  pdfdocs         - PDF

  psdocs          - Postscript

  xmldocs         - XML DocBook

  mandocs         - man pages

  installmandocs  - install man pages generated by mandocs

  cleandocs       - clean all generated DocBook files



Architecture specific targets (x86):

* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)

  install      - Install kernel using

                  (your) ~/bin/installkernel or

                  (distribution) /sbin/installkernel or

                  install to $(INSTALL_PATH) and run lilo

  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)

  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)

  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)

  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)

                  bzdisk/fdimage*/isoimage also accept:

                  FDARGS="..."  arguments for the booted kernel

                  FDINITRD=file initrd for the booted kernel



  i386_defconfig           - Build for i386

  x86_64_defconfig         - Build for x86_64



  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build

  make V=2   [targets] 2 => give reason for rebuild of target

  make O=dir [targets] Locate all output files in "dir", including .config

  make C=1   [targets] Check all c source with $CHECK (sparse by default)

  make C=2   [targets] Force check of all c source with $CHECK

  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections

  make W=n   [targets] Enable extra gcc checks, n=1,2,3 where

1: warnings which may be relevant and do not occur too often

2: warnings which occur quite often but may still be relevant

3: more obscure warnings, can most likely be ignored

Multiple levels can be combined with W=12 or W=123



Execute "make" or "make all" to build all targets marked with [*]

For further info see the ./README file