2016年10月4日 星期二

Sample Real Time Streaming Protocol

OPTIONS rtsp://192.168.9.154:554/stream2 RTSP/1.0\r\n
CSeq: 1\r\n
User-Agent: Lavf57.21.101\r\n
\r\n

RTSP/1.0 200 OK\r\n
CSeq: 1\r\n
Date: Tue, Oct 04 2016 03:48:31 GMT\r\n
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\r\n
\r\n

DESCRIBE rtsp://192.168.9.154:554/stream2 RTSP/1.0\r\n
Accept: application/sdp\r\n
CSeq: 2\r\n
User-Agent: Lavf57.21.101\r\n
\r\n

RTSP/1.0 200 OK\r\n
CSeq: 2\r\n
Date: Tue, Oct 04 2016 03:48:31 GMT\r\n
Content-Base: rtsp://192.168.9.154/stream2/\r\n
Content-type: application/sdp
Content-length: 525
\r\n

Session Description Protocol
Session Description Protocol Version (v): 0
Owner/Creator, Session Id (o): - 1475552620719822 1 IN IP4 192.168.9.154
Session Name (s): IP camera Live streaming
Session Information (i): stream2
Time Description, active time (t): 0 0
Session Attribute (a): tool:LIVE555 Streaming Media v2012.01.26
Session Attribute (a): type:broadcast
Session Attribute (a): control:*
Session Attribute (a): range:npt=0-
Session Attribute (a): x-qt-text-nam:IP camera Live streaming
Session Attribute (a): x-qt-text-inf:stream2
Media Description, name and address (m): video 0 RTP/AVP 96
Connection Information (c): IN IP4 192.168.9.154
Bandwidth Information (b): AS:1500
Media Attribute (a): x-bufferdelay:0.15000
Media Attribute (a): rtpmap:96 H264/90000
Media Attribute (a): fmtp:96 packetization-mode=1;profile-level-id=640020;sprop-parameter-sets=Z2QAIKw0zAUAef8BbgICAoAAAfQAABOIdDADLQADLQXeXGhgBloABloLvLhQ,aO48MA==
Media Attribute (a): control:track1

Request: SETUP rtsp://192.168.9.154/stream2/track1 RTSP/1.0\r\n
Transport: RTP/AVP/UDP;unicast;client_port=23606-23607
CSeq: 3\r\n
User-Agent: Lavf57.21.101\r\n
\r\n

RTSP/1.0 200 OK\r\n
CSeq: 3\r\n
Date: Tue, Oct 04 2016 03:48:31 GMT\r\n
Transport: RTP/AVP;unicast;destination=192.168.9.99;source=192.168.9.154;client_port=23606-23607;server_port=6970-6971
Session: 21015C4A;timeout=60
\r\n

PLAY rtsp://192.168.9.154/stream2/ RTSP/1.0\r\n
Range: npt=0.000-\r\n
CSeq: 4\r\n
User-Agent: Lavf57.21.101\r\n
Session: 21015C4A
\r\n

RTSP/1.0 200 OK\r\n
CSeq: 4\r\n
Date: Tue, Oct 04 2016 03:48:31 GMT\r\n
Range: npt=0.000-\r\n
Session: 21015C4A
RTP-Info: url=rtsp://192.168.9.154/stream2/track1;seq=57586;rtptime=924475415\r\n
\r\n

2015年8月12日 星期三

CSS Selectors

選擇器,顧名思義就是選擇您要定義 CSS 的位置。其種類大約分成以下幾種:
  1. Class selectors(Class選擇器,Dreamweaver稱為類別選擇器,這樣翻譯也對啦)
  2. ID selectors(ID選擇器)
  3. Type selectors(型態選擇器,Dreamweaver稱為標籤選擇器,因為套用於HTML標籤)
  4. Universal selector(通用選擇器)
  5. Attribute selectors(屬性選擇器)
  6. Descendant combinator(後代選擇器)
  7. Child combinator(子選擇器)
  8. Adjacent sibling combinator(同層相鄰選擇器)
  9. General sibling combinator(同層全體選擇器)
  10. Pseudo-classes(偽類選擇器)
  11. Pseudo-elements(偽元素選擇器)
  12. Groups of selectors(群組選擇器)
W3C 定義1~5為單純選擇器 (Simple selectors),6~9為組合選擇器(Combinators)。

W3Schools' CSS reference
http://www.w3schools.com/cssref/css_selectors.asp



2015年7月9日 星期四

H.264 Frame - 2


H.264 Frame - 2

GOP 長度:
一個 IDR frame 到下一個 IDR frame 的範圍。
所以將 GOP 設為無限大(無 IDR Frame)雖然可以增加壓縮率,
但這樣就不能隨意跳轉到其他時間點播放/解碼。


「Frame Rate」是指影片每秒播放靜態畫面的數量。目前的主流規格有PAL與SECAM 的25fps及NTSC 的29.97 fps。有些電玩畫面的Frame Rate會高達60,甚至上百,如果不特別處理,在網路上播放時會因為傳輸速度及CPU處理能力趕不上,而會有掉格(您看到的是跳格)的現象。
「Bit Rate」是指單位時間播放壓縮後影片的位元數量,它相當於影片播放時的頻寬消耗量,以多少Kbps或Mbps為單位。可以想像的是,較高的Bit Rate可容納更高的視訊品質,但與「解析度」有其相配性。以480p配500kbps及720p配800kbps,在電腦銀幕上的觀看效果是不錯的,也同時兼顧了頻寬成本及符合大多數網友可以順暢收看的網路環境!

Bitrate Control

固定位元速率Constant bitrate,簡稱CBR
當形容編解碼器的時候,CBR編碼指的是編碼器的輸出碼率(或者解碼器的輸入碼率)應該是固定制(常數)。當在一個頻寬受限的信道中進行多媒體通訊的時候CBR是非常有用的,因為這時候受限的是最高碼率,CBR可以更容易的使用這樣的信道。但是CBR不適合進行儲存,因為CBR將導致沒有足夠的碼率對複雜的內容部分進行編碼(從而導致品質下降),同時在簡單的內容部分會浪費一些碼率。

平均位元速率(ABR, Average Bit-Rate)在音訊編碼時,指這樣一種編碼方式:它與固定位元速率(CBR)基本相同,會按照設定的目標碼率進行編碼。但當編碼器認為「適當」的時候,會使用高於目標碼率的數值來進行編碼以保證更好的品質。
例如一首192kbps的平均位元速率編碼的MP3,其中可能存在分散著的一些極短的片段使用了高於192kbps的碼率。但由於它們實在太短了,因此最終的目的檔並不會比使用固定位元速率編碼的檔案大很多,通常差異在2~3%左右。

可變位元速率Variable bitrate,簡稱VBR
當形容編解碼器的時候,VBR編碼指的是編碼器的輸出碼率(或者解碼器的輸入碼率)可以根據編碼器的輸入源訊號的複雜度自適應的調整,目的是達到保持輸出品質保持不變而不是保持輸出碼率保持不變。VBR適用於儲存(不太適用於串流傳輸),可以更有效地利用有限的儲存空間:用比較多的碼字對複雜度高的段進行編碼,用比較少的碼字對複雜度低的段進行編碼。

H.264 Frame



H.264 Frame

影片是由許多連續的 Frames 所組成,但並不是所有 Frames 都是完整的畫面,那些 Frames 需要參考其他 Frames 才能解碼出一張完整的畫面。

H.264 的 Frame types 有 I、B、P 三種。

I-frame:
不需要參考其他 Frames,是一張完整的畫面。

I-frame (IDR):
不需要參考其他 Frames,是一張完整的畫面。
IDR frame 為真正的 關鍵畫格 (keyframes),
P-frame & B-frame 不會越過 IDR frame 去參考其他 Frames,
所以可以隨意跳轉到任意 IDR frame 開始播放/解碼,而不會發生問題。

P-frame:
只紀錄了與之前的 Frames 相異的區塊,最多可以參考 "16 張" 之前的 Frames
播放/解碼時需要參用到之前的 Frames 的部分資料,才能解碼出完整畫面。
在 x264 中,你不能控制 P-frame 數量,但你可以控制一個 P-frame 所能參考的 Frame 數量,
也就是 Reference frame (ref) 的數值。

B-frame:
只紀錄了與前一張與後一張的 Frames 相異的區塊,壓縮率高(由其是在低動態/低變化的影片),
播放/解碼時需要用到前後兩張的 Frames 的部分資料,才能解碼出完整畫面。

由於 P-/B-frame 不是完整的畫面,解碼時必須參考其他 Frames,
所以你不能隨意跳轉到 P-/B-frame 上播放/解碼。
也就是說你如果播放 MPEG 視訊格式,當你跳播放時間點時,
正常而言,並不會跳到你所選的時間點上,而是最近的 IDR / I-frame。

由以上得知,在 bitrate 充足的情況下,則不需要使用較多 B-frame、Reference frame (ref) ,
多少 bitrate 為充足依影片內容為定,高動態影片需要較多 bitrate,低動則較少。

至於使用時機...
提高 B-frame/ref 使用量可以降低 bitrate 的需求,使用較少 bitrate 達到目標品質。
低動態的影片可以使用較多的 B-frame,高動態或是純靜態則是 P-frame 效果較好。

對於相容性與硬體負擔...
提高 B-frame/ref 使用量的副作用是降相容性以及提高硬體負擔,請先保證相容性再來追求壓縮率。
而 ref 的副作用要比 B-frame 強,例如 ref=16 這代表解碼一個 P-frame 必須要連跳回 1~16 張之前的 Frames 取用資料。

2015年6月9日 星期二

IEEE 802.1X principle and function implementation



  • IEEE 802.1X is an IEEE Standard for port-based Network Access Control (“port” means the same physical connection to the LAN infrastructure). It is part of the IEEE 802.1 group of networking protocols. It provides an authentication mechanism for devices to connect to a LAN, either establishing a connection or preventing the connection if authentication fails. IEEE 802.1X prevents what is called “port hi-jacking”; that is, when an unauthorized computer gets access to a network by getting to a network jack inside or outside a building. IEEE 802.1X is useful in, for example, network video applications since network cameras are often located in public spaces where a network jack can pose a security risk. In today’s enterprise networks, IEEE 802.1X is becoming a basic requirement for anything that is connected to a network.

  • Three basic terms in 802.1X.
    1. Supplicant -- user, client
    2. Authentication server  -- RADIUS server
    3. Authenticator -- devices. ex: switch.


  • The protocol used in 802.1X is Extensible Authentication Protocol encapsulation over LANs (EAPOL). There are a number of modes of operation, but the most common case would look something like this (see Figure 1):

    1. The authenticator sends an “EAP-Request/Identity” packet to the supplicant as soon as it detects that the network link is active (e.g., the supplicant, for example a network camera in a network video system, is connected to the switch).
    2. The supplicant sends an “EAP-Response/Identity” packet to the authenticator.
    3. The “EAP-Response/Identity” packet is then passed on to the authentication (RADIUS) server by the authenticator.
    4. The authentication server sends back a challenge to the authenticator, such as with a token password system.
    5. The authenticator unpacks this from IP and repackages it into EAPOL and sends it to the supplicant. Different authentication methods will vary this message and the total number of messages. EAP supports client-only authentication and strong mutual authentication.
    6. The supplicant responds to the challenge by the authenticator.
    7. The authenticator passes the response to the challenge onto the authentication server.
    8. If the supplicant provides proper identity, the authentication server responds with a success message to the authenticator.
    9. The success message is then passed onto the supplicant by the authenticator. The authenticator now allows access of the supplicant to the LAN, possibly restricted based on attributes that came back from the authentication server. For example, the authenticator might switch the supplicant to a particular virtual LAN or install a set of firewall rules.

2015年4月26日 星期日

Self define chroot environment

1. Create new required root directory.
2. Create all needed directories. ($newroot $newroot/dev $newroot/bin $newroot/home $newroot/lib $newroot/etc $newroot/usr/lib $newroot/usr/bin $newroot/proc $newroot/dev/pts)
3. Collect needed execution files and libraries. Copy these needed files . The destination location will be on ${newroot}/bin and ${newroot}/lib
4, Copy required configuration files. (/etc files:   group  passwd  profile)
5. Do chroot command. (In user SSH login session, or define in inittab to chroot during sysinit boot time)

2015年4月20日 星期一

影像取樣與擷取

取樣(Sampling) - 連續函數數位化的過程

奈奎斯特定理 (Nyquist Theorem)
奈奎斯特定理說明必須以高於受測訊號的最高頻率兩倍以上的速度進行取樣,才能正確地重建波型

數位影像(digital image)和一般(類比)照片的不同之處在於其xyf(x,y) 的值都是不連續(或離散)的。
數位影像可以看成一個連續影像經過取樣而成的大型陣列。這些點就是所謂的像素pixels),組成了數位影像。